From a62edd05de47ad741fffbf5d8b3a292705cb68e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20M=C3=A4kel=C3=A4?= Date: Mon, 20 Jul 2020 11:28:45 +0300 Subject: [PATCH] adding rootkey to genesis --- chain/gen/genesis/genesis.go | 61 +++++++++++++++++------------------- genesis/types.go | 2 ++ 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index ebacf51cb..56b3f353d 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -207,7 +207,6 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge } // var newAddress address.Address - if (info.Type == genesis.TAccount) { var ainfo genesis.AccountMeta if err := json.Unmarshal(info.Meta, &ainfo); err != nil { @@ -230,31 +229,9 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge if err := json.Unmarshal(info.Meta, &ainfo); err != nil { return nil, xerrors.Errorf("unmarshaling account meta: %w", err) } - - pending, err := adt.MakeEmptyMap(adt.WrapStore(ctx, cst)).Root() - if err != nil { - return nil, xerrors.Errorf("failed to create empty map: %v", err) - } - - st, err := cst.Put(ctx, &multisig.State{ - Signers: ainfo.Signers, - NumApprovalsThreshold: uint64(ainfo.Threshold), - StartEpoch: abi.ChainEpoch(ainfo.VestingStart), - UnlockDuration: abi.ChainEpoch(ainfo.VestingDuration), - PendingTxns: pending, - InitialBalance: info.Balance, - }) - if err != nil { + if err = createMultisig(ctx, bs, cst, state, ida, info.Balance, ainfo); err != nil { return nil, err } - err = state.SetActor(ida, &types.Actor{ - Code: builtin.MultisigActorCodeID, - Balance: info.Balance, - Head: st, - }) - if err != nil { - return nil, xerrors.Errorf("setting account from actmap: %w", err) - } } } @@ -264,22 +241,40 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge return nil, err } - vrst, err := cst.Put(ctx, &account.State{Address: RootVerifierAddr}) - if err != nil { + if err = createMultisig(ctx, bs, cst, state, vregroot, types.NewInt(0), template.VerifregRootKey); err != nil { return nil, err } - err = state.SetActor(vregroot, &types.Actor{ - Code: builtin.AccountActorCodeID, - Balance: types.NewInt(0), - Head: vrst, - }) + return state, nil +} +func createMultisig(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore, state *state.StateTree, ida address.Address, balance abi.TokenAmount, ainfo genesis.MultisigMeta) error { + + pending, err := adt.MakeEmptyMap(adt.WrapStore(ctx, cst)).Root() if err != nil { - return nil, xerrors.Errorf("setting account from actmap: %w", err) + return xerrors.Errorf("failed to create empty map: %v", err) } - return state, nil + st, err := cst.Put(ctx, &multisig.State{ + Signers: ainfo.Signers, + NumApprovalsThreshold: uint64(ainfo.Threshold), + StartEpoch: abi.ChainEpoch(ainfo.VestingStart), + UnlockDuration: abi.ChainEpoch(ainfo.VestingDuration), + PendingTxns: pending, + InitialBalance: balance, + }) + if err != nil { + return err + } + err = state.SetActor(ida, &types.Actor{ + Code: builtin.MultisigActorCodeID, + Balance: balance, + Head: st, + }) + if err != nil { + return xerrors.Errorf("setting account from actmap: %w", err) + } + return nil } func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot cid.Cid, template genesis.Template) (cid.Cid, error) { diff --git a/genesis/types.go b/genesis/types.go index acf69298f..69723e81b 100644 --- a/genesis/types.go +++ b/genesis/types.go @@ -78,4 +78,6 @@ type Template struct { NetworkName string Timestamp uint64 `json:",omitempty"` + + VerifregRootKey MultisigMeta }