mirror of https://github.com/poanetwork/gecko.git
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
|
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
||
|
// See the file LICENSE for licensing terms.
|
||
|
|
||
|
package snowball
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/prometheus/client_golang/prometheus"
|
||
|
)
|
||
|
|
||
|
// Parameters required for snowball consensus
|
||
|
type Parameters struct {
|
||
|
Namespace string
|
||
|
Metrics prometheus.Registerer
|
||
|
K, Alpha, BetaVirtuous, BetaRogue int
|
||
|
}
|
||
|
|
||
|
// Valid returns nil if the parameters describe a valid initialization.
|
||
|
func (p Parameters) Valid() error {
|
||
|
switch {
|
||
|
case p.Alpha <= p.K/2:
|
||
|
return fmt.Errorf("K = %d, Alpha = %d: Fails the condition that: K/2 < Alpha", p.K, p.Alpha)
|
||
|
case p.K < p.Alpha:
|
||
|
return fmt.Errorf("K = %d, Alpha = %d: Fails the condition that: Alpha <= K", p.K, p.Alpha)
|
||
|
case p.BetaVirtuous <= 0:
|
||
|
return fmt.Errorf("BetaVirtuous = %d: Fails the condition that: 0 < BetaVirtuous", p.BetaVirtuous)
|
||
|
case p.BetaRogue < p.BetaVirtuous:
|
||
|
return fmt.Errorf("BetaVirtuous = %d, BetaRogue = %d: Fails the condition that: BetaVirtuous <= BetaRogue", p.BetaVirtuous, p.BetaRogue)
|
||
|
default:
|
||
|
return nil
|
||
|
}
|
||
|
}
|