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

config: update validation with check committee #3294

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
AnnaShaleva marked this conversation as resolved.
Show resolved Hide resolved
}
if len(p.StandbyCommittee) < int(p.ValidatorsCount) {
return errors.New("validators count can't exceed the size of StandbyCommittee")
Expand Down
33 changes: 33 additions & 0 deletions pkg/config/protocol_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ func TestProtocolConfigurationValidation(t *testing.T) {
ValidatorsHistory: map[uint32]uint32{0: 1, 100: 4},
}
require.NoError(t, p.Validate())
p = &ProtocolConfiguration{
StandbyCommittee: []string{},
CommitteeHistory: map[uint32]uint32{0: 1, 100: 4},
ValidatorsHistory: map[uint32]uint32{0: 1, 100: 4},
}
err := p.Validate()
require.Error(t, err)
require.Contains(t, err.Error(), "configuration should include StandbyCommittee")
p = &ProtocolConfiguration{
StandbyCommittee: []string{"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2"},
}
err = p.Validate()
require.Error(t, err)
require.Contains(t, err.Error(), "configuration should either have one of ValidatorsCount or ValidatorsHistory, not both")
}

func TestProtocolConfigurationValidation_Hardforks(t *testing.T) {
Expand All @@ -149,32 +163,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
Loading