Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit db277ea

Browse files
committed
Make propagated blocks shared_ptr
Need to store the verified blocks removed from the block queue in a shared_ptr and pass a copy of this shared ptr to EthereumCapability for propagation because propagation happens on another thread.
1 parent 7093a31 commit db277ea

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

libethereum/Client.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ void Client::syncBlockQueue()
389389
unsigned count;
390390
Timer t;
391391

392-
VerifiedBlocks verifiedBlocks;
393-
m_bq.drain(verifiedBlocks, m_syncAmount);
392+
std::shared_ptr<VerifiedBlocks> verifiedBlocks = std::make_shared<VerifiedBlocks>();
393+
m_bq.drain(*verifiedBlocks, m_syncAmount);
394394

395395
// Propagate new blocks to peers before importing them into the chain
396396
auto h = m_host.lock();
@@ -403,7 +403,7 @@ void Client::syncBlockQueue()
403403
h->propagateBlocks(verifiedBlocks);
404404

405405
h256s badBlockHashes;
406-
tie(ir, count) = bc().sync(verifiedBlocks, badBlockHashes, m_stateDB);
406+
tie(ir, count) = bc().sync(*verifiedBlocks, badBlockHashes, m_stateDB);
407407
m_syncBlockQueue = m_bq.doneDrain(badBlockHashes);
408408

409409
double elapsed = t.elapsed();

libethereum/EthereumCapability.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -952,13 +952,13 @@ void EthereumCapability::removeSentTransactions(std::vector<h256> const& _txHash
952952
}
953953
}
954954

955-
void EthereumCapability::propagateBlocks(VerifiedBlocks const& _blocks)
955+
void EthereumCapability::propagateBlocks(std::shared_ptr<VerifiedBlocks const> const& _blocks)
956956
{
957-
if (_blocks.empty())
957+
if (_blocks->empty())
958958
return;
959959

960-
m_host->postWork([this, &_blocks]() {
961-
auto const currentHash = _blocks.cend()->verified.info.hash();
960+
m_host->postWork([this, _blocks]() {
961+
auto const currentHash = _blocks->back().verified.info.hash();
962962
auto const peersWithoutBlock = selectPeers(
963963
[&](EthereumPeer const& _peer) { return !_peer.isBlockKnown(currentHash); });
964964

@@ -967,7 +967,7 @@ void EthereumCapability::propagateBlocks(VerifiedBlocks const& _blocks)
967967

968968
std::vector<NodeID> peersToSend = randomPeers(peersWithoutBlock, peersToSendNumber);
969969
for (NodeID const& peerID : peersToSend)
970-
for (auto const& b : _blocks)
970+
for (auto const& b : *_blocks)
971971
{
972972
RLPStream ts;
973973
m_host->prep(peerID, name(), ts, NewBlockPacket, 2)
@@ -983,7 +983,7 @@ void EthereumCapability::propagateBlocks(VerifiedBlocks const& _blocks)
983983
}
984984
}
985985
if (!peersToSend.empty())
986-
LOG(m_logger) << "Sent " << _blocks.size() << " block(s) to " << peersToSend.size()
986+
LOG(m_logger) << "Sent " << _blocks->size() << " block(s) to " << peersToSend.size()
987987
<< " peers";
988988
});
989989
}

libethereum/EthereumCapability.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class EthereumCapability : public p2p::CapabilityFace
146146
/// Send new blocks to peers. Should be done after we've verified the PoW but before we've
147147
/// imported the blocks into the chain (in order to reduce the uncle rate). Actual sending of
148148
/// blocks is done on the network thread.
149-
void propagateBlocks(VerifiedBlocks const& _blocks);
149+
void propagateBlocks(std::shared_ptr<VerifiedBlocks const> const& _blocks);
150150

151151
private:
152152
static char const* const c_stateNames[static_cast<int>(SyncState::Size)];

0 commit comments

Comments
 (0)