From adee4b2a5ec52601561fe174e48f046fba2c8e78 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Wed, 18 Nov 2020 02:56:30 -0500 Subject: [PATCH] Setup remainder msig signers when parsing genesis template --- chain/gen/genesis/f01_init.go | 44 +++++++++++++++++++++++------------ chain/gen/genesis/genesis.go | 2 +- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/chain/gen/genesis/f01_init.go b/chain/gen/genesis/f01_init.go index 667079a6db6..24f06f2b61e 100644 --- a/chain/gen/genesis/f01_init.go +++ b/chain/gen/genesis/f01_init.go @@ -21,7 +21,7 @@ import ( bstore "github.com/filecoin-project/lotus/lib/blockstore" ) -func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesis.Actor, rootVerifier genesis.Actor) (int64, *types.Actor, map[address.Address]address.Address, error) { +func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesis.Actor, rootVerifier genesis.Actor, remainder genesis.Actor) (int64, *types.Actor, map[address.Address]address.Address, error) { if len(initialActors) > MaxAccounts { return 0, nil, nil, xerrors.New("too many initial actors") } @@ -90,19 +90,10 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi } } - if rootVerifier.Type == genesis.TAccount { - var ainfo genesis.AccountMeta - if err := json.Unmarshal(rootVerifier.Meta, &ainfo); err != nil { - return 0, nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err) - } - value := cbg.CborInt(80) - if err := amap.Put(abi.AddrKey(ainfo.Owner), &value); err != nil { - return 0, nil, nil, err - } - } else if rootVerifier.Type == genesis.TMultisig { + setupMsig := func(meta json.RawMessage) error { var ainfo genesis.MultisigMeta - if err := json.Unmarshal(rootVerifier.Meta, &ainfo); err != nil { - return 0, nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err) + if err := json.Unmarshal(meta, &ainfo); err != nil { + return xerrors.Errorf("unmarshaling account meta: %w", err) } for _, e := range ainfo.Signers { if _, ok := keyToId[e]; ok { @@ -112,16 +103,39 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi value := cbg.CborInt(counter) if err := amap.Put(abi.AddrKey(e), &value); err != nil { - return 0, nil, nil, err + return err } counter = counter + 1 var err error keyToId[e], err = address.NewIDAddress(uint64(value)) if err != nil { - return 0, nil, nil, err + return err } } + + return nil + } + + if rootVerifier.Type == genesis.TAccount { + var ainfo genesis.AccountMeta + if err := json.Unmarshal(rootVerifier.Meta, &ainfo); err != nil { + return 0, nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err) + } + value := cbg.CborInt(80) + if err := amap.Put(abi.AddrKey(ainfo.Owner), &value); err != nil { + return 0, nil, nil, err + } + } else if rootVerifier.Type == genesis.TMultisig { + err := setupMsig(rootVerifier.Meta) + if err != nil { + return 0, nil, nil, xerrors.Errorf("setting up root verifier msig: %w", err) + } + } + + 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 e441af7ae11..ef81410bba7 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -134,7 +134,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge // Create init actor - idStart, initact, keyIDs, err := SetupInitActor(bs, template.NetworkName, template.Accounts, template.VerifregRootKey) + idStart, initact, keyIDs, err := SetupInitActor(bs, template.NetworkName, template.Accounts, template.VerifregRootKey, template.RemainderAccount) if err != nil { return nil, nil, xerrors.Errorf("setup init actor: %w", err) }