Skip to content

Commit e7ea858

Browse files
committed
Merge #13527: policy: Remove promiscuousmempoolflags
faa2444 policy: Remove promiscuousmempoolflags (MarcoFalke) Pull request description: It seems odd to clutter validation code with features that can only ever be used for testing (testnet or regtest). Removing that test-only code makes the mempool logic less painful to understand and easier to reason about when changed or refactored in the future. Tree-SHA512: 3b897aa9604ac8d82ebe9573c6efd468c93ddaa08d378ebc902e247b7aa6c68fcde71e5b449c08f17a067146cdc66dc50a67ce06d07607c27e5189a49c3fba3f
2 parents b413ba0 + faa2444 commit e7ea858

File tree

5 files changed

+29
-42
lines changed

5 files changed

+29
-42
lines changed

src/miner.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
133133

134134
// Decide whether to include witness transactions
135135
// This is only needed in case the witness softfork activation is reverted
136-
// (which would require a very deep reorganization) or when
137-
// -promiscuousmempoolflags is used.
136+
// (which would require a very deep reorganization).
137+
// Note that the mempool would accept transactions with witness data before
138+
// IsWitnessEnabled, but we would only ever mine blocks after IsWitnessEnabled
139+
// unless there is a massive block reorganization with the witness softfork
140+
// not activated.
138141
// TODO: replace this with a call to main to assess validity of a mempool
139142
// transaction (which in most cases can be a no-op).
140143
fIncludeWitness = IsWitnessEnabled(pindexPrev, chainparams.GetConsensus()) && fMineWitnessTx;

src/validation.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,7 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
894894
}
895895
}
896896

897-
unsigned int scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS;
898-
if (!chainparams.RequireStandard()) {
899-
scriptVerifyFlags = gArgs.GetArg("-promiscuousmempoolflags", scriptVerifyFlags);
900-
}
897+
constexpr unsigned int scriptVerifyFlags = STANDARD_SCRIPT_VERIFY_FLAGS;
901898

902899
// Check against previous transactions
903900
// This is done last to help prevent CPU exhaustion denial-of-service attacks.
@@ -932,20 +929,8 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
932929
// transactions into the mempool can be exploited as a DoS attack.
933930
unsigned int currentBlockScriptVerifyFlags = GetBlockScriptFlags(chainActive.Tip(), Params().GetConsensus());
934931
if (!CheckInputsFromMempoolAndCache(tx, state, view, pool, currentBlockScriptVerifyFlags, true, txdata)) {
935-
// If we're using promiscuousmempoolflags, we may hit this normally
936-
// Check if current block has some flags that scriptVerifyFlags
937-
// does not before printing an ominous warning
938-
if (!(~scriptVerifyFlags & currentBlockScriptVerifyFlags)) {
939-
return error("%s: BUG! PLEASE REPORT THIS! ConnectInputs failed against latest-block but not STANDARD flags %s, %s",
932+
return error("%s: BUG! PLEASE REPORT THIS! CheckInputs failed against latest-block but not STANDARD flags %s, %s",
940933
__func__, hash.ToString(), FormatStateMessage(state));
941-
} else {
942-
if (!CheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, false, txdata)) {
943-
return error("%s: ConnectInputs failed against MANDATORY but not STANDARD flags due to promiscuous mempool %s, %s",
944-
__func__, hash.ToString(), FormatStateMessage(state));
945-
} else {
946-
LogPrintf("Warning: -promiscuousmempool flags set to not include currently enforced soft forks, this may break mining or otherwise cause instability!\n");
947-
}
948-
}
949934
}
950935

951936
if (test_accept) {

test/functional/feature_cltv.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def create_transaction(node, coinbase, to_address, amount):
6262
class BIP65Test(BitcoinTestFramework):
6363
def set_test_params(self):
6464
self.num_nodes = 1
65-
self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']]
65+
self.extra_args = [['-whitelist=127.0.0.1']]
6666
self.setup_clean_chain = True
6767

6868
def run_test(self):
@@ -116,12 +116,13 @@ def run_test(self):
116116
spendtx.rehash()
117117

118118
# First we show that this tx is valid except for CLTV by getting it
119-
# accepted to the mempool (which we can achieve with
120-
# -promiscuousmempoolflags).
121-
self.nodes[0].p2p.send_and_ping(msg_tx(spendtx))
122-
assert spendtx.hash in self.nodes[0].getrawmempool()
119+
# rejected from the mempool for exactly that reason.
120+
assert_equal(
121+
[{'txid': spendtx.hash, 'allowed': False, 'reject-reason': '64: non-mandatory-script-verify-flag (Negative locktime)'}],
122+
self.nodes[0].testmempoolaccept(rawtxs=[bytes_to_hex_str(spendtx.serialize())], allowhighfees=True)
123+
)
123124

124-
# Now we verify that a block with this transaction is invalid.
125+
# Now we verify that a block with this transaction is also invalid.
125126
block.vtx.append(spendtx)
126127
block.hashMerkleRoot = block.calc_merkle_root()
127128
block.solve()

test/functional/feature_dersig.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ def create_transaction(node, coinbase, to_address, amount):
4747
tx.deserialize(BytesIO(hex_str_to_bytes(signresult['hex'])))
4848
return tx
4949

50+
5051
class BIP66Test(BitcoinTestFramework):
5152
def set_test_params(self):
5253
self.num_nodes = 1
53-
self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']]
54+
self.extra_args = [['-whitelist=127.0.0.1']]
5455
self.setup_clean_chain = True
5556

5657
def run_test(self):
@@ -108,12 +109,13 @@ def run_test(self):
108109
spendtx.rehash()
109110

110111
# First we show that this tx is valid except for DERSIG by getting it
111-
# accepted to the mempool (which we can achieve with
112-
# -promiscuousmempoolflags).
113-
self.nodes[0].p2p.send_and_ping(msg_tx(spendtx))
114-
assert spendtx.hash in self.nodes[0].getrawmempool()
112+
# rejected from the mempool for exactly that reason.
113+
assert_equal(
114+
[{'txid': spendtx.hash, 'allowed': False, 'reject-reason': '64: non-mandatory-script-verify-flag (Non-canonical DER signature)'}],
115+
self.nodes[0].testmempoolaccept(rawtxs=[bytes_to_hex_str(spendtx.serialize())], allowhighfees=True)
116+
)
115117

116-
# Now we verify that a block with this transaction is invalid.
118+
# Now we verify that a block with this transaction is also invalid.
117119
block.vtx.append(spendtx)
118120
block.hashMerkleRoot = block.calc_merkle_root()
119121
block.rehash()

test/functional/feature_segwit.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def set_test_params(self):
4343
self.num_nodes = 3
4444
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
4545
self.extra_args = [["-rpcserialversion=0", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"],
46-
["-blockversion=4", "-promiscuousmempoolflags=517", "-rpcserialversion=1", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"],
47-
["-blockversion=536870915", "-promiscuousmempoolflags=517", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"]]
46+
["-blockversion=4", "-rpcserialversion=1", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"],
47+
["-blockversion=536870915", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"]]
4848

4949
def setup_network(self):
5050
super().setup_network()
@@ -64,12 +64,8 @@ def skip_mine(self, node, txid, sign, redeem_script=""):
6464
sync_blocks(self.nodes)
6565

6666
def fail_accept(self, node, error_msg, txid, sign, redeem_script=""):
67-
assert_raises_rpc_error(-26, error_msg, send_to_witness, 1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script)
67+
assert_raises_rpc_error(-26, error_msg, send_to_witness, use_p2wsh=1, node=node, utxo=getutxo(txid), pubkey=self.pubkey[0], encode_p2sh=False, amount=Decimal("49.998"), sign=sign, insert_redeem_script=redeem_script)
6868

69-
def fail_mine(self, node, txid, sign, redeem_script=""):
70-
send_to_witness(1, node, getutxo(txid), self.pubkey[0], False, Decimal("49.998"), sign, redeem_script)
71-
assert_raises_rpc_error(-1, "CreateNewBlock: TestBlockValidity failed", node.generate, 1)
72-
sync_blocks(self.nodes)
7369

7470
def run_test(self):
7571
self.nodes[0].generate(161) #block 161
@@ -171,10 +167,10 @@ def run_test(self):
171167
assert(self.nodes[0].getrawtransaction(segwit_tx_list[i]) == bytes_to_hex_str(tx.serialize_without_witness()))
172168

173169
self.log.info("Verify witness txs without witness data are invalid after the fork")
174-
self.fail_mine(self.nodes[2], wit_ids[NODE_2][WIT_V0][2], False)
175-
self.fail_mine(self.nodes[2], wit_ids[NODE_2][WIT_V1][2], False)
176-
self.fail_mine(self.nodes[2], p2sh_ids[NODE_2][WIT_V0][2], False, witness_script(False, self.pubkey[2]))
177-
self.fail_mine(self.nodes[2], p2sh_ids[NODE_2][WIT_V1][2], False, witness_script(True, self.pubkey[2]))
170+
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program hash mismatch) (code 64)', wit_ids[NODE_2][WIT_V0][2], sign=False)
171+
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program was passed an empty witness) (code 64)', wit_ids[NODE_2][WIT_V1][2], sign=False)
172+
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program hash mismatch) (code 64)', p2sh_ids[NODE_2][WIT_V0][2], sign=False, redeem_script=witness_script(False, self.pubkey[2]))
173+
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program was passed an empty witness) (code 64)', p2sh_ids[NODE_2][WIT_V1][2], sign=False, redeem_script=witness_script(True, self.pubkey[2]))
178174

179175
self.log.info("Verify default node can now use witness txs")
180176
self.success_mine(self.nodes[0], wit_ids[NODE_0][WIT_V0][0], True) #block 432

0 commit comments

Comments
 (0)