mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
refactor: drop redundant hash argument from FetchBlock
This commit is contained in:
parent
8d1a3e6498
commit
0e3d7c5ee1
3 changed files with 11 additions and 12 deletions
|
@ -312,7 +312,7 @@ public:
|
||||||
/** Implement PeerManager */
|
/** Implement PeerManager */
|
||||||
void StartScheduledTasks(CScheduler& scheduler) override;
|
void StartScheduledTasks(CScheduler& scheduler) override;
|
||||||
void CheckForStaleTipAndEvictPeers() override;
|
void CheckForStaleTipAndEvictPeers() override;
|
||||||
bool FetchBlock(NodeId id, const uint256& hash, const CBlockIndex& index) override;
|
bool FetchBlock(NodeId id, const CBlockIndex& block_index) override;
|
||||||
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override;
|
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override;
|
||||||
bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; }
|
bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; }
|
||||||
void SendPings() override;
|
void SendPings() override;
|
||||||
|
@ -1428,7 +1428,7 @@ bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex)
|
||||||
(GetBlockProofEquivalentTime(*pindexBestHeader, *pindex, *pindexBestHeader, m_chainparams.GetConsensus()) < STALE_RELAY_AGE_LIMIT);
|
(GetBlockProofEquivalentTime(*pindexBestHeader, *pindex, *pindexBestHeader, m_chainparams.GetConsensus()) < STALE_RELAY_AGE_LIMIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PeerManagerImpl::FetchBlock(NodeId id, const uint256& hash, const CBlockIndex& index)
|
bool PeerManagerImpl::FetchBlock(NodeId id, const CBlockIndex& block_index)
|
||||||
{
|
{
|
||||||
if (fImporting || fReindex) return false;
|
if (fImporting || fReindex) return false;
|
||||||
|
|
||||||
|
@ -1440,9 +1440,10 @@ bool PeerManagerImpl::FetchBlock(NodeId id, const uint256& hash, const CBlockInd
|
||||||
if (!state->fHaveWitness) return false;
|
if (!state->fHaveWitness) return false;
|
||||||
|
|
||||||
// Mark block as in-flight unless it already is
|
// Mark block as in-flight unless it already is
|
||||||
if (!BlockRequested(id, index)) return false;
|
if (!BlockRequested(id, block_index)) return false;
|
||||||
|
|
||||||
// Construct message to request the block
|
// Construct message to request the block
|
||||||
|
const uint256& hash{block_index.GetBlockHash()};
|
||||||
std::vector<CInv> invs{CInv(MSG_BLOCK | MSG_WITNESS_FLAG, hash)};
|
std::vector<CInv> invs{CInv(MSG_BLOCK | MSG_WITNESS_FLAG, hash)};
|
||||||
|
|
||||||
// Send block request message to the peer
|
// Send block request message to the peer
|
||||||
|
|
|
@ -45,12 +45,11 @@ public:
|
||||||
/**
|
/**
|
||||||
* Attempt to manually fetch block from a given peer. We must already have the header.
|
* Attempt to manually fetch block from a given peer. We must already have the header.
|
||||||
*
|
*
|
||||||
* @param[in] id The peer id
|
* @param[in] id The peer id
|
||||||
* @param[in] hash The block hash
|
* @param[in] block_index The blockindex
|
||||||
* @param[in] pindex The blockindex
|
* @returns Whether a request was successfully made
|
||||||
* @returns Whether a request was successfully made
|
|
||||||
*/
|
*/
|
||||||
virtual bool FetchBlock(NodeId id, const uint256& hash, const CBlockIndex& pindex) = 0;
|
virtual bool FetchBlock(NodeId id, const CBlockIndex& block_index) = 0;
|
||||||
|
|
||||||
/** Begin running background tasks, should only be called once */
|
/** Begin running background tasks, should only be called once */
|
||||||
virtual void StartScheduledTasks(CScheduler& scheduler) = 0;
|
virtual void StartScheduledTasks(CScheduler& scheduler) = 0;
|
||||||
|
|
|
@ -801,9 +801,8 @@ static RPCHelpMan getblockfrompeer()
|
||||||
PeerManager& peerman = EnsurePeerman(node);
|
PeerManager& peerman = EnsurePeerman(node);
|
||||||
CConnman& connman = EnsureConnman(node);
|
CConnman& connman = EnsureConnman(node);
|
||||||
|
|
||||||
uint256 hash(ParseHashV(request.params[0], "hash"));
|
const uint256 hash(ParseHashV(request.params[0], "hash"));
|
||||||
|
const NodeId nodeid{request.params[1].get_int64()};
|
||||||
const NodeId nodeid = static_cast<NodeId>(request.params[1].get_int64());
|
|
||||||
|
|
||||||
// Check that the peer with nodeid exists
|
// Check that the peer with nodeid exists
|
||||||
if (!connman.ForNode(nodeid, [](CNode* node) {return true;})) {
|
if (!connman.ForNode(nodeid, [](CNode* node) {return true;})) {
|
||||||
|
@ -820,7 +819,7 @@ static RPCHelpMan getblockfrompeer()
|
||||||
|
|
||||||
if (index->nStatus & BLOCK_HAVE_DATA) {
|
if (index->nStatus & BLOCK_HAVE_DATA) {
|
||||||
result.pushKV("warnings", "Block already downloaded");
|
result.pushKV("warnings", "Block already downloaded");
|
||||||
} else if (!peerman.FetchBlock(nodeid, hash, *index)) {
|
} else if (!peerman.FetchBlock(nodeid, *index)) {
|
||||||
throw JSONRPCError(RPC_MISC_ERROR, "Failed to fetch block from peer");
|
throw JSONRPCError(RPC_MISC_ERROR, "Failed to fetch block from peer");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue