-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Tidy consensus #2156
Closed
Closed
Tidy consensus #2156
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,7 +371,7 @@ class Consensus | |
startRound( | ||
NetClock::time_point const& now, | ||
typename Ledger_t::ID const& prevLedgerID, | ||
Ledger_t const& prevLedger, | ||
Ledger_t prevLedger, | ||
bool proposing); | ||
|
||
/** A peer has proposed a new position, adjust our tracking. | ||
|
@@ -638,7 +638,7 @@ void | |
Consensus<Derived, Traits>::startRound( | ||
NetClock::time_point const& now, | ||
typename Ledger_t::ID const& prevLedgerID, | ||
Ledger_t const& prevLedger, | ||
Ledger_t prevLedger, | ||
bool proposing) | ||
{ | ||
std::lock_guard<std::recursive_mutex> _(*lock_); | ||
|
@@ -653,11 +653,31 @@ Consensus<Derived, Traits>::startRound( | |
{ | ||
prevCloseTime_ = rawCloseTimes_.self; | ||
} | ||
|
||
Mode startMode = proposing ? Mode::proposing : Mode::observing; | ||
|
||
// We were handed the wrong ledger | ||
if (prevLedger.id() != prevLedgerID) | ||
{ | ||
// try to acquire the correct one | ||
if(auto newLedger = impl().acquireLedger(prevLedgerID)) | ||
{ | ||
prevLedger = *newLedger; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ledger_t looks like it's usually a thin wrapper around a shared_ptr (i.e. RCLCxLedger). There's a minor benefit if we move here instead of copy. |
||
} | ||
else // Unable to acquire the correct ledger | ||
{ | ||
startMode = Mode::wrongLedger; | ||
JLOG(j_.info()) | ||
<< "Entering consensus with: " << previousLedger_.id(); | ||
JLOG(j_.info()) << "Correct LCL is: " << prevLedgerID; | ||
} | ||
} | ||
|
||
startRoundInternal( | ||
now, | ||
prevLedgerID, | ||
prevLedger, | ||
proposing ? Mode::proposing : Mode::observing); | ||
startMode); | ||
} | ||
template <class Derived, class Traits> | ||
void | ||
|
@@ -687,19 +707,6 @@ Consensus<Derived, Traits>::startRoundInternal( | |
previousLedger_.closeAgree(), | ||
previousLedger_.seq() + 1); | ||
|
||
if (previousLedger_.id() != prevLedgerID_) | ||
{ | ||
handleWrongLedger(prevLedgerID_); | ||
|
||
// Unable to acquire the correct ledger | ||
if (mode_ == Mode::wrongLedger) | ||
{ | ||
JLOG(j_.info()) | ||
<< "Entering consensus with: " << previousLedger_.id(); | ||
JLOG(j_.info()) << "Correct LCL is: " << prevLedgerID; | ||
} | ||
} | ||
|
||
playbackProposals(); | ||
if (peerProposals_.size() > (prevProposers_ / 2)) | ||
{ | ||
|
@@ -1005,14 +1012,15 @@ Consensus<Derived, Traits>::handleWrongLedger( | |
{ | ||
assert(lgrId != prevLedgerID_ || previousLedger_.id() != lgrId); | ||
|
||
// Stop proposing because we are out of sync | ||
leaveConsensus(); | ||
|
||
// First time switching to this ledger | ||
if (prevLedgerID_ != lgrId) | ||
{ | ||
// first time switching to this ledger | ||
prevLedgerID_ = lgrId; | ||
|
||
// Stop proposing because we are out of sync | ||
leaveConsensus(); | ||
|
||
// Clear out state | ||
if (result_) | ||
{ | ||
result_->disputes.clear(); | ||
|
@@ -1387,7 +1395,18 @@ Consensus<Derived, Traits>::updateOurPositions() | |
// Share our new transaction set if we haven't already received | ||
// it from a peer | ||
if (acquired_.emplace(newID, result_->set).second) | ||
{ | ||
impl().relay(result_->set); | ||
// Update votes for any peers that have also taken this | ||
// transaction set as their position | ||
for (auto const& p : peerProposals_) | ||
{ | ||
if (p.second.position() == newID) | ||
{ | ||
updateDisputes(p.first, result_->set); | ||
} | ||
} | ||
} | ||
|
||
if (mode_ == Mode::proposing) | ||
impl().propose(result_->position); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: The
{}
really aren't necessary.