Skip to content

Commit

Permalink
config: update validation with check committee
Browse files Browse the repository at this point in the history
ProtocolConfiguration section must include stand by committee and the
number of validators or committee/validators history.

Close #3247

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Jan 18, 2024
1 parent ed73628 commit 91be7b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/config/protocol_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ func (p *ProtocolConfiguration) Validate() error {
shouldBeDisabled = true
}
}
if p.ValidatorsCount != 0 && len(p.ValidatorsHistory) != 0 {
return errors.New("configuration should either have ValidatorsCount or ValidatorsHistory, not both")
if p.ValidatorsCount != 0 && len(p.ValidatorsHistory) != 0 || p.ValidatorsCount == 0 && len(p.ValidatorsHistory) == 0 {
return errors.New("configuration should either have one of ValidatorsCount or ValidatorsHistory, not both")
}

if len(p.StandbyCommittee) == 0 {
return errors.New("configuration should include StandbyCommittee")
}
if len(p.StandbyCommittee) < int(p.ValidatorsCount) {
return errors.New("validators count can't exceed the size of StandbyCommittee")
Expand Down
19 changes: 19 additions & 0 deletions pkg/config/protocol_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,32 +149,51 @@ func TestProtocolConfigurationValidation_Hardforks(t *testing.T) {
"Aspidochelone": 2,
"Basilisk": 1, // Lower height in higher hard-fork.
},
StandbyCommittee: []string{
"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2",
},
ValidatorsCount: 1,
}
require.Error(t, p.Validate())
p = &ProtocolConfiguration{
Hardforks: map[string]uint32{
"Aspidochelone": 2,
"Basilisk": 2, // Same height is OK.
}, StandbyCommittee: []string{
"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2",
},
ValidatorsCount: 1,
}
require.NoError(t, p.Validate())
p = &ProtocolConfiguration{
Hardforks: map[string]uint32{
"Aspidochelone": 2,
"Basilisk": 3, // Larger height is OK.
},
StandbyCommittee: []string{
"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2",
},
ValidatorsCount: 1,
}
require.NoError(t, p.Validate())
p = &ProtocolConfiguration{
Hardforks: map[string]uint32{
"Aspidochelone": 2,
},
StandbyCommittee: []string{
"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2",
},
ValidatorsCount: 1,
}
require.NoError(t, p.Validate())
p = &ProtocolConfiguration{
Hardforks: map[string]uint32{
"Basilisk": 2,
},
StandbyCommittee: []string{
"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2",
},
ValidatorsCount: 1,
}
require.NoError(t, p.Validate())
}
Expand Down

0 comments on commit 91be7b8

Please sign in to comment.