From 34d5399211eeb61e7e7961c301fb2ddea8aa3f6a Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Wed, 8 Dec 2021 20:16:36 +0700 Subject: rpc: more detailed errors for getblockfrompeer --- src/rpc/blockchain.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/rpc/blockchain.cpp') 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; }, -- cgit v1.2.3