Skip to content

Commit

Permalink
Make quorum unreachable if validator list expires (RIPD-1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonianb authored and bachase committed Nov 27, 2017
1 parent 8f347a5 commit 02059a2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/ripple/app/misc/ValidatorList.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ ValidatorList::onConsensusStart (
list.second.expiration <=
timeKeeper_.now().time_since_epoch().count())
removePublisherList (list.first);
else if (! list.second.available)

if (! list.second.available)
allListsAvailable = false;
}

Expand Down
5 changes: 4 additions & 1 deletion src/ripple/app/misc/impl/ValidatorList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ ValidatorList::applyList (
(iOld != oldList.end () && *iOld < *iNew))
{
// Decrement list count for removed keys
if (keyListings_[*iOld] == 1)
if (keyListings_[*iOld] <= 1)
keyListings_.erase (*iOld);
else
--keyListings_[*iOld];
Expand Down Expand Up @@ -421,6 +421,9 @@ ValidatorList::removePublisherList (PublicKey const& publisherKey)
--iVal->second;
}

iList->second.list.clear();
iList->second.available = false;

return true;
}

Expand Down
40 changes: 35 additions & 5 deletions src/test/app/ValidatorList_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ class ValidatorList_test : public beast::unit_test::suite
BEAST_EXPECT(trustedKeys->load (
emptyLocalKey, emptyCfgKeys, cfgKeys));

std::vector<Validator> list ({randomValidator()});
hash_set<PublicKey> activeValidators ({ list[0].masterPublic });
std::vector<Validator> list ({randomValidator(), randomValidator()});
hash_set<PublicKey> activeValidators ({ list[0].masterPublic, list[1].masterPublic });

// do not apply expired list
auto const version = 1;
Expand All @@ -774,13 +774,43 @@ class ValidatorList_test : public beast::unit_test::suite
manifest, blob, sig, version));

trustedKeys->onConsensusStart (activeValidators);
BEAST_EXPECT(trustedKeys->trusted (list[0].masterPublic));
BEAST_EXPECT(trustedKeys->trusted (list[0].signingPublic));
for(Validator const & val : list)
{
BEAST_EXPECT(trustedKeys->trusted (val.masterPublic));
BEAST_EXPECT(trustedKeys->trusted (val.signingPublic));
}
BEAST_EXPECT(trustedKeys->quorum () == 2);

env.timeKeeper().set(expiration);
trustedKeys->onConsensusStart (activeValidators);
BEAST_EXPECT(! trustedKeys->trusted (list[0].masterPublic));
BEAST_EXPECT(! trustedKeys->trusted (list[0].signingPublic));
BEAST_EXPECT(! trustedKeys->trusted (list[1].masterPublic));
BEAST_EXPECT(trustedKeys->quorum () ==
std::numeric_limits<std::size_t>::max());

// (Re)trust validators from new valid list
std::vector<Validator> list2 ({list[0], randomValidator()});
activeValidators.insert(list2[1].masterPublic);
auto const sequence2 = 2;
NetClock::time_point const expiration2 =
env.timeKeeper().now() + 60s;
auto const blob2 = makeList (
list2, sequence2, expiration2.time_since_epoch().count());
auto const sig2 = signList (blob2, pubSigningKeys);

BEAST_EXPECT(ListDisposition::accepted ==
trustedKeys->applyList (
manifest, blob2, sig2, version));

trustedKeys->onConsensusStart (activeValidators);
for(Validator const & val : list2)
{
BEAST_EXPECT(trustedKeys->trusted (val.masterPublic));
BEAST_EXPECT(trustedKeys->trusted (val.signingPublic));
}
BEAST_EXPECT(! trustedKeys->trusted (list[1].masterPublic));
BEAST_EXPECT(! trustedKeys->trusted (list[1].signingPublic));
BEAST_EXPECT(trustedKeys->quorum () == 2);
}
{
// Test 1-9 configured validators
Expand Down

0 comments on commit 02059a2

Please sign in to comment.