Skip to content

Commit 0e3d7c5

Browse files
committed
refactor: drop redundant hash argument from FetchBlock
1 parent 8d1a3e6 commit 0e3d7c5

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/net_processing.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class PeerManagerImpl final : public PeerManager
312312
/** Implement PeerManager */
313313
void StartScheduledTasks(CScheduler& scheduler) override;
314314
void CheckForStaleTipAndEvictPeers() override;
315-
bool FetchBlock(NodeId id, const uint256& hash, const CBlockIndex& index) override;
315+
bool FetchBlock(NodeId id, const CBlockIndex& block_index) override;
316316
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override;
317317
bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; }
318318
void SendPings() override;
@@ -1428,7 +1428,7 @@ bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex)
14281428
(GetBlockProofEquivalentTime(*pindexBestHeader, *pindex, *pindexBestHeader, m_chainparams.GetConsensus()) < STALE_RELAY_AGE_LIMIT);
14291429
}
14301430

1431-
bool PeerManagerImpl::FetchBlock(NodeId id, const uint256& hash, const CBlockIndex& index)
1431+
bool PeerManagerImpl::FetchBlock(NodeId id, const CBlockIndex& block_index)
14321432
{
14331433
if (fImporting || fReindex) return false;
14341434

@@ -1440,9 +1440,10 @@ bool PeerManagerImpl::FetchBlock(NodeId id, const uint256& hash, const CBlockInd
14401440
if (!state->fHaveWitness) return false;
14411441

14421442
// Mark block as in-flight unless it already is
1443-
if (!BlockRequested(id, index)) return false;
1443+
if (!BlockRequested(id, block_index)) return false;
14441444

14451445
// Construct message to request the block
1446+
const uint256& hash{block_index.GetBlockHash()};
14461447
std::vector<CInv> invs{CInv(MSG_BLOCK | MSG_WITNESS_FLAG, hash)};
14471448

14481449
// Send block request message to the peer

src/net_processing.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
4545
/**
4646
* Attempt to manually fetch block from a given peer. We must already have the header.
4747
*
48-
* @param[in] id The peer id
49-
* @param[in] hash The block hash
50-
* @param[in] pindex The blockindex
51-
* @returns Whether a request was successfully made
48+
* @param[in] id The peer id
49+
* @param[in] block_index The blockindex
50+
* @returns Whether a request was successfully made
5251
*/
53-
virtual bool FetchBlock(NodeId id, const uint256& hash, const CBlockIndex& pindex) = 0;
52+
virtual bool FetchBlock(NodeId id, const CBlockIndex& block_index) = 0;
5453

5554
/** Begin running background tasks, should only be called once */
5655
virtual void StartScheduledTasks(CScheduler& scheduler) = 0;

src/rpc/blockchain.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -801,9 +801,8 @@ static RPCHelpMan getblockfrompeer()
801801
PeerManager& peerman = EnsurePeerman(node);
802802
CConnman& connman = EnsureConnman(node);
803803

804-
uint256 hash(ParseHashV(request.params[0], "hash"));
805-
806-
const NodeId nodeid = static_cast<NodeId>(request.params[1].get_int64());
804+
const uint256 hash(ParseHashV(request.params[0], "hash"));
805+
const NodeId nodeid{request.params[1].get_int64()};
807806

808807
// Check that the peer with nodeid exists
809808
if (!connman.ForNode(nodeid, [](CNode* node) {return true;})) {
@@ -820,7 +819,7 @@ static RPCHelpMan getblockfrompeer()
820819

821820
if (index->nStatus & BLOCK_HAVE_DATA) {
822821
result.pushKV("warnings", "Block already downloaded");
823-
} else if (!peerman.FetchBlock(nodeid, hash, *index)) {
822+
} else if (!peerman.FetchBlock(nodeid, *index)) {
824823
throw JSONRPCError(RPC_MISC_ERROR, "Failed to fetch block from peer");
825824
}
826825
return result;

0 commit comments

Comments
 (0)