-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ViewChange: add a rotating leader view change
- Loading branch information
1 parent
8de5ba3
commit f067472
Showing
18 changed files
with
159 additions
and
42 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package rotating | ||
|
||
import ( | ||
"go.dedis.ch/fabric/consensus" | ||
"go.dedis.ch/fabric/crypto" | ||
"go.dedis.ch/fabric/mino" | ||
) | ||
|
||
// ViewChange is an implementation of the view change interface that will rotate | ||
// the leader based on the index of the proposal. | ||
// | ||
// - implements viewchange.ViewChange | ||
type ViewChange struct { | ||
addr mino.Address | ||
} | ||
|
||
// NewViewChange returns a new instance of the view change. | ||
func NewViewChange(addr mino.Address) ViewChange { | ||
return ViewChange{addr: addr} | ||
} | ||
|
||
// Wait implements viewchange.ViewChange. | ||
func (vc ViewChange) Wait(prop consensus.Proposal, authority crypto.CollectiveAuthority) (uint32, bool) { | ||
leader := int(prop.GetIndex()) % authority.Len() | ||
|
||
iter := authority.AddressIterator() | ||
iter.Seek(leader) | ||
if iter.HasNext() && iter.GetNext().Equal(vc.addr) { | ||
return uint32(leader), true | ||
} | ||
|
||
return uint32(leader), false | ||
} | ||
|
||
// Verify implements viewchange.ViewChange. | ||
func (vc ViewChange) Verify(prop consensus.Proposal, authority crypto.CollectiveAuthority) uint32 { | ||
leader := int(prop.GetIndex()) % authority.Len() | ||
|
||
return uint32(leader) | ||
} |
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
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
Oops, something went wrong.