forked from TrueCloudLab/neoneo-go
config: do not allow zero numbers for validators/committee history
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
8149d33fef
commit
0c049f620f
2 changed files with 28 additions and 0 deletions
|
@ -130,6 +130,9 @@ func (p *ProtocolConfiguration) Validate() error {
|
|||
}
|
||||
var arr = make([]heightNumber, 0, len(p.CommitteeHistory))
|
||||
for h, n := range p.CommitteeHistory {
|
||||
if n == 0 {
|
||||
return fmt.Errorf("invalid CommitteeHistory: bad members count (%d) for height %d", n, h)
|
||||
}
|
||||
if int(n) > len(p.StandbyCommittee) {
|
||||
return fmt.Errorf("too small StandbyCommittee for required number of committee members at %d", h)
|
||||
}
|
||||
|
@ -148,6 +151,9 @@ func (p *ProtocolConfiguration) Validate() error {
|
|||
}
|
||||
arr = arr[:0]
|
||||
for h, n := range p.ValidatorsHistory {
|
||||
if n == 0 {
|
||||
return fmt.Errorf("invalid ValidatorsHistory: bad members count (%d) for height %d", n, h)
|
||||
}
|
||||
if int(n) > len(p.StandbyCommittee) {
|
||||
return fmt.Errorf("too small StandbyCommittee for required number of validators at %d", h)
|
||||
}
|
||||
|
|
|
@ -110,6 +110,28 @@ func TestProtocolConfigurationValidation(t *testing.T) {
|
|||
ValidatorsHistory: map[uint32]uint32{0: 4, 100: 4},
|
||||
}
|
||||
require.Error(t, p.Validate())
|
||||
p = &ProtocolConfiguration{
|
||||
StandbyCommittee: []string{
|
||||
"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2",
|
||||
"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e",
|
||||
"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699",
|
||||
"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62",
|
||||
},
|
||||
CommitteeHistory: map[uint32]uint32{0: 0, 100: 4},
|
||||
ValidatorsHistory: map[uint32]uint32{0: 1, 100: 4},
|
||||
}
|
||||
require.Error(t, p.Validate())
|
||||
p = &ProtocolConfiguration{
|
||||
StandbyCommittee: []string{
|
||||
"02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2",
|
||||
"02103a7f7dd016558597f7960d27c516a4394fd968b9e65155eb4b013e4040406e",
|
||||
"03d90c07df63e690ce77912e10ab51acc944b66860237b608c4f8f8309e71ee699",
|
||||
"02a7bc55fe8684e0119768d104ba30795bdcc86619e864add26156723ed185cd62",
|
||||
},
|
||||
CommitteeHistory: map[uint32]uint32{0: 1, 100: 4},
|
||||
ValidatorsHistory: map[uint32]uint32{0: 0, 100: 4},
|
||||
}
|
||||
require.Error(t, p.Validate())
|
||||
p = &ProtocolConfiguration{
|
||||
Hardforks: map[string]uint32{
|
||||
"Unknown": 123, // Unknown hard-fork.
|
||||
|
|
Loading…
Reference in a new issue