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

Resolve long time consensus stuck by network and simple refactorings #915

Merged

Conversation

Charleslee522
Copy link
Member

@Charleslee522 Charleslee522 commented Jan 21, 2019

Github Issue

fixes #900

Solution

  1. When receiving the old ballot, a node broadcasts expired ballot.
  2. If the ballot what a node has is old, a node removes it from the voting results and broadcasts an expired ballot
  3. Because of expired ballot, the consensus stuck is resolved and the next round of voting begins.

ps. As usual, please check each commits

@spikeekips Thanks for your awesome design idea :)

@Charleslee522 Charleslee522 added enhancement New feature or request Refactoring labels Jan 21, 2019
@Charleslee522 Charleslee522 self-assigned this Jan 21, 2019
@Charleslee522 Charleslee522 force-pushed the consensus-stuck-missing-ballot branch 2 times, most recently from f23ce85 to 1a88da6 Compare January 22, 2019 01:00
Round: blt.VotingBasis().Round,
BallotState: blt.State(),
},
false,
Copy link
Contributor

Choose a reason for hiding this comment

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

In this part, nr.SetSendRecord should be true? The expired Ballot is sent, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

@spikeekips Oh, good question 👍
This false setting is for initializing SendRecord.
Because if SendRecord is true, then this ballot will be discarded in nr.BroadcastBallot().
If it is confusing, I can make this to another method like InitializeSendRecord.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Charleslee522 Renaming will be good :)

@Charleslee522 Charleslee522 force-pushed the consensus-stuck-missing-ballot branch 2 times, most recently from 7923616 to 5620c9a Compare January 29, 2019 02:19
@Charleslee522
Copy link
Member Author

@anarcher @kfangw @Geod24 Do you need any help? More description or something? :)

Copy link
Contributor

@Geod24 Geod24 left a comment

Choose a reason for hiding this comment

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

Just a few comments, but looks nice

config := is.Conf
opc, _ := ballot.NewCollectTxFeeFromBallot(*newExpiredBallot, config.CommonAccountAddress)
opi, _ := ballot.NewInflationFromBallot(*newExpiredBallot, config.CommonAccountAddress, config.InitialBalance)
ptx, _ := ballot.NewProposerTransactionFromBallot(*newExpiredBallot, opc, opi)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not avoid error checking here

@@ -85,6 +85,25 @@ func (is *ISAAC) SelectProposer(blockHeight uint64, round uint64) string {
return is.proposerSelector.Select(blockHeight, round)
}

func (is *ISAAC) GenerateExpiredBallot(basis voting.Basis, state ballot.State) ballot.Ballot {
Copy link
Contributor

Choose a reason for hiding this comment

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

Documentation?


newExpiredBallot.SetProposerTransaction(ptx)
newExpiredBallot.SignByProposer(is.Node.Keypair(), config.NetworkID)
newExpiredBallot.Sign(is.Node.Keypair(), config.NetworkID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we always need to call Sign after SignByProposer, SignByProposer should probably do it itself.
That will also avoid the double hashing / signature which is expensive.

Copy link
Member Author

Choose a reason for hiding this comment

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

hm.. already SignByProposer is called in Sign.
I need more time to think about handing and signing ExpiredBallot.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Geod24 How about handling it in the next pr?
I think it is not related with this commit :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -2,7 +2,6 @@ package ballot

import (
"encoding/json"
"time"
Copy link
Contributor

Choose a reason for hiding this comment

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

I love this commit

@@ -225,14 +225,14 @@ func (is *ISAAC) Vote(b ballot.Ballot) (isNew bool, err error) {
return
}

func (is *ISAAC) CanGetVotingResult(b ballot.Ballot) (rv RoundVoteResult, vh voting.Hole, finished bool) {
func (is *ISAAC) CanGetVotingResult(blt ballot.Ballot) (rv RoundVoteResult, vh voting.Hole, finished bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 for using at least 3 char identifiers. Makes the code much more readable IMO.

@@ -24,11 +24,11 @@ func NewBallotSendRecord(nodeAlias string) *BallotSendRecord {
return p
}

func (r *BallotSendRecord) SetSent(state ISAACState) {
func (r *BallotSendRecord) SetSent(state ISAACState, sent bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good time to add documentation?

@@ -225,6 +225,52 @@ func (is *ISAAC) Vote(b ballot.Ballot) (isNew bool, err error) {
return
}

// RemoveOldBallots checkes that `blt` has valid confirmed and proposed time.
Copy link
Contributor

Choose a reason for hiding this comment

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

Whyyyyyy do all golang documentation start with the function name ? Presumable having the doc attached to the symbol should be enough ? Especially given the extra long names of Go functions...

Anyway, you don't have to change it, since it's consistent with the rest. However, "checkes" => "checks"

}
var roundVote *RoundVote
var err error
roundVote, err = runningRound.RoundVote(blt.Proposer())
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not := ?

}
}
case ballot.StateACCEPT:
for nodeAddr, blt := range roundVote.ACCEPT {
Copy link
Contributor

Choose a reason for hiding this comment

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

No way to pull this code together ? They have the same logic, just a different variables (roundVote.{SIGN,ACCEPT})

@Charleslee522 Charleslee522 force-pushed the consensus-stuck-missing-ballot branch from 5620c9a to 2d15378 Compare January 31, 2019 02:24
@@ -24,6 +24,8 @@ func NewBallotSendRecord(nodeAlias string) *BallotSendRecord {
return p
}

// SetSent sets that the ballot of this ISAACState has already been sent.
// This is to prevent one node from retransmitting another result.
Copy link
Contributor

Choose a reason for hiding this comment

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

Big big 👍 for documenting what the function is for. It's much more important than what the function do (which one can understand from the code).

Copy link
Contributor

@Geod24 Geod24 left a comment

Choose a reason for hiding this comment

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

LGTM

@Charleslee522
Copy link
Member Author

@spikeekips can i merge it? :)

Copy link
Contributor

@spikeekips spikeekips left a comment

Choose a reason for hiding this comment

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

@spikeekips can i merge it? :)

Sorry Too late :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to handle the stopped consensus for a long time
3 participants