Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/staking/api: Fix genesis sanity check for nonexisting accounts #2671

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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