aboutsummaryrefslogtreecommitdiff
path: root/src/validation.h
diff options
context:
space:
mode:
authorglozow <gzhao408@berkeley.edu>2021-04-05 10:12:58 -0700
committerglozow <gzhao408@berkeley.edu>2021-05-24 14:42:10 +0100
commit2ef187941db439c5b3e529f08b6ab153ff061fc5 (patch)
treee0b09e18c6e411566b0a4db3e210bde2b7a73133 /src/validation.h
parent578148ded62828a9820398165c41670f4dbb523d (diff)
downloadbitcoin-2ef187941db439c5b3e529f08b6ab153ff061fc5.tar.xz
[validation] package validation for test accepts
Only allow test accepts for now. Use the CoinsViewTemporary to keep track of coins created by each transaction so that subsequent transactions can spend them. Uncache all coins since we only ever do test accepts (Note this is different from ATMP which doesn't uncache for valid test_accepts) to minimize impact on the coins cache. Require that the input txns have no conflicts and be ordered topologically. This commit isn't able to detect unsorted packages.
Diffstat (limited to 'src/validation.h')
-rw-r--r--src/validation.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/validation.h b/src/validation.h
index 231f55d827..3f09e59dab 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -18,6 +18,7 @@
#include <fs.h>
#include <node/utxo_snapshot.h>
#include <policy/feerate.h>
+#include <policy/packages.h>
#include <protocol.h> // For CMessageHeader::MessageStartChars
#include <script/script_error.h>
#include <sync.h>
@@ -205,6 +206,28 @@ private:
};
/**
+* Validation result for package mempool acceptance.
+*/
+struct PackageMempoolAcceptResult
+{
+ const PackageValidationState m_state;
+ /**
+ * Map from wtxid to finished MempoolAcceptResults. The client is responsible
+ * for keeping track of the transaction objects themselves. If a result is not
+ * present, it means validation was unfinished for that transaction.
+ */
+ std::map<const uint256, const MempoolAcceptResult> m_tx_results;
+
+ explicit PackageMempoolAcceptResult(PackageValidationState state,
+ std::map<const uint256, const MempoolAcceptResult>&& results)
+ : m_state{state}, m_tx_results(std::move(results)) {}
+
+ /** Constructor to create a PackageMempoolAcceptResult from a single MempoolAcceptResult */
+ explicit PackageMempoolAcceptResult(const uint256& wtxid, const MempoolAcceptResult& result)
+ : m_tx_results{ {wtxid, result} } {}
+};
+
+/**
* (Try to) add a transaction to the memory pool.
* @param[in] bypass_limits When true, don't enforce mempool fee limits.
* @param[in] test_accept When true, run validation checks but don't submit to mempool.
@@ -212,6 +235,18 @@ private:
MempoolAcceptResult AcceptToMemoryPool(CChainState& active_chainstate, CTxMemPool& pool, const CTransactionRef& tx,
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.
+* @param[in] txns Group of transactions which may be independent or contain
+* parent-child dependencies. The transactions must not conflict, i.e.
+* must not spend the same inputs, even if it would be a valid BIP125
+* replace-by-fee. Parents must appear before children.
+* @returns a PackageMempoolAcceptResult which includes a MempoolAcceptResult for each transaction.
+* If a transaction fails, validation will exit early and some results may be missing.
+*/
+PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTxMemPool& pool,
+ const Package& txns, bool test_accept)
+ EXCLUSIVE_LOCKS_REQUIRED(cs_main);
/** Apply the effects of this transaction on the UTXO set represented by view */
void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);