mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-10 04:33:59 +01:00
rpc: turn already downloaded into error in getblockfrompeer
This commit is contained in:
@@ -787,10 +787,7 @@ static RPCHelpMan getblockfrompeer()
|
|||||||
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
|
{"blockhash", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The block hash"},
|
||||||
{"nodeid", RPCArg::Type::NUM, RPCArg::Optional::NO, "The node ID (see getpeerinfo for node IDs)"},
|
{"nodeid", RPCArg::Type::NUM, RPCArg::Optional::NO, "The node ID (see getpeerinfo for node IDs)"},
|
||||||
},
|
},
|
||||||
RPCResult{RPCResult::Type::OBJ, "", "",
|
RPCResult{RPCResult::Type::OBJ_EMPTY, "", /*optional=*/ false, "", {}},
|
||||||
{
|
|
||||||
{RPCResult::Type::STR, "warnings", /*optional=*/true, "any warnings"},
|
|
||||||
}},
|
|
||||||
RPCExamples{
|
RPCExamples{
|
||||||
HelpExampleCli("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")
|
HelpExampleCli("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")
|
||||||
+ HelpExampleRpc("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")
|
+ HelpExampleRpc("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")
|
||||||
@@ -816,14 +813,14 @@ static RPCHelpMan getblockfrompeer()
|
|||||||
throw JSONRPCError(RPC_MISC_ERROR, "Block header missing");
|
throw JSONRPCError(RPC_MISC_ERROR, "Block header missing");
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue result = UniValue::VOBJ;
|
|
||||||
|
|
||||||
if (index->nStatus & BLOCK_HAVE_DATA) {
|
if (index->nStatus & BLOCK_HAVE_DATA) {
|
||||||
result.pushKV("warnings", "Block already downloaded");
|
throw JSONRPCError(RPC_MISC_ERROR, "Block already downloaded");
|
||||||
} else if (!peerman.FetchBlock(nodeid, *index)) {
|
}
|
||||||
|
|
||||||
|
if (!peerman.FetchBlock(nodeid, *index)) {
|
||||||
throw JSONRPCError(RPC_MISC_ERROR, "Failed to fetch block from peer");
|
throw JSONRPCError(RPC_MISC_ERROR, "Failed to fetch block from peer");
|
||||||
}
|
}
|
||||||
return result;
|
return UniValue::VOBJ;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,12 +61,10 @@ class GetBlockFromPeerTest(BitcoinTestFramework):
|
|||||||
self.log.info("Successful fetch")
|
self.log.info("Successful fetch")
|
||||||
result = self.nodes[0].getblockfrompeer(short_tip, peer_0_peer_1_id)
|
result = self.nodes[0].getblockfrompeer(short_tip, peer_0_peer_1_id)
|
||||||
self.wait_until(lambda: self.check_for_block(short_tip), timeout=1)
|
self.wait_until(lambda: self.check_for_block(short_tip), timeout=1)
|
||||||
assert(not "warnings" in result)
|
assert_equal(result, {})
|
||||||
|
|
||||||
self.log.info("Don't fetch blocks we already have")
|
self.log.info("Don't fetch blocks we already have")
|
||||||
result = self.nodes[0].getblockfrompeer(short_tip, peer_0_peer_1_id)
|
assert_raises_rpc_error(-1, "Block already downloaded", self.nodes[0].getblockfrompeer, short_tip, peer_0_peer_1_id)
|
||||||
assert("warnings" in result)
|
|
||||||
assert_equal(result["warnings"], "Block already downloaded")
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
GetBlockFromPeerTest().main()
|
GetBlockFromPeerTest().main()
|
||||||
|
|||||||
Reference in New Issue
Block a user