mirror of https://github.com/poanetwork/quorum.git
Added roundchange tests and updated docs and comments
This commit is contained in:
parent
1d80555093
commit
75663f6a73
|
@ -338,6 +338,7 @@ func (sb *backend) IsQIBFTConsensus() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// StartQBFTConsensus stops existing legacy ibft consensus and starts the new qibft consensus
|
||||
func (sb *backend) StartQIBFTConsensus() error {
|
||||
sb.logger.Trace("Starting QIBFT Consensus")
|
||||
if err := sb.Stop(); err != nil {
|
||||
|
|
|
@ -90,3 +90,67 @@ func TestRoundChangeSet(t *testing.T) {
|
|||
t.Errorf("the change messages mismatch: have %v, want nil", rc.roundChanges[view.Round.Uint64()])
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMinRoundChange(t *testing.T) {
|
||||
rcs := getRoundChangeSetForPositveTests()
|
||||
minRC := rcs.getMinRoundChange(big.NewInt(1))
|
||||
if minRC.Uint64() != 2 {
|
||||
t.Errorf("min Round Change mismatch: have %v, want 2", minRC.Uint64())
|
||||
}
|
||||
}
|
||||
|
||||
func TestClearLowerThan(t *testing.T) {
|
||||
rcs := getRoundChangeSetForPositveTests()
|
||||
rcs.ClearLowerThan(big.NewInt(3))
|
||||
if len(rcs.roundChanges) > 0 {
|
||||
t.Errorf("Number of Round Change messages mismatch: have %v, want 0", len(rcs.roundChanges))
|
||||
}
|
||||
|
||||
rcs = getRoundChangeSetForPositveTests()
|
||||
rcs.ClearLowerThan(big.NewInt(2))
|
||||
rcMsgs := rcs.roundChanges[2]
|
||||
if len(rcMsgs.messages) != 3 {
|
||||
t.Errorf("Number of Round Change messages mismatch: have %v, want 3", len(rcs.roundChanges))
|
||||
}
|
||||
}
|
||||
|
||||
func getRoundChangeSetForPositveTests() *roundChangeSet {
|
||||
vset := validator.NewSet(generateValidators(4), istanbul.RoundRobin)
|
||||
|
||||
view := &View{
|
||||
Sequence: big.NewInt(1),
|
||||
Round: big.NewInt(2),
|
||||
}
|
||||
proposal := makeBlock(1)
|
||||
|
||||
rcs := newRoundChangeSet(vset)
|
||||
|
||||
encodedRCMsg1, _ := Encode(&RoundChangeMessage{
|
||||
View: view,
|
||||
PreparedRound: big.NewInt(1),
|
||||
PreparedBlock: proposal,
|
||||
PreparedMessages: nil,
|
||||
})
|
||||
|
||||
msg1 := &message{
|
||||
Code: msgRoundChange,
|
||||
Msg: encodedRCMsg1,
|
||||
Address: vset.GetByIndex(0).Address(),
|
||||
}
|
||||
msg2 := &message{
|
||||
Code: msgRoundChange,
|
||||
Msg: encodedRCMsg1,
|
||||
Address: vset.GetByIndex(1).Address(),
|
||||
}
|
||||
msg3 := &message{
|
||||
Code: msgRoundChange,
|
||||
Msg: encodedRCMsg1,
|
||||
Address: vset.GetByIndex(2).Address(),
|
||||
}
|
||||
|
||||
rcs.Add(view.Round, msg1, big.NewInt(1), proposal, nil)
|
||||
rcs.Add(view.Round, msg2, big.NewInt(1), proposal, nil)
|
||||
rcs.Add(view.Round, msg3, big.NewInt(1), proposal, nil)
|
||||
|
||||
return rcs
|
||||
}
|
||||
|
|
|
@ -181,6 +181,7 @@ func Encode(val interface{}) ([]byte, error) {
|
|||
return rlp.EncodeToBytes(val)
|
||||
}
|
||||
|
||||
// Request is used to construct a Preprepare message
|
||||
type Request struct {
|
||||
Proposal istanbul.Proposal
|
||||
RCMessages *messageSet
|
||||
|
@ -235,6 +236,7 @@ func (v *View) Cmp(y *View) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
// Preprepare represents the message sent, when msgPreprepare is broadcasted
|
||||
type Preprepare struct {
|
||||
View *View
|
||||
Proposal istanbul.Proposal
|
||||
|
@ -264,6 +266,7 @@ func (b *Preprepare) DecodeRLP(s *rlp.Stream) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Subject represents the message sent when msgPrepare and msgCommit is broadcasted
|
||||
type Subject struct {
|
||||
View *View
|
||||
Digest istanbul.Proposal
|
||||
|
@ -292,6 +295,7 @@ func (b *Subject) String() string {
|
|||
return fmt.Sprintf("{View: %v, Proposal: %v}", b.View, b.Digest.String())
|
||||
}
|
||||
|
||||
// RoundChangeMessage represents the message sent when msgRoundChange is broadcasted
|
||||
type RoundChangeMessage struct {
|
||||
View *View
|
||||
PreparedRound *big.Int
|
||||
|
|
|
@ -66,4 +66,10 @@ nodes. This was introduced to enable existing network the ability to upgrade at
|
|||
it is incompatible with the existing formula. For new networks, it is recommended to set this value to `0` to use the
|
||||
updated formula immediately.
|
||||
|
||||
To update this value, the same process can be followed as other hard-forks.
|
||||
|
||||
### qibftBlock
|
||||
|
||||
The `qibftBlock` sets the block number from which to use `qibft` consensus. This was introduced to enable existing ibft networks the ability to start using qibft consensus at a point in the future. For new networks, it is recommended to set this value to `0` to use the updated formula immediately.
|
||||
|
||||
To update this value, the same process can be followed as other hard-forks.
|
Loading…
Reference in New Issue