From f09bb66ba29817b011a588369486f7ad8818339e Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Wed, 8 Mar 2023 17:58:56 +1000 Subject: [PATCH] validation: Check only MANDATORY_SCRIPT_VERIFY_FLAGS when -acceptnonstdtxn is set --- src/validation.cpp | 7 +++++-- test/functional/p2p_segwit.py | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index ed9889d9dd368c..b647af744ade17 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1010,8 +1010,7 @@ bool MemPoolAccept::PolicyScriptChecks(const ATMPArgs& args, Workspace& ws) AssertLockHeld(m_pool.cs); const CTransaction& tx = *ws.m_ptx; TxValidationState& state = ws.m_state; - - constexpr unsigned int scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS; + const unsigned int scriptVerifyFlags = (m_pool.m_require_standard ? STANDARD_SCRIPT_VERIFY_FLAGS : MANDATORY_SCRIPT_VERIFY_FLAGS); // Check input scripts and signatures. // This is done last to help prevent CPU exhaustion denial-of-service attacks. @@ -2009,6 +2008,10 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex& block_index, const Ch { const Consensus::Params& consensusparams = chainman.GetConsensus(); + // Note that any flags returned from this function (ie, specified + // here or in script_flag_exceptions) must also be included in + // MANDATORY_SCRIPT_VERIFY_FLAGS in policy/policy.h + // BIP16 didn't become active until Apr 1 2012 (on mainnet, and // retroactively applied to testnet) // However, only one historical block violated the P2SH rules (on both diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py index 2850b7355dc43f..3cd6dfbd302d5b 100755 --- a/test/functional/p2p_segwit.py +++ b/test/functional/p2p_segwit.py @@ -1393,9 +1393,8 @@ def test_segwit_versions(self): # Now the node will no longer ask for getdata of this transaction when advertised by same txid self.std_node.announce_tx_and_wait_for_getdata(tx3, success=False) - # Spending a higher version witness output is not allowed by policy, - # even with the node that accepts non-standard txs. - test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=False, reason="reserved for soft-fork upgrades") + # Spending a higher version witness output is allowed on the node with -acceptnonstdtxn + test_transaction_acceptance(self.nodes[0], self.test_node, tx3, with_witness=True, accepted=True) # Building a block with the transaction must be valid, however even without -acceptnonstdtxn. block = self.build_next_block()