diff options
author | gzhao408 <gzhao408@berkeley.edu> | 2021-01-19 05:29:40 -0800 |
---|---|---|
committer | gzhao408 <gzhao408@berkeley.edu> | 2021-02-09 07:01:52 -0800 |
commit | f82baf0762f60c2ca5ffc339b095f9271d7c2f33 (patch) | |
tree | 4439a2ad3f6021a62be8bba8a8bf8da6d4b03174 /src/node/transaction.cpp | |
parent | 9db10a55061e09021ff8ea1d6637d99f7959035f (diff) |
[refactor] return MempoolAcceptResult
This creates a cleaner interface with ATMP, allows us to make results const,
and makes accessing values that don't make sense (e.g. fee when tx is
invalid) an error.
Diffstat (limited to 'src/node/transaction.cpp')
-rw-r--r-- | src/node/transaction.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/node/transaction.cpp b/src/node/transaction.cpp index d3bb9687a8..6f5acf41e3 100644 --- a/src/node/transaction.cpp +++ b/src/node/transaction.cpp @@ -50,22 +50,22 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t } if (!node.mempool->exists(hashTx)) { // Transaction is not already in the mempool. - TxValidationState state; if (max_tx_fee > 0) { // First, call ATMP with test_accept and check the fee. If ATMP // fails here, return error immediately. - CAmount fee{0}; - if (!AcceptToMemoryPool(*node.mempool, state, tx, - nullptr /* plTxnReplaced */, false /* bypass_limits */, /* test_accept */ true, &fee)) { - return HandleATMPError(state, err_string); - } else if (fee > max_tx_fee) { + const MempoolAcceptResult result = AcceptToMemoryPool(*node.mempool, tx, false /* bypass_limits */, + true /* test_accept */); + if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) { + return HandleATMPError(result.m_state, err_string); + } else if (result.m_base_fees.value() > max_tx_fee) { return TransactionError::MAX_FEE_EXCEEDED; } } // Try to submit the transaction to the mempool. - if (!AcceptToMemoryPool(*node.mempool, state, tx, - nullptr /* plTxnReplaced */, false /* bypass_limits */)) { - return HandleATMPError(state, err_string); + const MempoolAcceptResult result = AcceptToMemoryPool(*node.mempool, tx, false /* bypass_limits */, + false /* test_accept */); + if (result.m_result_type != MempoolAcceptResult::ResultType::VALID) { + return HandleATMPError(result.m_state, err_string); } // Transaction was accepted to the mempool. |