Skip to content

Commit ca2a233

Browse files
committed
Merge #13120: policy: Treat segwit as always active
fa7a6cf policy: Treat segwit as always active (MarcoFalke) Pull request description: Now that segwit is active for a long time, there is no need to reject transactions with the reason that segwit hasn't activated. Strictly speaking, this is a bug fix, because with the release of 0.16, we create segwit transactions in our wallet by default without checking if they are allowed by local policy. More broadly, this simplifies the code as if "premature witness" was always set to true with the corresponding command line args. Tree-SHA512: 484c26aa3a66faba6b41e8554a91a29bfc15fbf6caae3d5363a3966283143189c4bd5333a610b0669c1238f75620691264e73f6b9f1161cdacf7574d946436da
2 parents 5315660 + fa7a6cf commit ca2a233

File tree

9 files changed

+107
-118
lines changed

9 files changed

+107
-118
lines changed

src/policy/policy.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
5454
return (txout.nValue < GetDustThreshold(txout, dustRelayFeeIn));
5555
}
5656

57-
bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType, const bool witnessEnabled)
57+
bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType)
5858
{
5959
std::vector<std::vector<unsigned char> > vSolutions;
6060
if (!Solver(scriptPubKey, whichType, vSolutions))
@@ -73,13 +73,10 @@ bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType, const bool w
7373
(!fAcceptDatacarrier || scriptPubKey.size() > nMaxDatacarrierBytes))
7474
return false;
7575

76-
else if (!witnessEnabled && (whichType == TX_WITNESS_V0_KEYHASH || whichType == TX_WITNESS_V0_SCRIPTHASH))
77-
return false;
78-
7976
return whichType != TX_NONSTANDARD && whichType != TX_WITNESS_UNKNOWN;
8077
}
8178

82-
bool IsStandardTx(const CTransaction& tx, std::string& reason, const bool witnessEnabled)
79+
bool IsStandardTx(const CTransaction& tx, std::string& reason)
8380
{
8481
if (tx.nVersion > CTransaction::MAX_STANDARD_VERSION || tx.nVersion < 1) {
8582
reason = "version";
@@ -118,7 +115,7 @@ bool IsStandardTx(const CTransaction& tx, std::string& reason, const bool witnes
118115
unsigned int nDataOut = 0;
119116
txnouttype whichType;
120117
for (const CTxOut& txout : tx.vout) {
121-
if (!::IsStandard(txout.scriptPubKey, whichType, witnessEnabled)) {
118+
if (!::IsStandard(txout.scriptPubKey, whichType)) {
122119
reason = "scriptpubkey";
123120
return false;
124121
}

src/policy/policy.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFee);
7979

8080
bool IsDust(const CTxOut& txout, const CFeeRate& dustRelayFee);
8181

82-
bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType, const bool witnessEnabled = false);
82+
bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType);
8383
/**
8484
* Check for standard transaction types
8585
* @return True if all outputs (scriptPubKeys) use only standard transaction forms
8686
*/
87-
bool IsStandardTx(const CTransaction& tx, std::string& reason, const bool witnessEnabled = false);
87+
bool IsStandardTx(const CTransaction& tx, std::string& reason);
8888
/**
8989
* Check for standard transaction types
9090
* @param[in] mapInputs Map of previous transactions that have outputs we're spending

src/validation.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,9 @@ static bool AcceptToMemoryPoolWorker(const CChainParams& chainparams, CTxMemPool
577577
if (tx.IsCoinBase())
578578
return state.DoS(100, false, REJECT_INVALID, "coinbase");
579579

580-
// Reject transactions with witness before segregated witness activates (override with -prematurewitness)
581-
bool witnessEnabled = IsWitnessEnabled(chainActive.Tip(), chainparams.GetConsensus());
582-
if (!gArgs.GetBoolArg("-prematurewitness", false) && tx.HasWitness() && !witnessEnabled) {
583-
return state.DoS(0, false, REJECT_NONSTANDARD, "no-witness-yet", true);
584-
}
585-
586580
// Rather not work on nonstandard transactions (unless -testnet/-regtest)
587581
std::string reason;
588-
if (fRequireStandard && !IsStandardTx(tx, reason, witnessEnabled))
582+
if (fRequireStandard && !IsStandardTx(tx, reason))
589583
return state.DoS(0, false, REJECT_NONSTANDARD, reason);
590584

591585
// Do not work on transactions that are too small.

src/wallet/rpcwallet.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,13 +1450,6 @@ static UniValue addwitnessaddress(const JSONRPCRequest& request)
14501450
"Projects should transition to using the address_type argument of getnewaddress, or option -addresstype=[bech32|p2sh-segwit] instead.\n");
14511451
}
14521452

1453-
{
1454-
LOCK(cs_main);
1455-
if (!IsWitnessEnabled(chainActive.Tip(), Params().GetConsensus()) && !gArgs.GetBoolArg("-walletprematurewitness", false)) {
1456-
throw JSONRPCError(RPC_WALLET_ERROR, "Segregated witness not enabled on network");
1457-
}
1458-
}
1459-
14601453
CTxDestination dest = DecodeDestination(request.params[0].get_str());
14611454
if (!IsValidDestination(dest)) {
14621455
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");

test/functional/feature_nulldummy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def set_test_params(self):
4242
self.setup_clean_chain = True
4343
# This script tests NULLDUMMY activation, which is part of the 'segwit' deployment, so we go through
4444
# normal segwit activation here (and don't use the default always-on behaviour).
45-
self.extra_args = [['-whitelist=127.0.0.1', '-walletprematurewitness', '-vbparams=segwit:0:999999999999', '-addresstype=legacy', "-deprecatedrpc=addwitnessaddress"]]
45+
self.extra_args = [['-whitelist=127.0.0.1', '-vbparams=segwit:0:999999999999', '-addresstype=legacy', "-deprecatedrpc=addwitnessaddress"]]
4646

4747
def run_test(self):
4848
self.address = self.nodes[0].getnewaddress()

test/functional/feature_segwit.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ def set_test_params(self):
4242
self.setup_clean_chain = True
4343
self.num_nodes = 3
4444
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
45-
self.extra_args = [["-walletprematurewitness", "-rpcserialversion=0", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"],
46-
["-blockversion=4", "-promiscuousmempoolflags=517", "-prematurewitness", "-walletprematurewitness", "-rpcserialversion=1", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"],
47-
["-blockversion=536870915", "-promiscuousmempoolflags=517", "-prematurewitness", "-walletprematurewitness", "-vbparams=segwit:0:999999999999", "-addresstype=legacy", "-deprecatedrpc=addwitnessaddress"]]
45+
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"]]
4848

4949
def setup_network(self):
5050
super().setup_network()
@@ -129,21 +129,6 @@ def run_test(self):
129129
self.nodes[0].generate(260) #block 423
130130
sync_blocks(self.nodes)
131131

132-
self.log.info("Verify default node can't accept any witness format txs before fork")
133-
# unsigned, no scriptsig
134-
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", wit_ids[NODE_0][WIT_V0][0], False)
135-
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", wit_ids[NODE_0][WIT_V1][0], False)
136-
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", p2sh_ids[NODE_0][WIT_V0][0], False)
137-
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", p2sh_ids[NODE_0][WIT_V1][0], False)
138-
# unsigned with redeem script
139-
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", p2sh_ids[NODE_0][WIT_V0][0], False, witness_script(False, self.pubkey[0]))
140-
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", p2sh_ids[NODE_0][WIT_V1][0], False, witness_script(True, self.pubkey[0]))
141-
# signed
142-
self.fail_accept(self.nodes[0], "no-witness-yet", wit_ids[NODE_0][WIT_V0][0], True)
143-
self.fail_accept(self.nodes[0], "no-witness-yet", wit_ids[NODE_0][WIT_V1][0], True)
144-
self.fail_accept(self.nodes[0], "no-witness-yet", p2sh_ids[NODE_0][WIT_V0][0], True)
145-
self.fail_accept(self.nodes[0], "no-witness-yet", p2sh_ids[NODE_0][WIT_V1][0], True)
146-
147132
self.log.info("Verify witness txs are skipped for mining before the fork")
148133
self.skip_mine(self.nodes[2], wit_ids[NODE_2][WIT_V0][0], True) #block 424
149134
self.skip_mine(self.nodes[2], wit_ids[NODE_2][WIT_V1][0], True) #block 425
@@ -164,6 +149,16 @@ def run_test(self):
164149
segwit_tx_list = self.nodes[2].getblock(block[0])["tx"]
165150
assert_equal(len(segwit_tx_list), 5)
166151

152+
self.log.info("Verify default node can't accept txs with missing witness")
153+
# unsigned, no scriptsig
154+
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", wit_ids[NODE_0][WIT_V0][0], False)
155+
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", wit_ids[NODE_0][WIT_V1][0], False)
156+
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", p2sh_ids[NODE_0][WIT_V0][0], False)
157+
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", p2sh_ids[NODE_0][WIT_V1][0], False)
158+
# unsigned with redeem script
159+
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", p2sh_ids[NODE_0][WIT_V0][0], False, witness_script(False, self.pubkey[0]))
160+
self.fail_accept(self.nodes[0], "mandatory-script-verify-flag", p2sh_ids[NODE_0][WIT_V1][0], False, witness_script(True, self.pubkey[0]))
161+
167162
self.log.info("Verify block and transaction serialization rpcs return differing serializations depending on rpc serialization flag")
168163
assert(self.nodes[2].getblock(block[0], False) != self.nodes[0].getblock(block[0], False))
169164
assert(self.nodes[1].getblock(block[0], False) == self.nodes[2].getblock(block[0], False))

0 commit comments

Comments
 (0)