fix(genesis): set initial balances to 0

This commit is contained in:
Steven Allen 2021-06-18 14:20:48 -07:00
parent b30b5dd629
commit eb0a15faf0
8 changed files with 29 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package genesis
import ( import (
"context" "context"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin/system" "github.com/filecoin-project/lotus/chain/actors/builtin/system"
@ -32,8 +33,9 @@ func SetupSystemActor(ctx context.Context, bs bstore.Blockstore, av actors.Versi
} }
act := &types.Actor{ act := &types.Actor{
Code: actcid, Code: actcid,
Head: statecid, Head: statecid,
Balance: big.Zero(),
} }
return act, nil return act, nil

View File

@ -11,6 +11,7 @@ import (
"github.com/filecoin-project/go-address" "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/specs-actors/actors/util/adt" "github.com/filecoin-project/specs-actors/actors/util/adt"
@ -181,8 +182,9 @@ func SetupInitActor(ctx context.Context, bs bstore.Blockstore, netname string, i
} }
act := &types.Actor{ act := &types.Actor{
Code: actcid, Code: actcid,
Head: statecid, Head: statecid,
Balance: big.Zero(),
} }
return counter, act, keyToId, nil return counter, act, keyToId, nil

View File

@ -3,6 +3,7 @@ package genesis
import ( import (
"context" "context"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin/cron" "github.com/filecoin-project/lotus/chain/actors/builtin/cron"
@ -31,8 +32,9 @@ func SetupCronActor(ctx context.Context, bs bstore.Blockstore, av actors.Version
} }
act := &types.Actor{ act := &types.Actor{
Code: actcid, Code: actcid,
Head: statecid, Head: statecid,
Balance: big.Zero(),
} }
return act, nil return act, nil

View File

@ -3,6 +3,7 @@ package genesis
import ( import (
"context" "context"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/chain/actors/builtin/power" "github.com/filecoin-project/lotus/chain/actors/builtin/power"
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
@ -33,8 +34,9 @@ func SetupStoragePowerActor(ctx context.Context, bs bstore.Blockstore, av actors
} }
act := &types.Actor{ act := &types.Actor{
Code: actcid, Code: actcid,
Head: statecid, Head: statecid,
Balance: big.Zero(),
} }
return act, nil return act, nil

View File

@ -3,6 +3,7 @@ package genesis
import ( import (
"context" "context"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
"github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin/market" "github.com/filecoin-project/lotus/chain/actors/builtin/market"
@ -31,8 +32,9 @@ func SetupStorageMarketActor(ctx context.Context, bs bstore.Blockstore, av actor
} }
act := &types.Actor{ act := &types.Actor{
Code: actcid, Code: actcid,
Head: statecid, Head: statecid,
Balance: big.Zero(),
} }
return act, nil return act, nil

View File

@ -3,6 +3,7 @@ package genesis
import ( import (
"context" "context"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/chain/actors/builtin/verifreg" "github.com/filecoin-project/lotus/chain/actors/builtin/verifreg"
"github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors"
@ -46,8 +47,9 @@ func SetupVerifiedRegistryActor(ctx context.Context, bs bstore.Blockstore, av ac
} }
act := &types.Actor{ act := &types.Actor{
Code: actcid, Code: actcid,
Head: statecid, Head: statecid,
Balance: big.Zero(),
} }
return act, nil return act, nil

View File

@ -313,11 +313,10 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
totalFilAllocated := big.Zero() totalFilAllocated := big.Zero()
// flush as ForEach works on the HAMT
if _, err := state.Flush(ctx); err != nil {
return nil, nil, err
}
err = state.ForEach(func(addr address.Address, act *types.Actor) error { err = state.ForEach(func(addr address.Address, act *types.Actor) error {
if act.Balance.Nil() {
panic(fmt.Sprintf("actor %s (%s) has nil balance", addr, builtin.ActorNameByCode(act.Code)))
}
totalFilAllocated = big.Add(totalFilAllocated, act.Balance) totalFilAllocated = big.Add(totalFilAllocated, act.Balance)
return nil return nil
}) })

View File

@ -515,7 +515,8 @@ func (st *StateTree) ForEach(f func(address.Address, *types.Actor) error) error
if op.Delete { if op.Delete {
continue continue
} }
if err := f(addr, &op.Act); err != nil { act := op.Act // copy
if err := f(addr, &act); err != nil {
return err return err
} }
} }