diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index d779c5820..3ff38218c 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -212,7 +212,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 } @@ -223,7 +223,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 } @@ -288,7 +288,7 @@ 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 { + if err := createAccount(ctx, bs, cst, state, remAccKey, template.RemainderAccount, keyIDs); err != nil { return nil, nil, err } err = state.SetActor(remAccKey, &types.Actor{ @@ -303,7 +303,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 { @@ -332,8 +332,32 @@ func createAccount(ctx context.Context, bs bstore.Blockstore, cst cbor.IpldStore return xerrors.Errorf("failed to create empty map: %v", err) } + var signers []address.Address + + for _, e := range ainfo.Signers { + idAddress, _ := keyIDs[e] + // Check if actor already exists + _, err := state.GetActor(e) + if err == nil { + continue + } + 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) + } + signers = append(signers, idAddress) + } + st, err := cst.Put(ctx, &multisig.State{ - Signers: ainfo.Signers, + Signers: signers, NumApprovalsThreshold: uint64(ainfo.Threshold), StartEpoch: abi.ChainEpoch(ainfo.VestingStart), UnlockDuration: abi.ChainEpoch(ainfo.VestingDuration), diff --git a/chain/gen/genesis/t01_init.go b/chain/gen/genesis/t01_init.go index c3708329b..095f275fd 100644 --- a/chain/gen/genesis/t01_init.go +++ b/chain/gen/genesis/t01_init.go @@ -33,9 +33,35 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi amap := adt.MakeEmptyMap(store) keyToId := map[address.Address]address.Address{} + counter := int64(AccountStart) - for i, a := range initialActors { + 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 { + + if _, ok := keyToId[e]; ok { + continue + } + + 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 } @@ -48,12 +74,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)) @@ -71,6 +98,29 @@ 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 { + if _, ok := keyToId[e]; ok { + continue + } + 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() diff --git a/node/impl/full/state.go b/node/impl/full/state.go index ceea2e813..f5421e2ba 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -1092,6 +1092,12 @@ func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.A return nil, err } + aid, err := a.StateLookupID(ctx, addr, tsk) + if err != nil { + log.Warnf("lookup failure %v", err) + return nil, err + } + store := a.StateManager.ChainStore().Store(ctx) var st verifreg.State @@ -1105,7 +1111,7 @@ func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.A } var dcap verifreg.DataCap - if found, err := vh.Get(adt.AddrKey(addr), &dcap); err != nil { + if found, err := vh.Get(adt.AddrKey(aid), &dcap); err != nil { return nil, err } else if !found { return nil, nil