Skip to content

Commit

Permalink
config: do not allow negative validators count
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
  • Loading branch information
AnnaShaleva committed Apr 13, 2023
1 parent 0c049f6 commit a74454a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/node-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ protocol-related settings described in the table below.
| StateRootInHeader | `bool` | `false` | Enables storing state root in block header. | Experimental protocol extension! |
| StateSyncInterval | `int` | `40000` | The number of blocks between state heights available for MPT state data synchronization. | `P2PStateExchangeExtensions` should be enabled to use this setting. |
| TimePerBlock | `Duration` | `15s` | Minimal (and targeted for) time interval between blocks. Must be an integer number of milliseconds. |
| ValidatorsCount | `int` | `0` | Number of validators set for the whole network lifetime, can't be set if `ValidatorsHistory` setting is used. |
| ValidatorsCount | `uint32` | `0` | Number of validators set for the whole network lifetime, can't be set if `ValidatorsHistory` setting is used. |
| ValidatorsHistory | map[uint32]uint32 | none | Number of consensus nodes to use after given height (see `CommitteeHistory` also). Heights where the change occurs must be divisible by the number of committee members at that height. Can't be used with `ValidatorsCount` not equal to zero. |
| VerifyBlocks | `bool` | `false` | This setting is deprecated and no longer works, please use `SkipBlockVerification` in the `ApplicationConfiguration`, it will be removed in future node versions. |
| VerifyTransactions | `bool` | `false` | Denotes whether to verify transactions in the received blocks. |
6 changes: 3 additions & 3 deletions pkg/config/protocol_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type (
// TimePerBlock is the time interval between blocks that consensus nodes work with.
// It must be an integer number of milliseconds.
TimePerBlock time.Duration `yaml:"TimePerBlock"`
ValidatorsCount int `yaml:"ValidatorsCount"`
ValidatorsCount uint32 `yaml:"ValidatorsCount"`
// Validators stores history of changes to consensus node number (height: number).
ValidatorsHistory map[uint32]uint32 `yaml:"ValidatorsHistory"`
// Whether to verify received blocks.
Expand Down Expand Up @@ -125,7 +125,7 @@ func (p *ProtocolConfiguration) Validate() error {
if p.ValidatorsCount != 0 && len(p.ValidatorsHistory) != 0 {
return errors.New("configuration should either have ValidatorsCount or ValidatorsHistory, not both")
}
if len(p.StandbyCommittee) < p.ValidatorsCount {
if len(p.StandbyCommittee) < int(p.ValidatorsCount) {
return errors.New("validators count can't exceed the size of StandbyCommittee")
}
var arr = make([]heightNumber, 0, len(p.CommitteeHistory))
Expand Down Expand Up @@ -212,7 +212,7 @@ func getBestFromMap(dict map[uint32]uint32, height uint32) uint32 {
// It implies valid configuration file.
func (p *ProtocolConfiguration) GetNumOfCNs(height uint32) int {
if len(p.ValidatorsHistory) == 0 {
return p.ValidatorsCount
return int(p.ValidatorsCount)
}
return int(getBestFromMap(p.ValidatorsHistory, height))
}
Expand Down

0 comments on commit a74454a

Please sign in to comment.