diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -892,11 +892,7 @@ {"nodeid", RPCArg::Type::NUM, RPCArg::Optional::NO, "The node ID (see getpeerinfo for node IDs)"}, }, - RPCResult{RPCResult::Type::OBJ, - "", - "", - {{RPCResult::Type::STR, "warnings", /*optional=*/true, - "any warnings"}}}, + RPCResult{RPCResult::Type::OBJ_EMPTY, "", /*optional=*/false, "", {}}, RPCExamples{HelpExampleCli("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214a" "dbda81d7e2a3dd146f6ed09\" 0") + @@ -927,15 +923,15 @@ throw JSONRPCError(RPC_MISC_ERROR, "Block header missing"); } - UniValue result = UniValue::VOBJ; - if (index->nStatus.hasData()) { - result.pushKV("warnings", "Block already downloaded"); - } else if (!peerman.FetchBlock(config, nodeid, *index)) { + throw JSONRPCError(RPC_MISC_ERROR, "Block already downloaded"); + } + + if (!peerman.FetchBlock(config, nodeid, *index)) { throw JSONRPCError(RPC_MISC_ERROR, "Failed to fetch block from peer"); } - return result; + return UniValue::VOBJ; }, }; } diff --git a/src/rpc/util.h b/src/rpc/util.h --- a/src/rpc/util.h +++ b/src/rpc/util.h @@ -253,6 +253,7 @@ STR_AMOUNT, //!< Special string to represent a floating point amount STR_HEX, //!< Special string with only hex chars OBJ_DYN, //!< Special dictionary with keys that are not literals + OBJ_EMPTY, //!< Special type to allow empty OBJ ARR_FIXED, //!< Special array that has a fixed number of entries NUM_TIME, //!< Special numeric to denote unix epoch time ELISION, //!< Special type to denote elision (...) diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -785,6 +785,11 @@ return; } case Type::OBJ_DYN: + case Type::OBJ_EMPTY: { + sections.PushSection( + {indent + maybe_key + "{}", Description("empty JSON object")}); + return; + } case Type::OBJ: { sections.PushSection( {indent + maybe_key + "{", Description("json object")}); @@ -836,6 +841,7 @@ return UniValue::VARR == result.getType(); } case Type::OBJ_DYN: + case Type::OBJ_EMPTY: case Type::OBJ: { return UniValue::VOBJ == result.getType(); } diff --git a/test/functional/rpc_getblockfrompeer.py b/test/functional/rpc_getblockfrompeer.py --- a/test/functional/rpc_getblockfrompeer.py +++ b/test/functional/rpc_getblockfrompeer.py @@ -80,12 +80,14 @@ self.log.info("Successful fetch") result = self.nodes[0].getblockfrompeer(short_tip, peer_0_peer_1_id) self.wait_until(lambda: self.check_for_block(short_tip), timeout=1) - assert "warnings" not in result + assert_equal(result, {}) self.log.info("Don't fetch blocks we already have") - result = self.nodes[0].getblockfrompeer(short_tip, peer_0_peer_1_id) - assert "warnings" in result - assert_equal(result["warnings"], "Block already downloaded") + assert_raises_rpc_error(-1, + "Block already downloaded", + self.nodes[0].getblockfrompeer, + short_tip, + peer_0_peer_1_id) if __name__ == '__main__':