Skip to content

Commit 60243ca

Browse files
committed
rpc: turn already downloaded into error in getblockfrompeer
1 parent 809d66b commit 60243ca

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/rpc/blockchain.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,7 @@ static RPCHelpMan getblockfrompeer()
787787
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
788788
{"nodeid", RPCArg::Type::NUM, RPCArg::Optional::NO, "The node ID (see getpeerinfo for node IDs)"},
789789
},
790-
RPCResult{RPCResult::Type::OBJ, "", "",
791-
{
792-
{RPCResult::Type::STR, "warnings", /*optional=*/true, "any warnings"},
793-
}},
790+
RPCResult{RPCResult::Type::OBJ_EMPTY, "", /*optional=*/ false, "", {}},
794791
RPCExamples{
795792
HelpExampleCli("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")
796793
+ HelpExampleRpc("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")
@@ -816,14 +813,14 @@ static RPCHelpMan getblockfrompeer()
816813
throw JSONRPCError(RPC_MISC_ERROR, "Block header missing");
817814
}
818815

819-
UniValue result = UniValue::VOBJ;
820-
821816
if (index->nStatus & BLOCK_HAVE_DATA) {
822-
result.pushKV("warnings", "Block already downloaded");
823-
} else if (!peerman.FetchBlock(nodeid, *index)) {
817+
throw JSONRPCError(RPC_MISC_ERROR, "Block already downloaded");
818+
}
819+
820+
if (!peerman.FetchBlock(nodeid, *index)) {
824821
throw JSONRPCError(RPC_MISC_ERROR, "Failed to fetch block from peer");
825822
}
826-
return result;
823+
return UniValue::VOBJ;
827824
},
828825
};
829826
}

test/functional/rpc_getblockfrompeer.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ def run_test(self):
6161
self.log.info("Successful fetch")
6262
result = self.nodes[0].getblockfrompeer(short_tip, peer_0_peer_1_id)
6363
self.wait_until(lambda: self.check_for_block(short_tip), timeout=1)
64-
assert(not "warnings" in result)
64+
assert_equal(result, {})
6565

6666
self.log.info("Don't fetch blocks we already have")
67-
result = self.nodes[0].getblockfrompeer(short_tip, peer_0_peer_1_id)
68-
assert("warnings" in result)
69-
assert_equal(result["warnings"], "Block already downloaded")
67+
assert_raises_rpc_error(-1, "Block already downloaded", self.nodes[0].getblockfrompeer, short_tip, peer_0_peer_1_id)
7068

7169
if __name__ == '__main__':
7270
GetBlockFromPeerTest().main()

0 commit comments

Comments
 (0)