Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 545 Lines • ▼ Show 20 Lines | bool CheckFeeRate(size_t package_size, size_t package_vsize, | ||||
| return state.Invalid( | return state.Invalid( | ||||
| TxValidationResult::TX_PACKAGE_RECONSIDERABLE, | TxValidationResult::TX_PACKAGE_RECONSIDERABLE, | ||||
| "mempool min fee not met", | "mempool min fee not met", | ||||
| strprintf("%d < %d", package_fee, mempoolRejectFee)); | strprintf("%d < %d", package_fee, mempoolRejectFee)); | ||||
| } | } | ||||
| // Do not change this to use virtualsize without coordinating a network | // Do not change this to use virtualsize without coordinating a network | ||||
| // policy upgrade. | // policy upgrade. | ||||
| if (package_fee < m_pool.m_min_relay_feerate.GetFee(package_size)) { | if (package_fee < | ||||
| m_pool.m_opts.min_relay_feerate.GetFee(package_size)) { | |||||
| return state.Invalid( | return state.Invalid( | ||||
| TxValidationResult::TX_PACKAGE_RECONSIDERABLE, | TxValidationResult::TX_PACKAGE_RECONSIDERABLE, | ||||
| "min relay fee not met", | "min relay fee not met", | ||||
| strprintf("%d < %d", package_fee, | strprintf( | ||||
| m_pool.m_min_relay_feerate.GetFee(package_size))); | "%d < %d", package_fee, | ||||
| m_pool.m_opts.min_relay_feerate.GetFee(package_size))); | |||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| ValidationCache &GetValidationCache() { | ValidationCache &GetValidationCache() { | ||||
| return m_active_chainstate.m_chainman.m_validation_cache; | return m_active_chainstate.m_chainman.m_validation_cache; | ||||
| } | } | ||||
| Show All 25 Lines | bool MemPoolAccept::PreChecks(ATMPArgs &args, Workspace &ws) { | ||||
| // Coinbase is only valid in a block, not as a loose transaction. | // Coinbase is only valid in a block, not as a loose transaction. | ||||
| if (!CheckRegularTransaction(tx, state)) { | if (!CheckRegularTransaction(tx, state)) { | ||||
| // state filled in by CheckRegularTransaction. | // state filled in by CheckRegularTransaction. | ||||
| return false; | return false; | ||||
| } | } | ||||
| // Rather not work on nonstandard transactions (unless -testnet) | // Rather not work on nonstandard transactions (unless -testnet) | ||||
| std::string reason; | std::string reason; | ||||
| if (m_pool.m_require_standard && | if (m_pool.m_opts.require_standard && | ||||
| !IsStandardTx(tx, m_pool.m_max_datacarrier_bytes, | !IsStandardTx(tx, m_pool.m_opts.max_datacarrier_bytes, | ||||
| m_pool.m_permit_bare_multisig, | m_pool.m_opts.permit_bare_multisig, | ||||
| m_pool.m_dust_relay_feerate, reason)) { | m_pool.m_opts.dust_relay_feerate, reason)) { | ||||
| return state.Invalid(TxValidationResult::TX_NOT_STANDARD, reason); | return state.Invalid(TxValidationResult::TX_NOT_STANDARD, reason); | ||||
| } | } | ||||
| // Only accept nLockTime-using transactions that can be mined in the next | // Only accept nLockTime-using transactions that can be mined in the next | ||||
| // block; we don't want our mempool filled up with transactions that can't | // block; we don't want our mempool filled up with transactions that can't | ||||
| // be mined yet. | // be mined yet. | ||||
| TxValidationState ctxState; | TxValidationState ctxState; | ||||
| if (!ContextualCheckTransactionForCurrentBlock( | if (!ContextualCheckTransactionForCurrentBlock( | ||||
| ▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | bool MemPoolAccept::PreChecks(ATMPArgs &args, Workspace &ws) { | ||||
| if (!Consensus::CheckTxInputs(tx, state, m_view, | if (!Consensus::CheckTxInputs(tx, state, m_view, | ||||
| m_active_chainstate.m_chain.Height() + 1, | m_active_chainstate.m_chain.Height() + 1, | ||||
| ws.m_base_fees)) { | ws.m_base_fees)) { | ||||
| // state filled in by CheckTxInputs | // state filled in by CheckTxInputs | ||||
| return false; | return false; | ||||
| } | } | ||||
| // Check for non-standard pay-to-script-hash in inputs | // Check for non-standard pay-to-script-hash in inputs | ||||
| if (m_pool.m_require_standard && | if (m_pool.m_opts.require_standard && | ||||
| !AreInputsStandard(tx, m_view, ws.m_next_block_script_verify_flags)) { | !AreInputsStandard(tx, m_view, ws.m_next_block_script_verify_flags)) { | ||||
| return state.Invalid(TxValidationResult::TX_INPUTS_NOT_STANDARD, | return state.Invalid(TxValidationResult::TX_INPUTS_NOT_STANDARD, | ||||
| "bad-txns-nonstandard-inputs"); | "bad-txns-nonstandard-inputs"); | ||||
| } | } | ||||
| // ws.m_modified_fess includes any fee deltas from PrioritiseTransaction | // ws.m_modified_fess includes any fee deltas from PrioritiseTransaction | ||||
| ws.m_modified_fees = ws.m_base_fees; | ws.m_modified_fees = ws.m_base_fees; | ||||
| m_pool.ApplyDelta(txid, ws.m_modified_fees); | m_pool.ApplyDelta(txid, ws.m_modified_fees); | ||||
| Show All 21 Lines | bool MemPoolAccept::PreChecks(ATMPArgs &args, Workspace &ws) { | ||||
| // No individual transactions are allowed below the min relay feerate except | // No individual transactions are allowed below the min relay feerate except | ||||
| // from disconnected blocks. This requirement, unlike CheckFeeRate, cannot | // from disconnected blocks. This requirement, unlike CheckFeeRate, cannot | ||||
| // be bypassed using m_package_feerates because, while a tx could be package | // be bypassed using m_package_feerates because, while a tx could be package | ||||
| // CPFP'd when entering the mempool, we do not have a DoS-resistant method | // CPFP'd when entering the mempool, we do not have a DoS-resistant method | ||||
| // of ensuring the tx remains bumped. For example, the fee-bumping child | // of ensuring the tx remains bumped. For example, the fee-bumping child | ||||
| // could disappear due to a replacement. | // could disappear due to a replacement. | ||||
| if (!bypass_limits && | if (!bypass_limits && | ||||
| ws.m_modified_fees < | ws.m_modified_fees < | ||||
| m_pool.m_min_relay_feerate.GetFee(ws.m_ptx->GetTotalSize())) { | m_pool.m_opts.min_relay_feerate.GetFee(ws.m_ptx->GetTotalSize())) { | ||||
| // Even though this is a fee-related failure, this result is | // Even though this is a fee-related failure, this result is | ||||
| // TX_MEMPOOL_POLICY, not TX_PACKAGE_RECONSIDERABLE, because it cannot | // TX_MEMPOOL_POLICY, not TX_PACKAGE_RECONSIDERABLE, because it cannot | ||||
| // be bypassed using package validation. | // be bypassed using package validation. | ||||
| return state.Invalid( | return state.Invalid( | ||||
| TxValidationResult::TX_MEMPOOL_POLICY, "min relay fee not met", | TxValidationResult::TX_MEMPOOL_POLICY, "min relay fee not met", | ||||
| strprintf("%d < %d", ws.m_modified_fees, | strprintf("%d < %d", ws.m_modified_fees, | ||||
| m_pool.m_min_relay_feerate.GetFee(nSize))); | m_pool.m_opts.min_relay_feerate.GetFee(nSize))); | ||||
| } | } | ||||
| // No individual transactions are allowed below the mempool min feerate | // No individual transactions are allowed below the mempool min feerate | ||||
| // except from disconnected blocks and transactions in a package. Package | // except from disconnected blocks and transactions in a package. Package | ||||
| // transactions will be checked using package feerate later. | // transactions will be checked using package feerate later. | ||||
| if (!bypass_limits && !args.m_package_feerates && | if (!bypass_limits && !args.m_package_feerates && | ||||
| !CheckFeeRate(nSize, ws.m_vsize, ws.m_modified_fees, state)) { | !CheckFeeRate(nSize, ws.m_vsize, ws.m_modified_fees, state)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | bool MemPoolAccept::Finalize(const ATMPArgs &args, Workspace &ws) { | ||||
| // Store transaction in memory | // Store transaction in memory | ||||
| CTxMemPoolEntry *pentry = ws.m_entry.release(); | CTxMemPoolEntry *pentry = ws.m_entry.release(); | ||||
| auto entry = CTxMemPoolEntryRef::acquire(pentry); | auto entry = CTxMemPoolEntryRef::acquire(pentry); | ||||
| m_pool.addUnchecked(entry); | m_pool.addUnchecked(entry); | ||||
| auto spentCoins = GetSpentCoins(ws.m_ptx, m_view); | auto spentCoins = GetSpentCoins(ws.m_ptx, m_view); | ||||
| Assume(spentCoins.has_value()); | Assume(spentCoins.has_value()); | ||||
| if (m_pool.m_signals) { | if (m_pool.m_opts.signals) { | ||||
| m_pool.m_signals->TransactionAddedToMempool( | m_pool.m_opts.signals->TransactionAddedToMempool( | ||||
| ws.m_ptx, | ws.m_ptx, | ||||
| // Spent coins should never be null, but better be safe than sorry. | // Spent coins should never be null, but better be safe than sorry. | ||||
| spentCoins.has_value() ? std::make_shared<const std::vector<Coin>>( | spentCoins.has_value() ? std::make_shared<const std::vector<Coin>>( | ||||
| std::move(*spentCoins)) | std::move(*spentCoins)) | ||||
| : nullptr, | : nullptr, | ||||
| m_pool.GetAndIncrementSequence()); | m_pool.GetAndIncrementSequence()); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | bool MemPoolAccept::SubmitPackage( | ||||
| return all_submitted; | return all_submitted; | ||||
| } | } | ||||
| MempoolAcceptResult | MempoolAcceptResult | ||||
| MemPoolAccept::AcceptSingleTransaction(const CTransactionRef &ptx, | MemPoolAccept::AcceptSingleTransaction(const CTransactionRef &ptx, | ||||
| ATMPArgs &args) { | ATMPArgs &args) { | ||||
| AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
| // mempool "read lock" (held through | // mempool "read lock" (held through | ||||
| // m_pool.m_signals->TransactionAddedToMempool()) | // m_pool.m_opts.signals->TransactionAddedToMempool()) | ||||
| LOCK(m_pool.cs); | LOCK(m_pool.cs); | ||||
| const CBlockIndex *tip = m_active_chainstate.m_chain.Tip(); | const CBlockIndex *tip = m_active_chainstate.m_chain.Tip(); | ||||
| Workspace ws(ptx, | Workspace ws(ptx, | ||||
| GetNextBlockScriptFlags(tip, m_active_chainstate.m_chainman)); | GetNextBlockScriptFlags(tip, m_active_chainstate.m_chainman)); | ||||
| const std::vector<TxId> single_txid{ws.m_ptx->GetId()}; | const std::vector<TxId> single_txid{ws.m_ptx->GetId()}; | ||||
| ▲ Show 20 Lines • Show All 1,606 Lines • ▼ Show 20 Lines | TRACE6(validation, block_connected, block_hash.data(), pindex->nHeight, | ||||
| // in microseconds (µs) | // in microseconds (µs) | ||||
| time_5 - time_start); | time_5 - time_start); | ||||
| return true; | return true; | ||||
| } | } | ||||
| CoinsCacheSizeState Chainstate::GetCoinsCacheSizeState() { | CoinsCacheSizeState Chainstate::GetCoinsCacheSizeState() { | ||||
| AssertLockHeld(::cs_main); | AssertLockHeld(::cs_main); | ||||
| return this->GetCoinsCacheSizeState(m_coinstip_cache_size_bytes, | return this->GetCoinsCacheSizeState( | ||||
| m_mempool ? m_mempool->m_max_size_bytes | m_coinstip_cache_size_bytes, | ||||
| : 0); | m_mempool ? m_mempool->m_opts.max_size_bytes : 0); | ||||
| } | } | ||||
| CoinsCacheSizeState | CoinsCacheSizeState | ||||
| Chainstate::GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes, | Chainstate::GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes, | ||||
| size_t max_mempool_size_bytes) { | size_t max_mempool_size_bytes) { | ||||
| AssertLockHeld(::cs_main); | AssertLockHeld(::cs_main); | ||||
| int64_t nMempoolUsage = m_mempool ? m_mempool->DynamicMemoryUsage() : 0; | int64_t nMempoolUsage = m_mempool ? m_mempool->DynamicMemoryUsage() : 0; | ||||
| int64_t cacheSize = CoinsTip().DynamicMemoryUsage(); | int64_t cacheSize = CoinsTip().DynamicMemoryUsage(); | ||||
| ▲ Show 20 Lines • Show All 4,985 Lines • Show Last 20 Lines | |||||