@@ -775,8 +775,8 @@ static RPCHelpMan getblockfrompeer()
775
775
" \n We must have the header for this block, e.g. using submitheader.\n "
776
776
" \n Returns {} if a block-request was successfully scheduled\n " ,
777
777
{
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)" },
780
780
},
781
781
RPCResult{RPCResult::Type::OBJ, " " , " " ,
782
782
{
@@ -791,18 +791,11 @@ static RPCHelpMan getblockfrompeer()
791
791
const NodeContext& node = EnsureAnyNodeContext (request.context );
792
792
ChainstateManager& chainman = EnsureChainman (node);
793
793
PeerManager& peerman = EnsurePeerman (node);
794
- CConnman& connman = EnsureConnman (node);
795
-
796
- uint256 hash (ParseHashV (request.params [0 ], " hash" ));
797
794
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 ()};
804
797
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 ););
806
799
807
800
if (!index) {
808
801
throw JSONRPCError (RPC_MISC_ERROR, " Block header missing" );
@@ -812,8 +805,8 @@ static RPCHelpMan getblockfrompeer()
812
805
813
806
if (index->nStatus & BLOCK_HAVE_DATA) {
814
807
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 () );
817
810
}
818
811
return result;
819
812
},
@@ -3053,7 +3046,7 @@ static const CRPCCommand commands[] =
3053
3046
{ " blockchain" , " getbestchainlock" , &getbestchainlock, {} },
3054
3047
{ " blockchain" , " getblockcount" , &getblockcount, {} },
3055
3048
{ " blockchain" , " getblock" , &getblock, {" blockhash" ," verbosity|verbose" } },
3056
- { " blockchain" , " getblockfrompeer" , &getblockfrompeer, {" blockhash " , " nodeid " }},
3049
+ { " blockchain" , " getblockfrompeer" , &getblockfrompeer, {" block_hash " , " peer_id " }},
3057
3050
{ " blockchain" , " getblockhashes" , &getblockhashes, {" high" ," low" } },
3058
3051
{ " blockchain" , " getblockhash" , &getblockhash, {" height" } },
3059
3052
{ " blockchain" , " getblockheader" , &getblockheader, {" blockhash" ," verbose" } },
0 commit comments