[refactor] comment/naming improvements

This commit is contained in:
glozow 2021-05-27 08:39:59 +01:00
parent 7d91442461
commit e8ecc621be
6 changed files with 27 additions and 22 deletions

View File

@ -889,7 +889,7 @@ static RPCHelpMan testmempoolaccept()
"\nReturns result of mempool acceptance tests indicating if raw transaction(s) (serialized, hex-encoded) would be accepted by mempool.\n" "\nReturns result of mempool acceptance tests indicating if raw transaction(s) (serialized, hex-encoded) would be accepted by mempool.\n"
"\nIf multiple transactions are passed in, parents must come before children and package policies apply: the transactions cannot conflict with any mempool transactions or each other.\n" "\nIf multiple transactions are passed in, parents must come before children and package policies apply: the transactions cannot conflict with any mempool transactions or each other.\n"
"\nIf one transaction fails, other transactions may not be fully validated (the 'allowed' key will be blank).\n" "\nIf one transaction fails, other transactions may not be fully validated (the 'allowed' key will be blank).\n"
"\nThe maximum number of transactions allowed is 25 (MAX_PACKAGE_COUNT)\n" "\nThe maximum number of transactions allowed is " + ToString(MAX_PACKAGE_COUNT) + ".\n"
"\nThis checks if transactions violate the consensus or policy rules.\n" "\nThis checks if transactions violate the consensus or policy rules.\n"
"\nSee sendrawtransaction call.\n", "\nSee sendrawtransaction call.\n",
{ {
@ -905,7 +905,7 @@ static RPCHelpMan testmempoolaccept()
RPCResult{ RPCResult{
RPCResult::Type::ARR, "", "The result of the mempool acceptance test for each raw transaction in the input array.\n" RPCResult::Type::ARR, "", "The result of the mempool acceptance test for each raw transaction in the input array.\n"
"Returns results for each transaction in the same order they were passed in.\n" "Returns results for each transaction in the same order they were passed in.\n"
"It is possible for transactions to not be fully validated ('allowed' unset) if an earlier transaction failed.\n", "It is possible for transactions to not be fully validated ('allowed' unset) if another transaction failed.\n",
{ {
{RPCResult::Type::OBJ, "", "", {RPCResult::Type::OBJ, "", "",
{ {
@ -939,7 +939,6 @@ static RPCHelpMan testmempoolaccept()
UniValue::VARR, UniValue::VARR,
UniValueType(), // VNUM or VSTR, checked inside AmountFromValue() UniValueType(), // VNUM or VSTR, checked inside AmountFromValue()
}); });
const UniValue raw_transactions = request.params[0].get_array(); const UniValue raw_transactions = request.params[0].get_array();
if (raw_transactions.size() < 1 || raw_transactions.size() > MAX_PACKAGE_COUNT) { if (raw_transactions.size() < 1 || raw_transactions.size() > MAX_PACKAGE_COUNT) {
throw JSONRPCError(RPC_INVALID_PARAMETER, throw JSONRPCError(RPC_INVALID_PARAMETER,
@ -972,8 +971,8 @@ static RPCHelpMan testmempoolaccept()
}(); }();
UniValue rpc_result(UniValue::VARR); UniValue rpc_result(UniValue::VARR);
// We will check transaction fees we iterate through txns in order. If any transaction fee // We will check transaction fees while we iterate through txns in order. If any transaction fee
// exceeds maxfeerate, we will keave the rest of the validation results blank, because it // exceeds maxfeerate, we will leave the rest of the validation results blank, because it
// doesn't make sense to return a validation result for a transaction if its ancestor(s) would // doesn't make sense to return a validation result for a transaction if its ancestor(s) would
// not be submitted. // not be submitted.
bool exit_early{false}; bool exit_early{false};

View File

@ -28,8 +28,8 @@ struct MinerTestingSetup : public TestingSetup {
void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs); void TestPackageSelection(const CChainParams& chainparams, const CScript& scriptPubKey, const std::vector<CTransactionRef>& txFirst) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs);
bool TestSequenceLocks(const CTransaction& tx, int flags) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs) bool TestSequenceLocks(const CTransaction& tx, int flags) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, m_node.mempool->cs)
{ {
CCoinsViewMemPool viewMempool(&m_node.chainman->ActiveChainstate().CoinsTip(), *m_node.mempool); CCoinsViewMemPool view_mempool(&m_node.chainman->ActiveChainstate().CoinsTip(), *m_node.mempool);
return CheckSequenceLocks(m_node.chainman->ActiveChain().Tip(), viewMempool, tx, flags); return CheckSequenceLocks(m_node.chainman->ActiveChain().Tip(), view_mempool, tx, flags);
} }
BlockAssembler AssemblerForTest(const CChainParams& params); BlockAssembler AssemblerForTest(const CChainParams& params);
}; };

View File

@ -515,9 +515,9 @@ void CTxMemPool::removeForReorg(CChainState& active_chainstate, int flags)
LockPoints lp = it->GetLockPoints(); LockPoints lp = it->GetLockPoints();
assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate)); assert(std::addressof(::ChainstateActive()) == std::addressof(active_chainstate));
bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp); bool validLP = TestLockPointValidity(active_chainstate.m_chain, &lp);
CCoinsViewMemPool viewMempool(&active_chainstate.CoinsTip(), *this); CCoinsViewMemPool view_mempool(&active_chainstate.CoinsTip(), *this);
if (!CheckFinalTx(active_chainstate.m_chain.Tip(), tx, flags) if (!CheckFinalTx(active_chainstate.m_chain.Tip(), tx, flags)
|| !CheckSequenceLocks(active_chainstate.m_chain.Tip(), viewMempool, tx, flags, &lp, validLP)) { || !CheckSequenceLocks(active_chainstate.m_chain.Tip(), view_mempool, tx, flags, &lp, validLP)) {
// Note if CheckSequenceLocks fails the LockPoints may still be invalid // Note if CheckSequenceLocks fails the LockPoints may still be invalid
// So it's critical that we remove the tx and not depend on the LockPoints. // So it's critical that we remove the tx and not depend on the LockPoints.
txToRemove.insert(it); txToRemove.insert(it);

View File

@ -874,7 +874,8 @@ protected:
public: public:
CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn); CCoinsViewMemPool(CCoinsView* baseIn, const CTxMemPool& mempoolIn);
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override; bool GetCoin(const COutPoint &outpoint, Coin &coin) const override;
/** Add the coins created by this transaction. */ /** Add the coins created by this transaction. These coins are only temporarily stored in
* m_temp_added and cannot be flushed to the back end. Only used for package validation. */
void PackageAddTransaction(const CTransactionRef& tx); void PackageAddTransaction(const CTransactionRef& tx);
}; };

View File

@ -482,7 +482,7 @@ public:
/** /**
* Multiple transaction acceptance. Transactions may or may not be interdependent, * Multiple transaction acceptance. Transactions may or may not be interdependent,
* but must not conflict with each other. Parents must come before children if any * but must not conflict with each other. Parents must come before children if any
* dependencies exist, otherwise a TX_MISSING_INPUTS error will be returned. * dependencies exist.
*/ */
PackageMempoolAcceptResult AcceptMultipleTransactions(const std::vector<CTransactionRef>& txns, ATMPArgs& args) EXCLUSIVE_LOCKS_REQUIRED(cs_main); PackageMempoolAcceptResult AcceptMultipleTransactions(const std::vector<CTransactionRef>& txns, ATMPArgs& args) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
@ -1148,9 +1148,9 @@ PackageMempoolAcceptResult MemPoolAccept::AcceptMultipleTransactions(const std::
return PackageMempoolAcceptResult(package_state, std::move(results)); return PackageMempoolAcceptResult(package_state, std::move(results));
} }
// Make the coins created by this transaction available for subsequent transactions in the // Make the coins created by this transaction available for subsequent transactions in the
// package to spend. Since we already checked conflicts in the package and RBFs are // package to spend. Since we already checked conflicts in the package and we don't allow
// impossible, we don't need to track the coins spent. Note that this logic will need to be // replacements, we don't need to track the coins spent. Note that this logic will need to be
// updated if RBFs in packages are allowed in the future. // updated if package replace-by-fee is allowed in the future.
assert(args.disallow_mempool_conflicts); assert(args.disallow_mempool_conflicts);
m_viewmempool.PackageAddTransaction(ws.m_ptx); m_viewmempool.PackageAddTransaction(ws.m_ptx);
} }
@ -1227,7 +1227,6 @@ PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTx
const PackageMempoolAcceptResult result = MemPoolAccept(pool, active_chainstate).AcceptMultipleTransactions(package, args); const PackageMempoolAcceptResult result = MemPoolAccept(pool, active_chainstate).AcceptMultipleTransactions(package, args);
// Uncache coins pertaining to transactions that were not submitted to the mempool. // Uncache coins pertaining to transactions that were not submitted to the mempool.
// Ensure the cache is still within its size limits.
for (const COutPoint& hashTx : coins_to_uncache) { for (const COutPoint& hashTx : coins_to_uncache) {
active_chainstate.CoinsTip().Uncache(hashTx); active_chainstate.CoinsTip().Uncache(hashTx);
} }

View File

@ -234,11 +234,13 @@ MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, CTxMemPoo
bool bypass_limits, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main); bool bypass_limits, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
/** /**
* Atomically test acceptance of a package. If the package only contains one tx, package rules still apply. * Atomically test acceptance of a package. If the package only contains one tx, package rules still
* apply. Package validation does not allow BIP125 replacements, so the transaction(s) cannot spend
* the same inputs as any transaction in the mempool.
* @param[in] txns Group of transactions which may be independent or contain * @param[in] txns Group of transactions which may be independent or contain
* parent-child dependencies. The transactions must not conflict, i.e. * parent-child dependencies. The transactions must not conflict
* must not spend the same inputs, even if it would be a valid BIP125 * with each other, i.e., must not spend the same inputs. If any
* replace-by-fee. Parents must appear before children. * dependencies exist, parents must appear before children.
* @returns a PackageMempoolAcceptResult which includes a MempoolAcceptResult for each transaction. * @returns a PackageMempoolAcceptResult which includes a MempoolAcceptResult for each transaction.
* If a transaction fails, validation will exit early and some results may be missing. * If a transaction fails, validation will exit early and some results may be missing.
*/ */
@ -269,9 +271,13 @@ bool TestLockPointValidity(CChain& active_chain, const LockPoints* lp) EXCLUSIVE
* Check if transaction will be BIP68 final in the next block to be created on top of tip. * Check if transaction will be BIP68 final in the next block to be created on top of tip.
* @param[in] tip Chain tip to check tx sequence locks against. For example, * @param[in] tip Chain tip to check tx sequence locks against. For example,
* the tip of the current active chain. * the tip of the current active chain.
* @param[in] coins_view Any CCoinsView that provides access to the relevant coins * @param[in] coins_view Any CCoinsView that provides access to the relevant coins for
* for checking sequence locks. Any CCoinsView can be passed in; * checking sequence locks. For example, it can be a CCoinsViewCache
* it is assumed to be consistent with the tip. * that isn't connected to anything but contains all the relevant
* coins, or a CCoinsViewMemPool that is connected to the
* mempool and chainstate UTXO set. In the latter case, the caller is
* responsible for holding the appropriate locks to ensure that
* calls to GetCoin() return correct coins.
* Simulates calling SequenceLocks() with data from the tip passed in. * Simulates calling SequenceLocks() with data from the tip passed in.
* Optionally stores in LockPoints the resulting height and time calculated and the hash * Optionally stores in LockPoints the resulting height and time calculated and the hash
* of the block needed for calculation or skips the calculation and uses the LockPoints * of the block needed for calculation or skips the calculation and uses the LockPoints