Skip to content

Commit 0053e16

Browse files
committed
[logging] Don't log REJECT code when transaction is rejected
Remove the BIP61 REJECT code from error messages and logs when a transaction is rejected. BIP61 support was removed from Bitcoin Core in fa25f43. The REJECT codes will be removed from the codebase entirely in the following commit.
1 parent a1a07cf commit 0053e16

10 files changed

+32
-33
lines changed

Diff for: src/rpc/rawtransaction.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ static UniValue testmempoolaccept(const JSONRPCRequest& request)
906906
result_0.pushKV("allowed", test_accept_res);
907907
if (!test_accept_res) {
908908
if (state.IsInvalid()) {
909-
result_0.pushKV("reject-reason", strprintf("%i: %s", state.GetRejectCode(), state.GetRejectReason()));
909+
result_0.pushKV("reject-reason", strprintf("%s", state.GetRejectReason()));
910910
} else if (missing_inputs) {
911911
result_0.pushKV("reject-reason", "missing-inputs");
912912
} else {

Diff for: src/util/validation.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
/** Convert CValidationState to a human-readable message for logging */
1212
std::string FormatStateMessage(const CValidationState &state)
1313
{
14-
return strprintf("%s%s (code %i)",
14+
return strprintf("%s%s",
1515
state.GetRejectReason(),
16-
state.GetDebugMessage().empty() ? "" : ", "+state.GetDebugMessage(),
17-
state.GetRejectCode());
16+
state.GetDebugMessage().empty() ? "" : ", "+state.GetDebugMessage());
1817
}
1918

2019
const std::string strMessageMagic = "Bitcoin Signed Message:\n";

Diff for: test/functional/feature_bip68_sequence.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
SEQUENCE_LOCKTIME_MASK = 0x0000ffff
2525

2626
# RPC error for non-BIP68 final transactions
27-
NOT_FINAL_ERROR = "non-BIP68-final (code 64)"
27+
NOT_FINAL_ERROR = "non-BIP68-final"
2828

2929
class BIP68Test(BitcoinTestFramework):
3030
def set_test_params(self):

Diff for: test/functional/feature_cltv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def run_test(self):
126126
# First we show that this tx is valid except for CLTV by getting it
127127
# rejected from the mempool for exactly that reason.
128128
assert_equal(
129-
[{'txid': spendtx.hash, 'allowed': False, 'reject-reason': '64: non-mandatory-script-verify-flag (Negative locktime)'}],
129+
[{'txid': spendtx.hash, 'allowed': False, 'reject-reason': 'non-mandatory-script-verify-flag (Negative locktime)'}],
130130
self.nodes[0].testmempoolaccept(rawtxs=[spendtx.serialize().hex()], maxfeerate=0)
131131
)
132132

Diff for: test/functional/feature_dersig.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def run_test(self):
110110
# First we show that this tx is valid except for DERSIG by getting it
111111
# rejected from the mempool for exactly that reason.
112112
assert_equal(
113-
[{'txid': spendtx.hash, 'allowed': False, 'reject-reason': '64: non-mandatory-script-verify-flag (Non-canonical DER signature)'}],
113+
[{'txid': spendtx.hash, 'allowed': False, 'reject-reason': 'non-mandatory-script-verify-flag (Non-canonical DER signature)'}],
114114
self.nodes[0].testmempoolaccept(rawtxs=[spendtx.serialize().hex()], maxfeerate=0)
115115
)
116116

Diff for: test/functional/feature_nulldummy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from test_framework.test_framework import BitcoinTestFramework
2121
from test_framework.util import assert_equal, assert_raises_rpc_error
2222

23-
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero) (code 64)"
23+
NULLDUMMY_ERROR = "non-mandatory-script-verify-flag (Dummy CHECKMULTISIG argument must be zero)"
2424

2525
def trueDummy(tx):
2626
scriptSig = CScript(tx.vin[0].scriptSig)

Diff for: test/functional/feature_segwit.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ def run_test(self):
193193
assert self.nodes[0].getrawtransaction(tx_id, False, blockhash) == tx.serialize_without_witness().hex()
194194

195195
self.log.info("Verify witness txs without witness data are invalid after the fork")
196-
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)
197-
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)
198-
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]))
199-
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]))
196+
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program hash mismatch)', wit_ids[NODE_2][WIT_V0][2], sign=False)
197+
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program was passed an empty witness)', wit_ids[NODE_2][WIT_V1][2], sign=False)
198+
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program hash mismatch)', p2sh_ids[NODE_2][WIT_V0][2], sign=False, redeem_script=witness_script(False, self.pubkey[2]))
199+
self.fail_accept(self.nodes[2], 'non-mandatory-script-verify-flag (Witness program was passed an empty witness)', p2sh_ids[NODE_2][WIT_V1][2], sign=False, redeem_script=witness_script(True, self.pubkey[2]))
200200

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

Diff for: test/functional/mempool_accept.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def run_test(self):
7171
node.generate(1)
7272
self.mempool_size = 0
7373
self.check_mempool_result(
74-
result_expected=[{'txid': txid_in_block, 'allowed': False, 'reject-reason': '18: txn-already-known'}],
74+
result_expected=[{'txid': txid_in_block, 'allowed': False, 'reject-reason': 'txn-already-known'}],
7575
rawtxs=[raw_tx_in_block],
7676
)
7777

@@ -109,7 +109,7 @@ def run_test(self):
109109
node.sendrawtransaction(hexstring=raw_tx_0)
110110
self.mempool_size += 1
111111
self.check_mempool_result(
112-
result_expected=[{'txid': txid_0, 'allowed': False, 'reject-reason': '18: txn-already-in-mempool'}],
112+
result_expected=[{'txid': txid_0, 'allowed': False, 'reject-reason': 'txn-already-in-mempool'}],
113113
rawtxs=[raw_tx_0],
114114
)
115115

@@ -133,7 +133,7 @@ def run_test(self):
133133
tx.vout[0].nValue -= int(4 * fee * COIN) # Set more fee
134134
# skip re-signing the tx
135135
self.check_mempool_result(
136-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '18: txn-mempool-conflict'}],
136+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'txn-mempool-conflict'}],
137137
rawtxs=[tx.serialize().hex()],
138138
maxfeerate=0,
139139
)
@@ -192,23 +192,23 @@ def run_test(self):
192192
# Skip re-signing the transaction for context independent checks from now on
193193
# tx.deserialize(BytesIO(hex_str_to_bytes(node.signrawtransactionwithwallet(tx.serialize().hex())['hex'])))
194194
self.check_mempool_result(
195-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: bad-txns-vout-empty'}],
195+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-vout-empty'}],
196196
rawtxs=[tx.serialize().hex()],
197197
)
198198

199199
self.log.info('A really large transaction')
200200
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
201201
tx.vin = [tx.vin[0]] * math.ceil(MAX_BLOCK_BASE_SIZE / len(tx.vin[0].serialize()))
202202
self.check_mempool_result(
203-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: bad-txns-oversize'}],
203+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-oversize'}],
204204
rawtxs=[tx.serialize().hex()],
205205
)
206206

207207
self.log.info('A transaction with negative output value')
208208
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
209209
tx.vout[0].nValue *= -1
210210
self.check_mempool_result(
211-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: bad-txns-vout-negative'}],
211+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-vout-negative'}],
212212
rawtxs=[tx.serialize().hex()],
213213
)
214214

@@ -217,7 +217,7 @@ def run_test(self):
217217
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
218218
tx.vout[0].nValue = 21000000 * COIN + 1
219219
self.check_mempool_result(
220-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: bad-txns-vout-toolarge'}],
220+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-vout-toolarge'}],
221221
rawtxs=[tx.serialize().hex()],
222222
)
223223

@@ -226,15 +226,15 @@ def run_test(self):
226226
tx.vout = [tx.vout[0]] * 2
227227
tx.vout[0].nValue = 21000000 * COIN
228228
self.check_mempool_result(
229-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: bad-txns-txouttotal-toolarge'}],
229+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-txouttotal-toolarge'}],
230230
rawtxs=[tx.serialize().hex()],
231231
)
232232

233233
self.log.info('A transaction with duplicate inputs')
234234
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
235235
tx.vin = [tx.vin[0]] * 2
236236
self.check_mempool_result(
237-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: bad-txns-inputs-duplicate'}],
237+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'bad-txns-inputs-duplicate'}],
238238
rawtxs=[tx.serialize().hex()],
239239
)
240240

@@ -243,49 +243,49 @@ def run_test(self):
243243
raw_tx_coinbase_spent = node.getrawtransaction(txid=node.decoderawtransaction(hexstring=raw_tx_in_block)['vin'][0]['txid'])
244244
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_coinbase_spent)))
245245
self.check_mempool_result(
246-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '16: coinbase'}],
246+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'coinbase'}],
247247
rawtxs=[tx.serialize().hex()],
248248
)
249249

250250
self.log.info('Some nonstandard transactions')
251251
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
252252
tx.nVersion = 3 # A version currently non-standard
253253
self.check_mempool_result(
254-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: version'}],
254+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'version'}],
255255
rawtxs=[tx.serialize().hex()],
256256
)
257257
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
258258
tx.vout[0].scriptPubKey = CScript([OP_0]) # Some non-standard script
259259
self.check_mempool_result(
260-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: scriptpubkey'}],
260+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'scriptpubkey'}],
261261
rawtxs=[tx.serialize().hex()],
262262
)
263263
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
264264
tx.vin[0].scriptSig = CScript([OP_HASH160]) # Some not-pushonly scriptSig
265265
self.check_mempool_result(
266-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: scriptsig-not-pushonly'}],
266+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'scriptsig-not-pushonly'}],
267267
rawtxs=[tx.serialize().hex()],
268268
)
269269
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
270270
output_p2sh_burn = CTxOut(nValue=540, scriptPubKey=CScript([OP_HASH160, hash160(b'burn'), OP_EQUAL]))
271271
num_scripts = 100000 // len(output_p2sh_burn.serialize()) # Use enough outputs to make the tx too large for our policy
272272
tx.vout = [output_p2sh_burn] * num_scripts
273273
self.check_mempool_result(
274-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: tx-size'}],
274+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'tx-size'}],
275275
rawtxs=[tx.serialize().hex()],
276276
)
277277
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
278278
tx.vout[0] = output_p2sh_burn
279279
tx.vout[0].nValue -= 1 # Make output smaller, such that it is dust for our policy
280280
self.check_mempool_result(
281-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: dust'}],
281+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'dust'}],
282282
rawtxs=[tx.serialize().hex()],
283283
)
284284
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
285285
tx.vout[0].scriptPubKey = CScript([OP_RETURN, b'\xff'])
286286
tx.vout = [tx.vout[0]] * 2
287287
self.check_mempool_result(
288-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: multi-op-return'}],
288+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'multi-op-return'}],
289289
rawtxs=[tx.serialize().hex()],
290290
)
291291

@@ -294,7 +294,7 @@ def run_test(self):
294294
tx.vin[0].nSequence -= 1 # Should be non-max, so locktime is not ignored
295295
tx.nLockTime = node.getblockcount() + 1
296296
self.check_mempool_result(
297-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: non-final'}],
297+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'non-final'}],
298298
rawtxs=[tx.serialize().hex()],
299299
)
300300

@@ -303,7 +303,7 @@ def run_test(self):
303303
tx.vin[0].nSequence = 2 # We could include it in the second block mined from now, but not the very next one
304304
# Can skip re-signing the tx because of early rejection
305305
self.check_mempool_result(
306-
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': '64: non-BIP68-final'}],
306+
result_expected=[{'txid': tx.rehash(), 'allowed': False, 'reject-reason': 'non-BIP68-final'}],
307307
rawtxs=[tx.serialize().hex()],
308308
maxfeerate=0,
309309
)

Diff for: test/functional/p2p_dos_header_tree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def run_test(self):
5757
} in self.nodes[0].getchaintips()
5858

5959
self.log.info("Feed all fork headers (fails due to checkpoint)")
60-
with self.nodes[0].assert_debug_log(['bad-fork-prior-to-checkpoint (code 67)']):
60+
with self.nodes[0].assert_debug_log(['bad-fork-prior-to-checkpoint']):
6161
self.nodes[0].p2p.send_message(msg_headers(self.headers_fork))
6262
self.nodes[0].p2p.wait_for_disconnect()
6363

Diff for: test/functional/rpc_rawtransaction.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def run_test(self):
454454
# Thus, testmempoolaccept should reject
455455
testres = self.nodes[2].testmempoolaccept([rawTxSigned['hex']], 0.00001000)[0]
456456
assert_equal(testres['allowed'], False)
457-
assert_equal(testres['reject-reason'], '256: absurdly-high-fee')
457+
assert_equal(testres['reject-reason'], 'absurdly-high-fee')
458458
# and sendrawtransaction should throw
459459
assert_raises_rpc_error(-26, "absurdly-high-fee", self.nodes[2].sendrawtransaction, rawTxSigned['hex'], 0.00001000)
460460
# and the following calls should both succeed
@@ -478,7 +478,7 @@ def run_test(self):
478478
# Thus, testmempoolaccept should reject
479479
testres = self.nodes[2].testmempoolaccept([rawTxSigned['hex']])[0]
480480
assert_equal(testres['allowed'], False)
481-
assert_equal(testres['reject-reason'], '256: absurdly-high-fee')
481+
assert_equal(testres['reject-reason'], 'absurdly-high-fee')
482482
# and sendrawtransaction should throw
483483
assert_raises_rpc_error(-26, "absurdly-high-fee", self.nodes[2].sendrawtransaction, rawTxSigned['hex'])
484484
# and the following calls should both succeed

0 commit comments

Comments
 (0)