From 9560439a567d12183d95d1b0a94ecf0f47053d2a Mon Sep 17 00:00:00 2001 From: pasta Date: Wed, 11 Nov 2026 02:26:05 +0000 Subject: [PATCH] fix: skip undecoded provider payloads in transaction JSON Unsupported provider transaction versions can deserialize without network information. Omit their optional decoded payload objects instead of letting JSON rendering throw through the REST block handler, and retain the raw payload bytes. Co-Authored-By: GPT 6.1 Sol --- src/core_write.cpp | 4 +-- test/functional/interface_rest.py | 45 +++++++++++++++++++++++++++++++ test/functional/rpc_deprecated.py | 10 ++++--- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/core_write.cpp b/src/core_write.cpp index d3ae39fb367c..38848367f55d 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -289,11 +289,11 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry } if (tx.nType == TRANSACTION_PROVIDER_REGISTER) { - if (const auto opt_proTx = GetTxPayload(tx)) { + if (const auto opt_proTx = GetTxPayload(tx); opt_proTx && opt_proTx->netInfo) { entry.pushKV("proRegTx", opt_proTx->ToJson()); } } else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_SERVICE) { - if (const auto opt_proTx = GetTxPayload(tx)) { + if (const auto opt_proTx = GetTxPayload(tx); opt_proTx && opt_proTx->netInfo) { entry.pushKV("proUpServTx", opt_proTx->ToJson()); } } else if (tx.nType == TRANSACTION_PROVIDER_UPDATE_REGISTRAR) { diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py index 37e47ed9575c..5aa514a8e068 100755 --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -12,10 +12,16 @@ import urllib.parse +from test_framework.blocktools import create_block, create_coinbase from test_framework.messages import ( BLOCK_HEADER_SIZE, COIN, + COutPoint, + CTransaction, + CTxIn, + CTxOut, ) +from test_framework.script import CScript, OP_TRUE from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, @@ -451,5 +457,44 @@ def run_test(self): self.sync_all() assert_equal(self.test_rest_request(f"/deploymentinfo/{header_only_hash}"), self.nodes[0].getdeploymentinfo(header_only_hash)) + self.log.info("Test rendering stored ProTx payloads with unsupported versions") + node = self.nodes[0] + tip = node.getbestblockhash() + protxes = [] + for tx_type in (1, 2): + for version in (0, 65535): + tx = CTransaction() + tx.nVersion = 3 + tx.nType = tx_type + tx.vin = [CTxIn(COutPoint(0x1234, len(protxes)))] + tx.vout = [CTxOut(1000, CScript([OP_TRUE]))] + tx.vExtraPayload = version.to_bytes(2, "little") + tx.calc_sha256() + protxes.append(tx) + block = create_block( + tmpl=node.getblocktemplate(), + coinbase=create_coinbase(node.getblockcount() + 1, dip4_activated=True, v20_activated=True), + txlist=protxes, + ) + block.solve() + assert_equal(node.submitblock(block.serialize().hex()), "bad-protx-version") + assert_equal(node.getblock(block.hash, 0), block.serialize().hex()) + + for deprecated_service in (False, True): + if deprecated_service: + self.restart_node(0, extra_args=self.extra_args[0] + ["-deprecatedrpc=service"]) + self.test_rest_request(f"/block/notxdetails/{block.hash}") + block_json = self.test_rest_request(f"/block/{block.hash}") + assert_equal(block_json, node.getblock(block.hash, 2)) + assert_equal(len(block_json["tx"]), len(block.vtx)) + for tx, tx_json in zip(protxes, block_json["tx"][1:]): + field = "proRegTx" if tx.nType == 1 else "proUpServTx" + for decoded in (tx_json, node.decoderawtransaction(tx.serialize().hex()), + node.getrawtransaction(tx.hash, True, block.hash)): + assert field not in decoded + assert_equal(decoded["extraPayload"], tx.vExtraPayload.hex()) + assert_equal(node.getbestblockhash(), tip) + assert_equal(self.test_rest_request("/chaininfo")["bestblockhash"], tip) + if __name__ == '__main__': RESTTest().main() diff --git a/test/functional/rpc_deprecated.py b/test/functional/rpc_deprecated.py index 7b5226591c43..e702f543109b 100755 --- a/test/functional/rpc_deprecated.py +++ b/test/functional/rpc_deprecated.py @@ -63,11 +63,13 @@ def test_malformed_deprecated_service_rawtransactions(self): self.log.info("Test malformed provider payloads do not crash -deprecatedrpc=service") node = self.nodes[2] block_count = node.getblockcount() - for tx_hex in [ - "03000100000000000000020000", # ProRegTx with only nVersion=0 payload - "03000200000000000000020000", # ProUpServTx with only nVersion=0 payload + for tx_hex, payload_field in [ + ("03000100000000000000020000", "proRegTx"), # ProRegTx with only nVersion=0 payload + ("03000200000000000000020000", "proUpServTx"), # ProUpServTx with only nVersion=0 payload ]: - assert_raises_rpc_error(-1, "Internal bug detected: obj.netInfo", node.decoderawtransaction, tx_hex) + decoded = node.decoderawtransaction(tx_hex) + assert payload_field not in decoded + assert_equal(decoded["extraPayload"], "0000") assert_equal(node.getblockcount(), block_count) if __name__ == '__main__':