From abca69b4760f4e45a7483a6180559dd129fd734c Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Tue, 18 Aug 2020 14:30:49 -0700 Subject: [PATCH] configurable remainder account --- chain/gen/gen.go | 18 +++++++++++++++--- chain/gen/genesis/genesis.go | 8 +++++++- genesis/types.go | 3 ++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/chain/gen/gen.go b/chain/gen/gen.go index bcf9c4f10..4d1a0e2ab 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -107,6 +107,17 @@ var DefaultVerifregRootkeyActor = genesis.Actor{ Meta: rootkeyMultisig.ActorMeta(), } +var remAccTestKey, _ = address.NewFromString("t1ceb34gnsc6qk5dt6n7xg6ycwzasjhbxm3iylkiy") +var remAccMeta = genesis.AccountMeta{ + Owner: remAccTestKey, +} + +var DefaultRemainderAccountActor = genesis.Actor{ + Type: genesis.TAccount, + Balance: big.NewInt(0), + Meta: remAccMeta.ActorMeta(), +} + func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) { saminer.SupportedProofTypes = map[abi.RegisteredSealProof]struct{}{ abi.RegisteredSealProof_StackedDrg2KiBV1: {}, @@ -210,9 +221,10 @@ func NewGeneratorWithSectors(numSectors int) (*ChainGen, error) { *genm1, *genm2, }, - VerifregRootKey: DefaultVerifregRootkeyActor, - NetworkName: "", - Timestamp: uint64(build.Clock.Now().Add(-500 * time.Duration(build.BlockDelaySecs) * time.Second).Unix()), + VerifregRootKey: DefaultVerifregRootkeyActor, + RemainderAccount: DefaultRemainderAccountActor, + NetworkName: "", + Timestamp: uint64(build.Clock.Now().Add(-500 * time.Duration(build.BlockDelaySecs) * time.Second).Unix()), } genb, err := genesis2.MakeGenesisBlock(context.TODO(), bs, sys, tpl) diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index 5d0a1cbfb..8c0a2632c 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -3,6 +3,7 @@ package genesis import ( "context" "encoding/json" + "fmt" "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" @@ -287,6 +288,9 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge 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, @@ -317,6 +321,7 @@ func createAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore if err != nil { return xerrors.Errorf("setting account from actmap: %w", err) } + return nil } else if info.Type == genesis.TMultisig { var ainfo genesis.MultisigMeta if err := json.Unmarshal(info.Meta, &ainfo); err != nil { @@ -346,9 +351,10 @@ func createAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore if err != nil { return xerrors.Errorf("setting account from actmap: %w", err) } + return nil } - return nil + return fmt.Errorf("failed to create account") } func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot cid.Cid, template genesis.Template, keyIDs map[address.Address]address.Address) (cid.Cid, error) { diff --git a/genesis/types.go b/genesis/types.go index 7d401fd0e..468a09067 100644 --- a/genesis/types.go +++ b/genesis/types.go @@ -79,5 +79,6 @@ type Template struct { NetworkName string Timestamp uint64 `json:",omitempty"` - VerifregRootKey Actor + VerifregRootKey Actor + RemainderAccount Actor }