MCPcopy Create free account
hub / github.com/ElementsProject/elements / ReplacementChecks

Method ReplacementChecks

src/validation.cpp:999–1043  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

997}
998
999bool MemPoolAccept::ReplacementChecks(Workspace& ws)
1000{
1001 AssertLockHeld(cs_main);
1002 AssertLockHeld(m_pool.cs);
1003
1004 const CTransaction& tx = *ws.m_ptx;
1005 const uint256& hash = ws.m_hash;
1006 TxValidationState& state = ws.m_state;
1007
1008 CFeeRate newFeeRate(ws.m_modified_fees, ws.m_vsize);
1009 // The replacement transaction must have a higher feerate than its direct conflicts.
1010 // - The motivation for this check is to ensure that the replacement transaction is preferable for
1011 // block-inclusion, compared to what would be removed from the mempool.
1012 // - This logic predates ancestor feerate-based transaction selection, which is why it doesn't
1013 // consider feerates of descendants.
1014 // - Note: Ancestor feerate-based transaction selection has made this comparison insufficient to
1015 // guarantee that this is incentive-compatible for miners, because it is possible for a
1016 // descendant transaction of a direct conflict to pay a higher feerate than the transaction that
1017 // might replace them, under these rules.
1018 if (const auto err_string{PaysMoreThanConflicts(ws.m_iters_conflicting, newFeeRate, hash)}) {
1019 return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "insufficient fee", *err_string);
1020 }
1021
1022 // Calculate all conflicting entries and enforce BIP125 Rule #5.
1023 if (const auto err_string{GetEntriesForConflicts(tx, m_pool, ws.m_iters_conflicting, ws.m_all_conflicting)}) {
1024 return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY,
1025 "too many potential replacements", *err_string);
1026 }
1027 // Enforce BIP125 Rule #2.
1028 if (const auto err_string{HasNoNewUnconfirmed(tx, m_pool, ws.m_iters_conflicting)}) {
1029 return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY,
1030 "replacement-adds-unconfirmed", *err_string);
1031 }
1032 // Check if it's economically rational to mine this transaction rather than the ones it
1033 // replaces and pays for its own relay fees. Enforce BIP125 Rules #3 and #4.
1034 for (CTxMemPool::txiter it : ws.m_all_conflicting) {
1035 ws.m_conflicting_fees += it->GetModifiedFee();
1036 ws.m_conflicting_size += it->GetTxSize();
1037 }
1038 if (const auto err_string{PaysForRBF(ws.m_conflicting_fees, ws.m_modified_fees, ws.m_vsize,
1039 ::incrementalRelayFee, hash)}) {
1040 return state.Invalid(TxValidationResult::TX_MEMPOOL_POLICY, "insufficient fee", *err_string);
1041 }
1042 return true;
1043}
1044
1045bool MemPoolAccept::PackageMempoolChecks(const std::vector<CTransactionRef>& txns,
1046 PackageValidationState& package_state)

Callers

nothing calls this directly

Calls 7

PaysMoreThanConflictsFunction · 0.85
GetEntriesForConflictsFunction · 0.85
HasNoNewUnconfirmedFunction · 0.85
PaysForRBFFunction · 0.85
InvalidMethod · 0.80
GetModifiedFeeMethod · 0.45
GetTxSizeMethod · 0.45

Tested by

no test coverage detected