From 01d29d08c2abe3fcf22b0fb3a70d30bc80fe86a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadej=20Jane=C5=BE?= Date: Fri, 31 Jan 2020 19:05:47 +0100 Subject: [PATCH] go/staking/api: Check if thresholds for all kinds are defined in genesis --- .changelog/2633.feature.md | 1 + go/staking/api/sanity_check.go | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changelog/2633.feature.md diff --git a/.changelog/2633.feature.md b/.changelog/2633.feature.md new file mode 100644 index 00000000000..c7207a00000 --- /dev/null +++ b/.changelog/2633.feature.md @@ -0,0 +1 @@ +go/staking/api: Check if thresholds for all kinds are defined in genesis. diff --git a/go/staking/api/sanity_check.go b/go/staking/api/sanity_check.go index 397f799d42d..664cc0151c7 100644 --- a/go/staking/api/sanity_check.go +++ b/go/staking/api/sanity_check.go @@ -143,9 +143,13 @@ func SanityCheckAccountShares(acct *Account, delegations map[signature.PublicKey // SanityCheck does basic sanity checking on the genesis state. func (g *Genesis) SanityCheck(now epochtime.EpochTime) error { // nolint: gocyclo - for thr, val := range g.Parameters.Thresholds { + for kind := KindEntity; kind <= KindMax; kind++ { + val, ok := g.Parameters.Thresholds[kind] + if !ok { + return fmt.Errorf("staking: sanity check failed: threshold for kind '%s' not defined", kind) + } if !val.IsValid() { - return fmt.Errorf("staking: sanity check failed: threshold '%s' has invalid value", thr.String()) + return fmt.Errorf("staking: sanity check failed: threshold '%s' has invalid value", kind) } }