From 354e1256381125e9f2703b0fa59ecd8480afec59 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Sat, 10 Dec 2022 09:54:23 +0000 Subject: [PATCH 01/10] Merge bitcoin/bitcoin#26213: rpc: Strict type checking for RPC boolean parameters fa0153e609caf61a59efb0779e754861edc1684d refactor: Replace isTrue with get_bool (MarcoFalke) fa2cc5d1d66aa00e828d1bb65b9923f76fbdf4e1 bugfix: Strict type checking for RPC boolean parameters (MarcoFalke) Pull request description: ACKs for top commit: ryanofsky: Code review ACK fa0153e609caf61a59efb0779e754861edc1684d furszy: Code ACK fa0153e6 Tree-SHA512: b221f823c69d90c94447fd491071ff3659cfd512872b495ebc3e711f50633351974102c9ef7e50fa4a393c4131d349adea8fd41cc9d66f1f31e1f5e7a5f78757 Co-authored-by: fanquake --- doc/release-notes-26213.md | 8 ++++++++ src/rpc/net.cpp | 6 ++---- test/functional/rpc_net.py | 3 +++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 doc/release-notes-26213.md diff --git a/doc/release-notes-26213.md b/doc/release-notes-26213.md new file mode 100644 index 000000000000..2fba5ec6137f --- /dev/null +++ b/doc/release-notes-26213.md @@ -0,0 +1,8 @@ +Low-level changes +================= + +- Previously `setban`, `addpeeraddress`, `walletcreatefundedpsbt`, methods + allowed non-boolean and non-null values to be passed as boolean parameters. + Any string, number, array, or object value that was passed would be treated + as false. After this change, passing any value except `true`, `false`, or + `null` now triggers a JSON value is not of expected type error. (#7666) diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 7457eae7b1b5..7b054e3b4769 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -797,9 +797,7 @@ static RPCHelpMan setban() if (!request.params[2].isNull()) banTime = request.params[2].getInt(); - bool absolute = false; - if (request.params[3].isTrue()) - absolute = true; + const bool absolute{request.params[3].isNull() ? false : request.params[3].get_bool()}; if (absolute && banTime < GetTime()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Absolute timestamp is in the past"); @@ -1029,7 +1027,7 @@ static RPCHelpMan addpeeraddress() const std::string& addr_string{request.params[0].get_str()}; const auto port{request.params[1].getInt()}; - const bool tried{request.params[2].isTrue()}; + const bool tried{request.params[2].isNull() ? false : request.params[2].get_bool()}; UniValue obj(UniValue::VOBJ); std::optional net_addr{LookupHost(addr_string, false)}; diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 2cf351a52ae0..0c186f72e0f9 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -351,6 +351,9 @@ def test_addpeeraddress(self): assert_equal(node.addpeeraddress(address="", port=8333), {"success": False}) assert_equal(node.getnodeaddresses(count=0), []) + self.log.debug("Test that non-bool tried fails") + assert_raises_rpc_error(-3, "JSON value of type string is not of expected type bool", self.nodes[0].addpeeraddress, address="1.2.3.4", tried="True", port=1234) + self.log.debug("Test that adding an address with invalid port fails") assert_raises_rpc_error(-1, "JSON integer out of range", self.nodes[0].addpeeraddress, address="1.2.3.4", port=-1) assert_raises_rpc_error(-1, "JSON integer out of range", self.nodes[0].addpeeraddress, address="1.2.3.4", port=65536) From f3ec293d1efaf3e3177ad10b3b1b771a59d5af35 Mon Sep 17 00:00:00 2001 From: Konstantin Akimov Date: Tue, 13 Dec 2022 17:59:26 -0500 Subject: [PATCH 02/10] Merge bitcoin/bitcoin#23319: rpc: Return fee and prevout (utxos) to getrawtransaction f86697163e5cdbc3bc4a65cfb7dbaa3d9eb602a9 rpc: Return fee and prevout(s) to getrawtransaction (Douglas Chimento) Pull request description: Add fee response in BTC to getrawtransaction #23264 ### For Reviewers * Verbose arg is now an int * Verbose = 2 includes a `fee` field and `prevout` * [./test/functional/rpc_rawtransaction.py](./test/functional/rpc_rawtransaction.py) contains a new test to validate fields of new verbosity 2 (not the values) ``` bitcoin-cli -chain=test getrawtransaction 9ae533f7da9be4a34997db78343a8d8d6d6186b6bba3959e56f416a5c70e7de4 2 000000000000001d442e556146d5f2841d85150c200e8d8b8a4b5005b13878f6 ``` ``` "in_active_chain": true, "txid": "9ae533f7da9be4a34997db78343a8d8d6d6186b6bba3959e56f416a5c70e7de4", "hash": "7f23e3f3a0a256ddea1d35ffd43e9afdd67cc68389ef1a804bb20c76abd6863e", .... "vin": [ { "txid": "23fc75d6d74f6f97e225839af69ff36a612fe04db58a4414ec4828d1749a05a0", "vout": 0, "scriptSig": { "asm": "", "hex": "" }, "prevout": { "generated": false, "height": 2099486, "value": 0.00017764, "scriptPubKey": { "asm": "0 7846ce1ced3253d8bd43008db2ca364cc722f5a2", "hex": "00147846ce1ced3253d8bd43008db2ca364cc722f5a2", "address": "tb1q0prvu88dxffa302rqzxm9j3kfnrj9adzk49mlp", "type": "witness_v0_keyhash" } }, "sequence": 4294967295 }, ... "fee": 0.00000762 } ``` ACKs for top commit: achow101: ACK f86697163e5cdbc3bc4a65cfb7dbaa3d9eb602a9 aureleoules: ACK f86697163e5cdbc3bc4a65cfb7dbaa3d9eb602a9 hernanmarino: re ACK f86697163e5cdbc3bc4a65cfb7dbaa3d9eb602a9 pablomartin4btc: re-tACK f86697163e5cdbc3bc4a65cfb7dbaa3d9eb602a9 Tree-SHA512: 591fdc285d74fa7803e04ad01c7b70bc20fac6b1369e7bd5b8e2cde9b750ea52d6c70d79225b74bef4f4bbc0fb960877778017184e146119da4a55f9593d1224 Co-authored-by: Andrew Chow --- src/rpc/blockchain.cpp | 2 +- src/rpc/client.cpp | 2 + src/rpc/rawtransaction.cpp | 129 +++++++++++++++++++------- test/functional/rpc_rawtransaction.py | 82 ++++++++++++++-- 4 files changed, 176 insertions(+), 39 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 974697e39e12..96ce9cb6a43e 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -83,7 +83,7 @@ static GlobalMutex cs_blockchange; static std::condition_variable cond_blockchange; static CUpdatedBlock latestblock GUARDED_BY(cs_blockchange); -extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool& mempool, const Chainstate& active_chainstate, const chainlock::Chainlocks& chainlocks, const llmq::CInstantSendManager& isman, const SpentIndex* spent_index, UniValue& entry, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS); +extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, const CTxMemPool& mempool, const Chainstate& active_chainstate, const chainlock::Chainlocks& chainlocks, const llmq::CInstantSendManager& isman, const SpentIndex* spent_index, UniValue& entry, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS); /* Calculate the difficulty for a given block index. */ diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 972e99c94924..05c007a9834b 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -128,9 +128,11 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getmerkleblocks", 2, "count" }, { "gettransaction", 1, "include_watchonly" }, { "gettransaction", 2, "verbose" }, + { "getrawtransaction", 1, "verbosity" }, { "getrawtransaction", 1, "verbose" }, { "getislocks", 0, "txids" }, { "getrawtransactionmulti", 0, "transactions" }, + { "getrawtransactionmulti", 1, "verbosity" }, { "getrawtransactionmulti", 1, "verbose" }, { "gettxchainlocks", 0, "txids" }, { "createrawtransaction", 0, "inputs" }, diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 9d55adcc00cb..7012262e571f 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -37,6 +37,7 @@ #include