@@ -935,19 +935,19 @@ void CWallet::LoadToWallet(const CWalletTx& wtxIn)
935935 }
936936}
937937
938- bool CWallet::AddToWalletIfInvolvingMe (const CTransactionRef& ptx, const CBlockIndex* pIndex , int posInBlock, bool fUpdate )
938+ bool CWallet::AddToWalletIfInvolvingMe (const CTransactionRef& ptx, const uint256& block_hash , int posInBlock, bool fUpdate )
939939{
940940 const CTransaction& tx = *ptx;
941941 {
942942 AssertLockHeld (cs_wallet);
943943
944- if (pIndex != nullptr ) {
944+ if (!block_hash. IsNull () ) {
945945 for (const CTxIn& txin : tx.vin ) {
946946 std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range (txin.prevout );
947947 while (range.first != range.second ) {
948948 if (range.first ->second != tx.GetHash ()) {
949- WalletLogPrintf (" Transaction %s (in block %s) conflicts with wallet transaction %s (both spend %s:%i)\n " , tx.GetHash ().ToString (), pIndex-> GetBlockHash () .ToString (), range.first ->second .ToString (), range.first ->first .hash .ToString (), range.first ->first .n );
950- MarkConflicted (pIndex-> GetBlockHash () , range.first ->second );
949+ WalletLogPrintf (" Transaction %s (in block %s) conflicts with wallet transaction %s (both spend %s:%i)\n " , tx.GetHash ().ToString (), block_hash .ToString (), range.first ->second .ToString (), range.first ->first .hash .ToString (), range.first ->first .n );
950+ MarkConflicted (block_hash , range.first ->second );
951951 }
952952 range.first ++;
953953 }
@@ -983,8 +983,8 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransactionRef& ptx, const CBlockI
983983 CWalletTx wtx (this , ptx);
984984
985985 // Get merkle branch if transaction was found in a block
986- if (pIndex != nullptr )
987- wtx.SetMerkleBranch (pIndex , posInBlock);
986+ if (!block_hash. IsNull () )
987+ wtx.SetMerkleBranch (block_hash , posInBlock);
988988
989989 return AddToWallet (wtx, false );
990990 }
@@ -1071,11 +1071,7 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
10711071 auto locked_chain = chain ().lock ();
10721072 LOCK (cs_wallet);
10731073
1074- int conflictconfirms = 0 ;
1075- CBlockIndex* pindex = LookupBlockIndex (hashBlock);
1076- if (pindex && chainActive.Contains (pindex)) {
1077- conflictconfirms = -(chainActive.Height () - pindex->nHeight + 1 );
1078- }
1074+ int conflictconfirms = -locked_chain->getBlockDepth (hashBlock);
10791075 // If number of conflict confirms cannot be determined, this means
10801076 // that the block is still unknown or not yet part of the main chain,
10811077 // for example when loading the wallet during a reindex. Do nothing in that
@@ -1122,7 +1118,7 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
11221118}
11231119
11241120void CWallet::SyncTransaction (const CTransactionRef& ptx, const CBlockIndex *pindex, int posInBlock, bool update_tx) {
1125- if (!AddToWalletIfInvolvingMe (ptx, pindex, posInBlock, update_tx))
1121+ if (!AddToWalletIfInvolvingMe (ptx, pindex-> GetBlockHash () , posInBlock, update_tx))
11261122 return ; // Not one of ours
11271123
11281124 // If a transaction changes 'conflicted' state, that changes the balance
@@ -2573,6 +2569,7 @@ static bool IsCurrentForAntiFeeSniping(interfaces::Chain::Lock& locked_chain)
25732569 */
25742570static uint32_t GetLocktimeForNewTransaction (interfaces::Chain::Lock& locked_chain)
25752571{
2572+ uint32_t const height = locked_chain.getHeight ().value_or (-1 );
25762573 uint32_t locktime;
25772574 // Discourage fee sniping.
25782575 //
@@ -2595,7 +2592,7 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain::Lock& locked_cha
25952592 // now we ensure code won't be written that makes assumptions about
25962593 // nLockTime that preclude a fix later.
25972594 if (IsCurrentForAntiFeeSniping (locked_chain)) {
2598- locktime = chainActive. Height () ;
2595+ locktime = height ;
25992596
26002597 // Secondly occasionally randomly pick a nLockTime even further back, so
26012598 // that transactions that are delayed after signing for whatever reason,
@@ -2609,7 +2606,7 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain::Lock& locked_cha
26092606 // unique "nLockTime fingerprint", set nLockTime to a constant.
26102607 locktime = 0 ;
26112608 }
2612- assert (locktime <= ( unsigned int )chainActive. Height () );
2609+ assert (locktime <= height );
26132610 assert (locktime < LOCKTIME_THRESHOLD);
26142611 return locktime;
26152612}
@@ -4282,10 +4279,10 @@ CWalletKey::CWalletKey(int64_t nExpires)
42824279 nTimeExpires = nExpires;
42834280}
42844281
4285- void CMerkleTx::SetMerkleBranch (const CBlockIndex* pindex , int posInBlock)
4282+ void CMerkleTx::SetMerkleBranch (const uint256& block_hash , int posInBlock)
42864283{
42874284 // Update the tx's hashBlock
4288- hashBlock = pindex-> GetBlockHash () ;
4285+ hashBlock = block_hash ;
42894286
42904287 // set the position of the transaction in the block
42914288 nIndex = posInBlock;
@@ -4298,12 +4295,7 @@ int CMerkleTx::GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) const
42984295
42994296 AssertLockHeld (cs_main);
43004297
4301- // Find the block it claims to be in
4302- CBlockIndex* pindex = LookupBlockIndex (hashBlock);
4303- if (!pindex || !chainActive.Contains (pindex))
4304- return 0 ;
4305-
4306- return ((nIndex == -1 ) ? (-1 ) : 1 ) * (chainActive.Height () - pindex->nHeight + 1 );
4298+ return locked_chain.getBlockDepth (hashBlock) * (nIndex == -1 ? -1 : 1 );
43074299}
43084300
43094301int CMerkleTx::GetBlocksToMaturity (interfaces::Chain::Lock& locked_chain) const
0 commit comments