From 574a22de6cecba62e9d3aabb9738d09e8ac7077a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 18 Aug 2020 22:45:43 +0200 Subject: [PATCH] genesis: Set remainder account balance correctly --- chain/gen/genesis/genesis.go | 16 ++++++++++++---- genesis/types.go | 3 +-- node/node_test.go | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index 80cf6f247..5d0a1cbfb 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -263,6 +263,11 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge } 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 { totalFilAllocated = big.Add(totalFilAllocated, act.Balance) return nil @@ -277,15 +282,18 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, xerrors.Errorf("somehow overallocated filecoin (allocated = %s)", types.FIL(totalFilAllocated)) } - template.RemainderAccount.Balance = remainingFil - remAccKey, err := address.NewIDAddress(90) if err != nil { return nil, nil, err } - if err := createAccount(ctx, bs, cst, state, remAccKey, template.RemainderAccount); err != nil { - return nil, nil, err + err = state.SetActor(remAccKey, &types.Actor{ + Code: builtin.AccountActorCodeID, + Balance: remainingFil, + Head: emptyobject, + }) + if err != nil { + return nil, nil, xerrors.Errorf("set burnt funds account actor: %w", err) } return state, keyIDs, nil diff --git a/genesis/types.go b/genesis/types.go index 468a09067..7d401fd0e 100644 --- a/genesis/types.go +++ b/genesis/types.go @@ -79,6 +79,5 @@ type Template struct { NetworkName string Timestamp uint64 `json:",omitempty"` - VerifregRootKey Actor - RemainderAccount Actor + VerifregRootKey Actor } diff --git a/node/node_test.go b/node/node_test.go index 770ce1f5b..f2df15ffd 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -351,7 +351,7 @@ func mockSbBuilder(t *testing.T, nFull int, storage []test.StorageMiner) ([]test genaccs = append(genaccs, genesis.Actor{ Type: genesis.TAccount, - Balance: big.Mul(big.NewInt(400_000_000_000), types.NewInt(build.FilecoinPrecision)), + Balance: big.Mul(big.NewInt(400_000_000), types.NewInt(build.FilecoinPrecision)), Meta: (&genesis.AccountMeta{Owner: wk.Address}).ActorMeta(), })