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

Commit 4adaeaf

Browse files
committed
Miscellaneous style-related changes and fix bug
Fix bug in randomPeers function
1 parent f298be1 commit 4adaeaf

File tree

4 files changed

+26
-25
lines changed

4 files changed

+26
-25
lines changed

libethereum/BlockChain.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ tuple<ImportRoute, bool, unsigned> BlockChain::sync(
434434
}
435435

436436
tuple<ImportRoute, unsigned> BlockChain::sync(
437-
VerifiedBlocks const& _blocks, h256s& _badBlockHashes, OverlayDB const& _stateDB)
437+
VerifiedBlocks const& _blocks, h256s& o_badBlockHashes, OverlayDB const& _stateDB)
438438
{
439439
h256s fresh;
440440
h256s dead;
@@ -463,9 +463,9 @@ tuple<ImportRoute, unsigned> BlockChain::sync(
463463
catch (dev::eth::UnknownParent const&)
464464
{
465465
cwarn << "ODD: Import queue contains block with unknown parent.";// << LogTag::Error << boost::current_exception_diagnostic_information();
466-
// NOTE: don't reimport since the queue should guarantee everything in the right order.
467-
// Can't continue - chain bad.
468-
_badBlockHashes.push_back(block.verified.info.hash());
466+
// NOTE: don't reimport since the queue should guarantee everything in the right order.
467+
// Can't continue - chain bad.
468+
o_badBlockHashes.push_back(block.verified.info.hash());
469469
}
470470
catch (dev::eth::FutureTime const&)
471471
{
@@ -480,12 +480,12 @@ tuple<ImportRoute, unsigned> BlockChain::sync(
480480
}
481481
catch (Exception& ex)
482482
{
483-
// cnote << "Exception while importing block. Someone (Jeff? That you?) seems to be giving us dodgy blocks!";// << LogTag::Error << diagnostic_information(ex);
483+
// cnote << "Exception while importing block. Someone (Jeff? That you?) seems to be giving us dodgy blocks!";// << LogTag::Error << diagnostic_information(ex);
484484
if (m_onBad)
485485
m_onBad(ex);
486486
// NOTE: don't reimport since the queue should guarantee everything in the right order.
487487
// Can't continue - chain bad.
488-
_badBlockHashes.push_back(block.verified.info.hash());
488+
o_badBlockHashes.push_back(block.verified.info.hash());
489489
}
490490
} while (false);
491491
}

libethereum/BlockChain.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class BlockChain
111111
/// @returns a tuple with two members - the first (ImportRoute) contains fresh blocks, dead
112112
/// blocks and imported transactions. The second contains the imported block count.
113113
std::tuple<ImportRoute, unsigned> sync(
114-
VerifiedBlocks const& _blocks, h256s& _badBlockHashes, OverlayDB const& _stateDB);
114+
VerifiedBlocks const& _blocks, h256s& o_badBlockHashes, OverlayDB const& _stateDB);
115115

116116
/// Attempt to import the given block directly into the BlockChain and sync with the state DB.
117117
/// @returns the block hashes of any blocks that came into/went out of the canonical block chain.

libethereum/Client.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ static_assert(BOOST_VERSION >= 106400, "Wrong boost headers version");
4343

4444
namespace
4545
{
46-
constexpr unsigned c_syncMin = 1;
47-
constexpr unsigned c_syncMax = 1000;
48-
constexpr double c_targetDuration = 1;
46+
constexpr unsigned c_syncMinBlockCount = 1;
47+
constexpr unsigned c_syncMaxBlockCount = 1000;
48+
constexpr double c_targetDurationS = 1;
4949

5050
std::string filtersToString(h256Hash const& _fs)
5151
{
@@ -389,7 +389,7 @@ void Client::syncBlockQueue()
389389
unsigned count;
390390
Timer t;
391391

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

395395
// Propagate new blocks to peers before importing them into the chain.
@@ -410,10 +410,10 @@ void Client::syncBlockQueue()
410410
<< (count / elapsed) << " blocks/s) in #" << bc().number();
411411
}
412412

413-
if (elapsed > c_targetDuration * 1.1 && count > c_syncMin)
414-
m_syncAmount = max(c_syncMin, count * 9 / 10);
415-
else if (count == m_syncAmount && elapsed < c_targetDuration * 0.9 && m_syncAmount < c_syncMax)
416-
m_syncAmount = min(c_syncMax, m_syncAmount * 11 / 10 + 1);
413+
if (elapsed > c_targetDurationS * 1.1 && count > c_syncMinBlockCount)
414+
m_syncAmount = max(c_syncMinBlockCount, count * 9 / 10);
415+
else if (count == m_syncAmount && elapsed < c_targetDurationS * 0.9 && m_syncAmount < c_syncMaxBlockCount)
416+
m_syncAmount = min(c_syncMaxBlockCount, m_syncAmount * 11 / 10 + 1);
417417
if (ir.liveBlocks.empty())
418418
return;
419419
onChainChanged(ir);

libethereum/EthereumCapability.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ class EthereumHostData : public EthereumHostDataFace
388388

389389
std::vector<NodeID> randomPeers(std::vector<NodeID> const& _peers, size_t _count)
390390
{
391-
if (_peers.size() >= _count || _peers.empty())
391+
if (_peers.size() <= _count || _peers.empty())
392392
return _peers;
393393

394394
std::vector<NodeID> peers{_peers};
@@ -554,20 +554,20 @@ void EthereumCapability::maintainBlockHashes(h256 const& _currentHash)
554554
LOG(m_logger) << "Sending new block hashes (current is " << _currentHash << ", was "
555555
<< m_latestBlockHashSent << ")";
556556

557-
h256s blocks =
557+
h256s blockHashes =
558558
get<0>(m_chain.treeRoute(m_latestBlockHashSent, _currentHash, false, false, true));
559559

560560
auto const peersWithoutBlock = selectPeers(
561561
[&](EthereumPeer const& _peer) { return !_peer.isBlockKnown(_currentHash); });
562562
for (NodeID const& peerID : peersWithoutBlock)
563563
{
564564
RLPStream ts;
565-
m_host->prep(peerID, name(), ts, NewBlockHashesPacket, blocks.size());
566-
for (auto const& b : blocks)
565+
m_host->prep(peerID, name(), ts, NewBlockHashesPacket, blockHashes.size());
566+
for (auto const& bh : blockHashes)
567567
{
568568
ts.appendList(2);
569-
ts.append(b);
570-
ts.append(m_chain.number(b));
569+
ts.append(bh);
570+
ts.append(m_chain.number(bh));
571571
}
572572

573573
auto itPeer = m_peers.find(peerID);
@@ -578,7 +578,7 @@ void EthereumCapability::maintainBlockHashes(h256 const& _currentHash)
578578
}
579579
}
580580
if (!peersWithoutBlock.empty())
581-
LOG(m_logger) << "Announced " << blocks.size() << " block(s) to "
581+
LOG(m_logger) << "Announced " << blockHashes.size() << " block(s) to "
582582
<< peersWithoutBlock.size() << " peers";
583583
}
584584
m_latestBlockHashSent = _currentHash;
@@ -957,16 +957,17 @@ void EthereumCapability::removeSentTransactions(std::vector<h256> const& _txHash
957957
}
958958
}
959959

960-
void EthereumCapability::propagateNewBlocks(shared_ptr<VerifiedBlocks const> const& _newBlocks)
960+
void EthereumCapability::propagateNewBlocks(std::shared_ptr<VerifiedBlocks const> const& _newBlocks)
961961
{
962962
// Safe to call isSyncing() from a non-network thread since the underlying variable is
963963
// std::atomic
964964
if (_newBlocks->empty() || isSyncing())
965965
return;
966966

967967
m_host->postWork([this, _newBlocks]() {
968-
// Verify that we're not too far behind - we perform this check on the network thread rather
969-
// than before posting the work to simplify the synchronization story
968+
// Verify that we're not too far behind - we perform this check on the network thread to
969+
// simplify the synchronization story (since otherwise we'd need to synchronize access to
970+
// m_latestBlockSent)
970971
auto const latestHash = _newBlocks->back().verified.info.hash();
971972
auto const detailsFrom = m_chain.details(m_latestBlockSent);
972973
auto const detailsTo = m_chain.details(latestHash);

0 commit comments

Comments
 (0)