Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make quorum unreachable if validator list expires (RIPD-1539) #2240

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ripple/app/misc/ValidatorList.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ ValidatorList::onConsensusStart (
list.second.expiration <=
timeKeeper_.now().time_since_epoch().count())
removePublisherList (list.first);
else if (! list.second.available)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are all published lists required to have an expiration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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 @@ -235,7 +235,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 @@ -395,6 +395,9 @@ ValidatorList::removePublisherList (PublicKey const& publisherKey)
--iVal->second;
}

iList->second.list.clear();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this call to clear, would that mean if a published list with keys K1,K2 expired, then was republished with key K1, the keyListsings_ count for K2 would have been decremented twice? If so, is it worth adding a unit test to cover that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good observation. This added test fails without the clear
3bb20f9

iList->second.available = false;

return true;
}

Expand Down
30 changes: 27 additions & 3 deletions src/test/app/ValidatorList_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,9 @@ class ValidatorList_test : public beast::unit_test::suite
BEAST_EXPECT(trustedKeys->load (
emptyLocalKey, emptyCfgKeys, cfgKeys));

std::vector<PublicKey> list ({randomNode()});
hash_set<PublicKey> activeValidators ({ list[0] });
std::vector<PublicKey> list ({randomNode(), randomNode()});
hash_set<PublicKey> activeValidators ({ list[0], list[1] });

// do not apply expired list
auto const version = 1;
auto const sequence = 1;
NetClock::time_point const expiration =
Expand All @@ -741,10 +740,35 @@ class ValidatorList_test : public beast::unit_test::suite

trustedKeys->onConsensusStart (activeValidators);
BEAST_EXPECT(trustedKeys->trusted (list[0]));
BEAST_EXPECT(trustedKeys->trusted (list[1]));
BEAST_EXPECT(trustedKeys->quorum () == 2);

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

// (Re)trust validators from new valid list
std::vector<PublicKey> list2 ({list[0], randomNode()});
activeValidators.insert(list2[1]);
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);
BEAST_EXPECT(trustedKeys->trusted (list[0]));
BEAST_EXPECT(trustedKeys->trusted (list2[1]));
BEAST_EXPECT(! trustedKeys->trusted (list[1]));
BEAST_EXPECT(trustedKeys->quorum () == 2);
}
{
// Test 1-9 configured validators
Expand Down