Skip to content

Commit

Permalink
[FOLD] Fallback to acquiring ledgers:
Browse files Browse the repository at this point in the history
When first starting up, a node may still be working to acquire the
ledgers for validations it has received. When calculating the preferred
ledger in this case, we should still rely on these validations over peer
counts until we acquire our first validated ledger. This should fix the
speed at which a newly started node syncs with the network.
  • Loading branch information
bachase committed Feb 3, 2018
1 parent 5fd14de commit f0bdfe1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ripple/consensus/Validations.h
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,27 @@ class Validations

// No trusted validations to determine branch
if (preferred.seq == Seq{0})
{
// fall back to majority over acquiring ledgers
auto it = std::max_element(
acquiring_.begin(),
acquiring_.end(),
[](auto const& a, auto const& b) {
std::pair<Seq, ID> const& aKey = a.first;
typename hash_set<NodeKey>::size_type const& aSize =
a.second.size();
std::pair<Seq, ID> const& bKey = b.first;
typename hash_set<NodeKey>::size_type const& bSize =
b.second.size();
// order by number of trusted peers validating that ledger
// break ties with ledger ID
return std::tie(aSize, aKey.second) <
std::tie(bSize, bKey.second);
});
if(it != acquiring_.end())
return it->first;
return std::make_pair(preferred.seq, preferred.id);
}

// If we are the parent of the preferred ledger, stick with our
// current ledger since we might be about to generate it
Expand Down
14 changes: 14 additions & 0 deletions src/test/consensus/Validations_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,20 @@ class Validations_test : public beast::unit_test::suite
BEAST_EXPECT(harness.vals().numTrustedForLedger(ID{2}) == 1);
// but ledger based data is not
BEAST_EXPECT(harness.vals().getNodesAfter(genesisLedger, ID{0}) == 0);
// Initial preferred branch falls back to the ledger we are trying to
// acquire
BEAST_EXPECT(
harness.vals().getPreferred(genesisLedger) ==
std::make_pair(Seq{2}, ID{2}));

// After adding another unavailable validation, the preferred ledger
// breaks ties via higher ID
BEAST_EXPECT(
ValStatus::current ==
harness.add(b.validate(ID{3}, Seq{2}, 0s, 0s, true)));
BEAST_EXPECT(
harness.vals().getPreferred(genesisLedger) ==
std::make_pair(Seq{2}, ID{3}));

// Create the ledger
Ledger ledgerAB = h["ab"];
Expand Down

0 comments on commit f0bdfe1

Please sign in to comment.