diff options
author | Sjors Provoost <sjors@sprovoost.nl> | 2021-12-08 20:16:36 +0700 |
---|---|---|
committer | Sjors Provoost <sjors@sprovoost.nl> | 2021-12-24 16:29:03 +0100 |
commit | 34d5399211eeb61e7e7961c301fb2ddea8aa3f6a (patch) | |
tree | adc860d9eaeb6ae1de648eef86415988a7fd8352 /src/rpc/blockchain.cpp | |
parent | 60243cac7286e4c4bdda7094bef4cf6d1564b583 (diff) | |
download | bitcoin-34d5399211eeb61e7e7961c301fb2ddea8aa3f6a.tar.xz |
rpc: more detailed errors for getblockfrompeer
Diffstat (limited to 'src/rpc/blockchain.cpp')
-rw-r--r-- | src/rpc/blockchain.cpp | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 27b04ed834..64c852f6a5 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -797,16 +797,10 @@ static RPCHelpMan getblockfrompeer() const NodeContext& node = EnsureAnyNodeContext(request.context); ChainstateManager& chainman = EnsureChainman(node); PeerManager& peerman = EnsurePeerman(node); - CConnman& connman = EnsureConnman(node); - const uint256 hash(ParseHashV(request.params[0], "hash")); + const uint256& hash{ParseHashV(request.params[0], "hash")}; const NodeId nodeid{request.params[1].get_int64()}; - // Check that the peer with nodeid exists - if (!connman.ForNode(nodeid, [](CNode* node) {return true;})) { - throw JSONRPCError(RPC_MISC_ERROR, strprintf("Peer nodeid %d does not exist", nodeid)); - } - const CBlockIndex* const index = WITH_LOCK(cs_main, return chainman.m_blockman.LookupBlockIndex(hash);); if (!index) { @@ -817,8 +811,8 @@ static RPCHelpMan getblockfrompeer() throw JSONRPCError(RPC_MISC_ERROR, "Block already downloaded"); } - if (!peerman.FetchBlock(nodeid, *index)) { - throw JSONRPCError(RPC_MISC_ERROR, "Failed to fetch block from peer"); + if (const auto err{peerman.FetchBlock(nodeid, *index)}) { + throw JSONRPCError(RPC_MISC_ERROR, err.value()); } return UniValue::VOBJ; }, |