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

Use ledger hash to break ties (RIPD-1468) #2169

Closed
wants to merge 3 commits into from

Conversation

bachase
Copy link
Collaborator

@bachase bachase commented Jul 12, 2017

When two ledgers have the same number of validations, the code will now use the ledger hash itself to break the tie rather than the highest node ID supporting each validation. This simplifies the interface for the generic Validations code.

Additionally, the second changeset makes storing the previous ledger ID/hash a detail of the Validations class, rather than tacking it on STValidation as an unserialized member. This simplifies the use of generic Validations in the consensus simulation framework.

@codecov-io
Copy link

codecov-io commented Jul 12, 2017

Codecov Report

Merging #2169 into develop will increase coverage by 0.02%.
The diff coverage is 54.71%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2169      +/-   ##
===========================================
+ Coverage    69.96%   69.98%   +0.02%     
===========================================
  Files          689      689              
  Lines        50734    50704      -30     
===========================================
- Hits         35495    35487       -8     
+ Misses       15239    15217      -22
Impacted Files Coverage Δ
src/ripple/protocol/STValidation.h 42.85% <ø> (+3.72%) ⬆️
src/ripple/app/consensus/RCLValidations.h 77.27% <ø> (+12.75%) ⬆️
src/ripple/app/consensus/RCLConsensus.cpp 64.6% <0%> (ø) ⬆️
src/ripple/app/misc/NetworkOPs.cpp 61.61% <0%> (+0.75%) ⬆️
src/ripple/consensus/Validations.h 98.37% <100%> (+0.6%) ⬆️
src/ripple/basics/DecayingSample.h 77.77% <0%> (-8.34%) ⬇️
src/ripple/app/ledger/PendingSaves.h 93.54% <0%> (-6.46%) ⬇️
src/ripple/protocol/impl/STVar.cpp 85.71% <0%> (-2.6%) ⬇️
src/ripple/core/impl/JobQueue.cpp 86.85% <0%> (-0.47%) ⬇️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cca574c...f8774f8. Read the comment docs.

if ((it.second.count > netLgrCount) ||
((it.second.count== netLgrCount) && (it.first == ledgerID)))
if ((it.second > netLgrCount) ||
((it.second== netLgrCount) && (it.first == ledgerID)))
Copy link
Contributor

Choose a reason for hiding this comment

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

it.second== netLgrCount --> it.second == netLgrCount

{
// Should the the only trusted for ID{20}
Copy link
Contributor

Choose a reason for hiding this comment

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

the the

//! of the ledger it replaces
struct ValidationAndPrevID
{
ValidationAndPrevID(Validation const& v) : val{v}, prevLedgerID{0}
Copy link
Contributor

Choose a reason for hiding this comment

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

This may be out of scope for this PR too, but currentTrustedDistribution and getNodesAfter can still return incorrect info if a validator sends a validation for the first time (in ~5 minutes) and prevLedgerID is zero.
#2084 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree that is still worth addressing, but would prefer to do as an independent change.

@@ -1348,10 +1351,9 @@ bool NetworkOPsImp::checkLastClosedLedger (
try
{
auto& vc = ledgers[peerLedger];
auto const nodeId = calcNodeID(peer->getNodePublic ());
Copy link
Contributor

Choose a reason for hiding this comment

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

Does removing this line mean we no longer need the try/catch?

Copy link
Collaborator Author

@bachase bachase Jul 14, 2017

Choose a reason for hiding this comment

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

Yes, I believe you are correct. Although, I'm not clear what was throwing before. The comment below suggests a peer may have disconnected, but peer is a shared_ptr here.

@@ -1223,7 +1223,9 @@ class ValidationCount
{
public:
int trustedValidations, nodesUsing;
NodeID highNodeUsing, highValidation;
// Ledger hashes to break ties
uint256 highUsingHash, highTrustedValHash;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this class is only used in checkLastClosedLedger in a hash_map<uint256, ValidationCount>, I'd consider removing both highUsingHash and highTrustedValHash (we already have the ledger hash as the key). Then you could handle tiebreaking outside of the comparison operator.

Copy link
Contributor

@wilsonianb wilsonianb left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@@ -1378,17 +1349,20 @@ bool NetworkOPsImp::checkLastClosedLedger (
// Temporary logging to make sure tiebreaking isn't broken
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this temporary logging is still useful, especially with the debug log above

@bachase
Copy link
Collaborator Author

bachase commented Jul 21, 2017

Rebased on 0.80.0-b3

bachase added 3 commits August 7, 2017 10:51
When two ledgers have the same number of validations, the code will now use the
ledger hash itself to break the tie rather than the highest node ID supporting
each validation.
@bachase
Copy link
Collaborator Author

bachase commented Aug 7, 2017

Rebased on 0.80.0-b4

Copy link
Collaborator

@JoelKatz JoelKatz left a comment

Choose a reason for hiding this comment

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

:neckbeard: 👍

@nbougalis
Copy link
Contributor

Merged as 60dd194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants