@@ -775,8 +775,8 @@ static RPCHelpMan getblockfrompeer()
775775 " \n We must have the header for this block, e.g. using submitheader.\n "
776776 " \n Returns {} if a block-request was successfully scheduled\n " ,
777777 {
778- {" blockhash " , RPCArg::Type::STR_HEX, RPCArg::Optional::NO, " The block hash" },
779- {" nodeid " , RPCArg::Type::NUM, RPCArg::Optional::NO, " The node ID (see getpeerinfo for node IDs)" },
778+ {" block_hash " , RPCArg::Type::STR_HEX, RPCArg::Optional::NO, " The block hash to try to fetch " },
779+ {" peer_id " , RPCArg::Type::NUM, RPCArg::Optional::NO, " The peer to fetch it from (see getpeerinfo for peer IDs)" },
780780 },
781781 RPCResult{RPCResult::Type::OBJ, " " , " " ,
782782 {
@@ -791,18 +791,11 @@ static RPCHelpMan getblockfrompeer()
791791 const NodeContext& node = EnsureAnyNodeContext (request.context );
792792 ChainstateManager& chainman = EnsureChainman (node);
793793 PeerManager& peerman = EnsurePeerman (node);
794- CConnman& connman = EnsureConnman (node);
795-
796- uint256 hash (ParseHashV (request.params [0 ], " hash" ));
797794
798- const NodeId nodeid = static_cast <NodeId>(request.params [1 ].get_int64 ());
799-
800- // Check that the peer with nodeid exists
801- if (!connman.ForNode (nodeid, [](CNode* node) {return true ;})) {
802- throw JSONRPCError (RPC_MISC_ERROR, strprintf (" Peer nodeid %d does not exist" , nodeid));
803- }
795+ const uint256& block_hash{ParseHashV (request.params [0 ], " block_hash" )};
796+ const NodeId peer_id{request.params [1 ].get_int64 ()};
804797
805- const CBlockIndex* const index = WITH_LOCK (cs_main, return chainman.m_blockman .LookupBlockIndex (hash ););
798+ const CBlockIndex* const index = WITH_LOCK (cs_main, return chainman.m_blockman .LookupBlockIndex (block_hash ););
806799
807800 if (!index) {
808801 throw JSONRPCError (RPC_MISC_ERROR, " Block header missing" );
@@ -812,8 +805,8 @@ static RPCHelpMan getblockfrompeer()
812805
813806 if (index->nStatus & BLOCK_HAVE_DATA) {
814807 result.pushKV (" warnings" , " Block already downloaded" );
815- } else if (! peerman.FetchBlock (nodeid, hash, *index)) {
816- throw JSONRPCError (RPC_MISC_ERROR, " Failed to fetch block from peer " );
808+ } else if (const auto err{ peerman.FetchBlock (peer_id, *index)} ) {
809+ throw JSONRPCError (RPC_MISC_ERROR, err. value () );
817810 }
818811 return result;
819812},
@@ -3053,7 +3046,7 @@ static const CRPCCommand commands[] =
30533046 { " blockchain" , " getbestchainlock" , &getbestchainlock, {} },
30543047 { " blockchain" , " getblockcount" , &getblockcount, {} },
30553048 { " blockchain" , " getblock" , &getblock, {" blockhash" ," verbosity|verbose" } },
3056- { " blockchain" , " getblockfrompeer" , &getblockfrompeer, {" blockhash " , " nodeid " }},
3049+ { " blockchain" , " getblockfrompeer" , &getblockfrompeer, {" block_hash " , " peer_id " }},
30573050 { " blockchain" , " getblockhashes" , &getblockhashes, {" high" ," low" } },
30583051 { " blockchain" , " getblockhash" , &getblockhash, {" height" } },
30593052 { " blockchain" , " getblockheader" , &getblockheader, {" blockhash" ," verbose" } },
0 commit comments