[refactor] make MempoolAcceptResult::m_replaced_transactions non-optional

This commit is contained in:
glozow committed 2024-05-01 13:34:37 +01:00
1 parent 842f7fdf78
commit 8496f69e1c
5 files changed
+6 -23

No files matched your search

+3 -9
View File
@@ -3281,9 +3281,7 @@ void PeerManagerImpl::ProcessPackageResult(const Package& package, const Package
switch (tx_result.m_result_type) { switch (tx_result.m_result_type) {
case MempoolAcceptResult::ResultType::VALID: case MempoolAcceptResult::ResultType::VALID:
{ {
Assume(tx_result.m_replaced_transactions.has_value()); ProcessValidTx(nodeid, tx, tx_result.m_replaced_transactions);
std::list<CTransactionRef> empty_replacement_list;
ProcessValidTx(nodeid, tx, tx_result.m_replaced_transactions.value_or(empty_replacement_list));
break; break;
} }
case MempoolAcceptResult::ResultType::INVALID: case MempoolAcceptResult::ResultType::INVALID:
@@ -3378,9 +3376,7 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
LogPrint(BCLog::TXPACKAGES, " accepted orphan tx %s (wtxid=%s)\n", orphanHash.ToString(), orphan_wtxid.ToString()); LogPrint(BCLog::TXPACKAGES, " accepted orphan tx %s (wtxid=%s)\n", orphanHash.ToString(), orphan_wtxid.ToString());
Assume(result.m_replaced_transactions.has_value()); ProcessValidTx(peer.m_id, porphanTx, result.m_replaced_transactions);
std::list<CTransactionRef> empty_replacement_list;
ProcessValidTx(peer.m_id, porphanTx, result.m_replaced_transactions.value_or(empty_replacement_list));
return true; return true;
} else if (state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) { } else if (state.GetResult() != TxValidationResult::TX_MISSING_INPUTS) {
LogPrint(BCLog::TXPACKAGES, " invalid orphan tx %s (wtxid=%s) from peer=%d. %s\n", LogPrint(BCLog::TXPACKAGES, " invalid orphan tx %s (wtxid=%s) from peer=%d. %s\n",
@@ -4578,9 +4574,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
const TxValidationState& state = result.m_state; const TxValidationState& state = result.m_state;
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
Assume(result.m_replaced_transactions.has_value()); ProcessValidTx(pfrom.GetId(), ptx, result.m_replaced_transactions);
std::list<CTransactionRef> empty_replacement_list;
ProcessValidTx(pfrom.GetId(), ptx, result.m_replaced_transactions.value_or(empty_replacement_list));
pfrom.m_last_tx_time = GetTime<std::chrono::seconds>(); pfrom.m_last_tx_time = GetTime<std::chrono::seconds>();
} }
else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS)
+2 -4
View File
@@ -994,10 +994,8 @@ static RPCHelpMan submitpackage()
fees.pushKV("effective-includes", effective_includes_res); fees.pushKV("effective-includes", effective_includes_res);
} }
result_inner.pushKV("fees", fees); result_inner.pushKV("fees", fees);
if (it->second.m_replaced_transactions.has_value()) { for (const auto& ptx : it->second.m_replaced_transactions) {
for (const auto& ptx : it->second.m_replaced_transactions.value()) { replaced_txids.insert(ptx->GetHash());
replaced_txids.insert(ptx->GetHash());
}
} }
break; break;
} }
-2
View File
@@ -139,7 +139,6 @@ void CheckATMPInvariants(const MempoolAcceptResult& res, bool txid_in_mempool, b
Assert(wtxid_in_mempool); Assert(wtxid_in_mempool);
Assert(res.m_state.IsValid()); Assert(res.m_state.IsValid());
Assert(!res.m_state.IsInvalid()); Assert(!res.m_state.IsInvalid());
Assert(res.m_replaced_transactions);
Assert(res.m_vsize); Assert(res.m_vsize);
Assert(res.m_base_fees); Assert(res.m_base_fees);
Assert(res.m_effective_feerate); Assert(res.m_effective_feerate);
@@ -154,7 +153,6 @@ void CheckATMPInvariants(const MempoolAcceptResult& res, bool txid_in_mempool, b
Assert(res.m_state.IsInvalid()); Assert(res.m_state.IsInvalid());
const bool is_reconsiderable{res.m_state.GetResult() == TxValidationResult::TX_RECONSIDERABLE}; const bool is_reconsiderable{res.m_state.GetResult() == TxValidationResult::TX_RECONSIDERABLE};
Assert(!res.m_replaced_transactions);
Assert(!res.m_vsize); Assert(!res.m_vsize);
Assert(!res.m_base_fees); Assert(!res.m_base_fees);
// Fee information is provided if the failure is TX_RECONSIDERABLE. // Fee information is provided if the failure is TX_RECONSIDERABLE.
-6
View File
@@ -68,12 +68,6 @@ std::optional<std::string> CheckPackageMempoolAcceptResult(const Package& txns,
return strprintf("tx %s unexpectedly failed: %s", wtxid.ToString(), atmp_result.m_state.ToString()); return strprintf("tx %s unexpectedly failed: %s", wtxid.ToString(), atmp_result.m_state.ToString());
} }
//m_replaced_transactions should exist iff the result was VALID
if (atmp_result.m_replaced_transactions.has_value() != valid) {
return strprintf("tx %s result should %shave m_replaced_transactions",
wtxid.ToString(), valid ? "" : "not ");
}
// m_vsize and m_base_fees should exist iff the result was VALID or MEMPOOL_ENTRY // m_vsize and m_base_fees should exist iff the result was VALID or MEMPOOL_ENTRY
const bool mempool_entry{atmp_result.m_result_type == MempoolAcceptResult::ResultType::MEMPOOL_ENTRY}; const bool mempool_entry{atmp_result.m_result_type == MempoolAcceptResult::ResultType::MEMPOOL_ENTRY};
if (atmp_result.m_base_fees.has_value() != (valid || mempool_entry)) { if (atmp_result.m_base_fees.has_value() != (valid || mempool_entry)) {
+1 -2
View File
@@ -113,7 +113,6 @@ void PruneBlockFilesManual(Chainstate& active_chainstate, int nManualPruneHeight
*| txid in mempool? | yes | no | no* | yes | yes | *| txid in mempool? | yes | no | no* | yes | yes |
*| wtxid in mempool? | yes | no | no* | yes | no | *| wtxid in mempool? | yes | no | no* | yes | no |
*| m_state | yes, IsValid() | yes, IsInvalid() | yes, IsInvalid() | yes, IsValid() | yes, IsValid() | *| m_state | yes, IsValid() | yes, IsInvalid() | yes, IsInvalid() | yes, IsValid() | yes, IsValid() |
*| m_replaced_transactions | yes | no | no | no | no |
*| m_vsize | yes | no | no | yes | no | *| m_vsize | yes | no | no | yes | no |
*| m_base_fees | yes | no | no | yes | no | *| m_base_fees | yes | no | no | yes | no |
*| m_effective_feerate | yes | yes | no | no | no | *| m_effective_feerate | yes | yes | no | no | no |
@@ -139,7 +138,7 @@ struct MempoolAcceptResult {
const TxValidationState m_state; const TxValidationState m_state;
/** Mempool transactions replaced by the tx. */ /** Mempool transactions replaced by the tx. */
const std::optional<std::list<CTransactionRef>> m_replaced_transactions; const std::list<CTransactionRef> m_replaced_transactions;
/** Virtual size as used by the mempool, calculated using serialized size and sigops. */ /** Virtual size as used by the mempool, calculated using serialized size and sigops. */
const std::optional<int64_t> m_vsize; const std::optional<int64_t> m_vsize;
/** Raw base fees in satoshis. */ /** Raw base fees in satoshis. */