From fe473e111cdeea3fd193006fe1caac3299ce0301 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Fri, 12 Mar 2021 16:58:43 -0500 Subject: [PATCH] Fix creation of remainder account when it's not a multisig --- chain/gen/genesis/f01_init.go | 19 ++++++++++++++++--- chain/gen/genesis/genesis.go | 14 ++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/chain/gen/genesis/f01_init.go b/chain/gen/genesis/f01_init.go index 9fc6cfb9e5c..718eb44807c 100644 --- a/chain/gen/genesis/f01_init.go +++ b/chain/gen/genesis/f01_init.go @@ -133,9 +133,22 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi } } - err := setupMsig(remainder.Meta) - if err != nil { - return 0, nil, nil, xerrors.Errorf("setting up remainder msig: %w", err) + if remainder.Type == genesis.TAccount { + var ainfo genesis.AccountMeta + if err := json.Unmarshal(remainder.Meta, &ainfo); err != nil { + return 0, nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err) + } + + // TODO: Use builtin.ReserveAddress... + value := cbg.CborInt(90) + if err := amap.Put(abi.AddrKey(ainfo.Owner), &value); err != nil { + return 0, nil, nil, err + } + } else if remainder.Type == genesis.TMultisig { + err := setupMsig(remainder.Meta) + if err != nil { + return 0, nil, nil, xerrors.Errorf("setting up remainder msig: %w", err) + } } amapaddr, err := amap.Root() diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index d382e4d0dff..4b86db5501e 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -330,24 +330,18 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err := json.Unmarshal(template.RemainderAccount.Meta, &ainfo); err != nil { return nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err) } - st, err := cst.Put(ctx, &account0.State{Address: ainfo.Owner}) - if err != nil { - return nil, nil, err - } _, ok := keyIDs[ainfo.Owner] if ok { return nil, nil, fmt.Errorf("remainder account has already been declared, cannot be assigned 90: %s", ainfo.Owner) } - err = state.SetActor(builtin.ReserveAddress, &types.Actor{ - Code: builtin0.AccountActorCodeID, - Balance: template.RemainderAccount.Balance, - Head: st, - }) + keyIDs[ainfo.Owner] = builtin.ReserveAddress + err = createAccountActor(ctx, cst, state, template.RemainderAccount, keyIDs) if err != nil { - return nil, nil, xerrors.Errorf("setting remainder account: %w", err) + return nil, nil, xerrors.Errorf("creating remainder acct: %w", err) } + case genesis.TMultisig: if err = createMultisigAccount(ctx, bs, cst, state, builtin.ReserveAddress, template.RemainderAccount, keyIDs); err != nil { return nil, nil, xerrors.Errorf("failed to set up remainder: %w", err)