mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-21 20:28:59 +02: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"},
|
||||
{"nodeid", RPCArg::Type::NUM, RPCArg::Optional::NO, "The node ID (see getpeerinfo for node IDs)"},
|
||||
},
|
||||
RPCResult{RPCResult::Type::OBJ, "", "",
|
||||
{
|
||||
{RPCResult::Type::STR, "warnings", /*optional=*/true, "any warnings"},
|
||||
}},
|
||||
RPCResult{RPCResult::Type::OBJ_EMPTY, "", /*optional=*/ false, "", {}},
|
||||
RPCExamples{
|
||||
HelpExampleCli("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")
|
||||
+ HelpExampleRpc("getblockfrompeer", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 0")
|
||||
@@ -816,14 +813,14 @@ static RPCHelpMan getblockfrompeer()
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Block header missing");
|
||||
}
|
||||
|
||||
UniValue result = UniValue::VOBJ;
|
||||
|
||||
if (index->nStatus & BLOCK_HAVE_DATA) {
|
||||
result.pushKV("warnings", "Block already downloaded");
|
||||
} else if (!peerman.FetchBlock(nodeid, *index)) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Block already downloaded");
|
||||
}
|
||||
|
||||
if (!peerman.FetchBlock(nodeid, *index)) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Failed to fetch block from peer");
|
||||
}
|
||||
return result;
|
||||
return UniValue::VOBJ;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user