Skip to content

Commit

Permalink
go/staking/api: Fix genesis sanity check for nonexisting accounts
Browse files Browse the repository at this point in the history
Detect when a (debonding) delegation is specified for a nonexisting
account and report an appropriate error.
  • Loading branch information
tjanez committed Feb 13, 2020
1 parent aad6d64 commit 3d437c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .changelog/2671.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
go/staking/api: Fix genesis sanity check for nonexisting accounts

Detect when a (debonding) delegation is specified for a nonexisting account
and report an appropriate error.
16 changes: 12 additions & 4 deletions go/staking/api/sanity_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,24 @@ func (g *Genesis) SanityCheck(now epochtime.EpochTime) error { // nolint: gocycl
}

// All shares of all delegations for a given account must add up to account's Escrow.Active.TotalShares.
for acct, delegations := range g.Delegations {
err := SanityCheckDelegations(g.Ledger[acct], delegations)
for acctID, delegations := range g.Delegations {
acct := g.Ledger[acctID]
if acct == nil {
return fmt.Errorf("staking: sanity check failed: delegation specified for a nonexisting account with ID: %v", acctID)
}
err := SanityCheckDelegations(acct, delegations)
if err != nil {
return err
}
}

// All shares of all debonding delegations for a given account must add up to account's Escrow.Debonding.TotalShares.
for acct, delegations := range g.DebondingDelegations {
err := SanityCheckDebondingDelegations(g.Ledger[acct], delegations)
for acctID, delegations := range g.DebondingDelegations {
acct := g.Ledger[acctID]
if acct == nil {
return fmt.Errorf("staking: sanity check failed: debonding delegation specified for a nonexisting account with ID: %v", acctID)
}
err := SanityCheckDebondingDelegations(acct, delegations)
if err != nil {
return err
}
Expand Down

0 comments on commit 3d437c7

Please sign in to comment.