@@ -1267,23 +1267,45 @@ void CWallet::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const
12671267 // state of transactions in our wallet is currently cleared when we
12681268 // receive another notification and there is a race condition where
12691269 // notification of a connected conflict might cause an outside process
1270- // to abandon a transaction and then have it inadvertantly cleared by
1270+ // to abandon a transaction and then have it inadvertently cleared by
12711271 // the notification that the conflicted transaction was evicted.
12721272
12731273 for (const CTransactionRef& ptx : vtxConflicted) {
1274- SyncTransaction (ptx, NULL , -1 );
1274+ SyncTransaction (ptx, nullptr , -1 );
12751275 }
12761276 for (size_t i = 0 ; i < pblock->vtx .size (); i++) {
12771277 SyncTransaction (pblock->vtx [i], pindex, i);
12781278 }
1279+
1280+ // Sapling: notify about the connected block
1281+ // Get prev block tree anchor
1282+ CBlockIndex* pprev = pindex->pprev ;
1283+ SaplingMerkleTree oldSaplingTree;
1284+ bool isSaplingActive = (pprev) != nullptr &&
1285+ Params ().GetConsensus ().NetworkUpgradeActive (pprev->nHeight ,
1286+ Consensus::UPGRADE_V5_0);
1287+ if (isSaplingActive) {
1288+ assert (pcoinsTip->GetSaplingAnchorAt (pprev->hashFinalSaplingRoot , oldSaplingTree));
1289+ } else {
1290+ assert (pcoinsTip->GetSaplingAnchorAt (SaplingMerkleTree::empty_root (), oldSaplingTree));
1291+ }
1292+
1293+ // Sapling: Update cached incremental witnesses
1294+ ChainTipAdded (pindex, pblock.get (), oldSaplingTree);
12791295}
12801296
1281- void CWallet::BlockDisconnected (const std::shared_ptr<const CBlock>& pblock)
1297+ void CWallet::BlockDisconnected (const std::shared_ptr<const CBlock>& pblock, int nBlockHeight )
12821298{
12831299 LOCK2 (cs_main, cs_wallet);
12841300 for (const CTransactionRef& ptx : pblock->vtx ) {
12851301 SyncTransaction (ptx, NULL , -1 );
12861302 }
1303+
1304+ if (Params ().GetConsensus ().NetworkUpgradeActive (nBlockHeight, Consensus::UPGRADE_V5_0)) {
1305+ // Update Sapling cached incremental witnesses
1306+ m_sspk_man->DecrementNoteWitnesses (nBlockHeight);
1307+ m_sspk_man->UpdateSaplingNullifierNoteMapForBlock (pblock.get ());
1308+ }
12871309}
12881310
12891311void CWallet::MarkAffectedTransactionsDirty (const CTransaction& tx)
@@ -4490,7 +4512,7 @@ void CWallet::IncrementNoteWitnesses(const CBlockIndex* pindex,
44904512 const CBlock* pblock,
44914513 SaplingMerkleTree& saplingTree) { m_sspk_man->IncrementNoteWitnesses (pindex, pblock, saplingTree); }
44924514
4493- void CWallet::DecrementNoteWitnesses (const CBlockIndex* pindex) { m_sspk_man->DecrementNoteWitnesses (pindex); }
4515+ void CWallet::DecrementNoteWitnesses (const CBlockIndex* pindex) { m_sspk_man->DecrementNoteWitnesses (pindex-> nHeight ); }
44944516
44954517bool CWallet::AddSaplingZKey (const libzcash::SaplingExtendedSpendingKey &key) { return m_sspk_man->AddSaplingZKey (key); }
44964518
0 commit comments