From 88fbc044b3832a795647938fbd426bd4b29a1f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20M=C3=A4kel=C3=A4?= Date: Tue, 18 Aug 2020 13:23:28 +0300 Subject: [PATCH] adding actors for genesis msig addresses --- chain/gen/genesis/genesis.go | 22 ++++++++++++--- chain/gen/genesis/t01_init.go | 50 ++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index bb6fc467d..c142db73c 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -211,7 +211,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, err } - if err = createAccount(ctx, bs, cst, state, ida, info); err != nil { + if err = createAccount(ctx, bs, cst, state, ida, info, keyIDs); err != nil { return nil, nil, err } @@ -222,7 +222,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, nil, err } - if err = createAccount(ctx, bs, cst, state, vregroot, template.VerifregRootKey); err != nil { + if err = createAccount(ctx, bs, cst, state, vregroot, template.VerifregRootKey, keyIDs); err != nil { return nil, nil, err } @@ -266,7 +266,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return state, keyIDs, nil } -func createAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore, state *state.StateTree, ida address.Address, info genesis.Actor) error { +func createAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore, state *state.StateTree, ida address.Address, info genesis.Actor, keyIDs map[address.Address]address.Address) error { if info.Type == genesis.TAccount { var ainfo genesis.AccountMeta if err := json.Unmarshal(info.Meta, &ainfo); err != nil { @@ -294,6 +294,22 @@ func createAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore return xerrors.Errorf("failed to create empty map: %v", err) } + for _, e := range ainfo.Signers { + idAddress, _ := keyIDs[e] + st, err := cst.Put(ctx, &account.State{Address: e}) + if err != nil { + return err + } + err = state.SetActor(idAddress, &types.Actor{ + Code: builtin.AccountActorCodeID, + Balance: types.NewInt(0), + Head: st, + }) + if err != nil { + return xerrors.Errorf("setting account from actmap: %w", err) + } + } + st, err := cst.Put(ctx, &multisig.State{ Signers: ainfo.Signers, NumApprovalsThreshold: uint64(ainfo.Threshold), diff --git a/chain/gen/genesis/t01_init.go b/chain/gen/genesis/t01_init.go index 3cf0d66be..7d00601f2 100644 --- a/chain/gen/genesis/t01_init.go +++ b/chain/gen/genesis/t01_init.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/filecoin-project/go-address" "github.com/filecoin-project/specs-actors/actors/builtin" @@ -33,8 +34,30 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi keyToId := map[address.Address]address.Address{} - for i, a := range initialActors { + counter := int64(AccountStart) + + for _, a := range initialActors { if a.Type == genesis.TMultisig { + var ainfo genesis.MultisigMeta + if err := json.Unmarshal(a.Meta, &ainfo); err != nil { + return nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err) + } + for _, e := range ainfo.Signers { + fmt.Printf("init set %s t0%d\n", e, counter) + + value := cbg.CborInt(counter) + if err := amap.Put(adt.AddrKey(e), &value); err != nil { + return nil, nil, err + } + counter = counter + 1 + var err error + keyToId[e], err = address.NewIDAddress(uint64(value)) + if err != nil { + return nil, nil, err + } + + } + // Need to add actors for all multisigs too continue } @@ -47,12 +70,13 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi return nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err) } - fmt.Printf("init set %s t0%d\n", ainfo.Owner, AccountStart+int64(i)) + fmt.Printf("init set %s t0%d\n", ainfo.Owner, counter) - value := cbg.CborInt(AccountStart + int64(i)) + value := cbg.CborInt(counter) if err := amap.Put(adt.AddrKey(ainfo.Owner), &value); err != nil { return nil, nil, err } + counter = counter + 1 var err error keyToId[ainfo.Owner], err = address.NewIDAddress(uint64(value)) @@ -70,6 +94,26 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi if err := amap.Put(adt.AddrKey(ainfo.Owner), &value); err != nil { return nil, nil, err } + } else if rootVerifier.Type == genesis.TMultisig { + var ainfo genesis.MultisigMeta + if err := json.Unmarshal(rootVerifier.Meta, &ainfo); err != nil { + return nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err) + } + for _, e := range ainfo.Signers { + fmt.Printf("init set %s t0%d\n", e, counter) + + value := cbg.CborInt(counter) + if err := amap.Put(adt.AddrKey(e), &value); err != nil { + return nil, nil, err + } + counter = counter + 1 + var err error + keyToId[e], err = address.NewIDAddress(uint64(value)) + if err != nil { + return nil, nil, err + } + + } } amapaddr, err := amap.Root()