diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -17,6 +17,11 @@ struct CBlockLocator; class CChainParams; class CScheduler; +class CTransaction; +class CValidationState; +namespace Consensus { +struct Params; +} namespace interfaces { @@ -106,6 +111,11 @@ //! is guaranteed to be an ancestor of the block used to create the //! locator. virtual Optional findLocatorFork(const CBlockLocator &locator) = 0; + + //! Check if transaction will be final given chain height current time. + virtual bool contextualCheckTransactionForCurrentBlock( + const Consensus::Params ¶ms, const CTransaction &tx, + CValidationState &state) = 0; }; //! Return Lock interface. Chain is locked when this is called, and diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -133,6 +134,12 @@ } return nullopt; } + bool contextualCheckTransactionForCurrentBlock( + const Consensus::Params ¶ms, const CTransaction &tx, + CValidationState &state) override { + LockAnnotation lock(::cs_main); + return ContextualCheckTransactionForCurrentBlock(params, tx, state); + } }; class LockingStateImpl : public LockImpl, diff --git a/src/interfaces/wallet.cpp b/src/interfaces/wallet.cpp --- a/src/interfaces/wallet.cpp +++ b/src/interfaces/wallet.cpp @@ -98,8 +98,7 @@ static WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock &locked_chain, const CWalletTx &wtx) { - // Temporary, for ContextualCheckTransactionForCurrentBlock below. - // Removed in upcoming commit. + // Temporary, for LookupBlockIndex below. Removed in upcoming commit. LockAnnotation lock(::cs_main); WalletTxStatus result; @@ -111,8 +110,9 @@ result.time_received = wtx.nTimeReceived; result.lock_time = wtx.tx->nLockTime; CValidationState state; - result.is_final = ContextualCheckTransactionForCurrentBlock( - Params().GetConsensus(), *wtx.tx, state); + result.is_final = + locked_chain.contextualCheckTransactionForCurrentBlock( + Params().GetConsensus(), *wtx.tx, state); result.is_trusted = wtx.IsTrusted(locked_chain); result.is_abandoned = wtx.isAbandoned(); result.is_coinbase = wtx.IsCoinBase(); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -711,9 +711,6 @@ // the user could have gotten from another RPC command prior to now pwallet->BlockUntilSyncedToCurrentChain(); - // Temporary, for ContextualCheckTransactionForCurrentBlock below. Removed - // in upcoming commit. - LockAnnotation lock(::cs_main); auto locked_chain = pwallet->chain().lock(); LOCK(pwallet->cs_wallet); @@ -742,7 +739,7 @@ CValidationState state; if (wtx.IsCoinBase() || - !ContextualCheckTransactionForCurrentBlock( + !locked_chain->contextualCheckTransactionForCurrentBlock( config.GetChainParams().GetConsensus(), *wtx.tx, state)) { continue; } @@ -807,9 +804,6 @@ // the user could have gotten from another RPC command prior to now pwallet->BlockUntilSyncedToCurrentChain(); - // Temporary, for ContextualCheckTransactionForCurrentBlock below. Removed - // in upcoming commit. - LockAnnotation lock(::cs_main); auto locked_chain = pwallet->chain().lock(); LOCK(pwallet->cs_wallet); @@ -829,7 +823,7 @@ const CWalletTx &wtx = pairWtx.second; CValidationState state; if (wtx.IsCoinBase() || - !ContextualCheckTransactionForCurrentBlock( + !locked_chain->contextualCheckTransactionForCurrentBlock( config.GetChainParams().GetConsensus(), *wtx.tx, state)) { continue; } @@ -1264,10 +1258,6 @@ ListReceived(const Config &config, interfaces::Chain::Lock &locked_chain, CWallet *const pwallet, const UniValue ¶ms, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet) { - // Temporary, for ContextualCheckTransactionForCurrentBlock below. Removed - // in upcoming commit. - LockAnnotation lock(::cs_main); - // Minimum confirmations int nMinDepth = 1; if (!params[0].isNull()) { @@ -1305,7 +1295,7 @@ CValidationState state; if (wtx.IsCoinBase() || - !ContextualCheckTransactionForCurrentBlock( + !locked_chain.contextualCheckTransactionForCurrentBlock( config.GetChainParams().GetConsensus(), *wtx.tx, state)) { continue; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2183,14 +2183,10 @@ } bool CWalletTx::IsTrusted(interfaces::Chain::Lock &locked_chain) const { - // Temporary, for ContextualCheckTransactionForCurrentBlock below. Removed - // in upcoming commit. - LockAnnotation lock(::cs_main); - // Quick answer in most cases CValidationState state; - if (!ContextualCheckTransactionForCurrentBlock(Params().GetConsensus(), *tx, - state)) { + if (!locked_chain.contextualCheckTransactionForCurrentBlock( + Params().GetConsensus(), *tx, state)) { return false; } @@ -2400,9 +2396,6 @@ // trusted. Amount CWallet::GetLegacyBalance(const isminefilter &filter, int minDepth) const { - // Temporary, for ContextualCheckTransactionForCurrentBlock below. Removed - // in upcoming commit. - LockAnnotation lock(::cs_main); auto locked_chain = chain().lock(); LOCK(cs_wallet); @@ -2414,8 +2407,8 @@ const int depth = wtx.GetDepthInMainChain(*locked_chain); CValidationState state; if (depth < 0 || - !ContextualCheckTransactionForCurrentBlock(params, *wtx.tx, - state) || + !locked_chain->contextualCheckTransactionForCurrentBlock( + params, *wtx.tx, state) || wtx.IsImmatureCoinBase(*locked_chain)) { continue; } @@ -2477,8 +2470,8 @@ const CWalletTx *pcoin = &entry.second; CValidationState state; - if (!ContextualCheckTransactionForCurrentBlock(params, *pcoin->tx, - state)) { + if (!locked_chain.contextualCheckTransactionForCurrentBlock( + params, *pcoin->tx, state)) { continue; }