Merge branch 'fix/genesis-multisig' of git://github.com/keyko-io/lotus into keyko-io-fix/genesis-multisig
This commit is contained in:
commit
073efeeacb
@ -212,7 +212,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
|||||||
return nil, nil, err
|
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
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
|||||||
return nil, nil, err
|
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
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
|||||||
return nil, nil, err
|
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
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
err = state.SetActor(remAccKey, &types.Actor{
|
err = state.SetActor(remAccKey, &types.Actor{
|
||||||
@ -303,7 +303,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
|
|||||||
return state, keyIDs, nil
|
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 {
|
if info.Type == genesis.TAccount {
|
||||||
var ainfo genesis.AccountMeta
|
var ainfo genesis.AccountMeta
|
||||||
if err := json.Unmarshal(info.Meta, &ainfo); err != nil {
|
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)
|
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{
|
st, err := cst.Put(ctx, &multisig.State{
|
||||||
Signers: ainfo.Signers,
|
Signers: signers,
|
||||||
NumApprovalsThreshold: uint64(ainfo.Threshold),
|
NumApprovalsThreshold: uint64(ainfo.Threshold),
|
||||||
StartEpoch: abi.ChainEpoch(ainfo.VestingStart),
|
StartEpoch: abi.ChainEpoch(ainfo.VestingStart),
|
||||||
UnlockDuration: abi.ChainEpoch(ainfo.VestingDuration),
|
UnlockDuration: abi.ChainEpoch(ainfo.VestingDuration),
|
||||||
|
@ -33,9 +33,35 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi
|
|||||||
amap := adt.MakeEmptyMap(store)
|
amap := adt.MakeEmptyMap(store)
|
||||||
|
|
||||||
keyToId := map[address.Address]address.Address{}
|
keyToId := map[address.Address]address.Address{}
|
||||||
|
counter := int64(AccountStart)
|
||||||
|
|
||||||
for i, a := range initialActors {
|
for _, a := range initialActors {
|
||||||
if a.Type == genesis.TMultisig {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,12 +74,13 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi
|
|||||||
return nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err)
|
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 {
|
if err := amap.Put(adt.AddrKey(ainfo.Owner), &value); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
counter = counter + 1
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
keyToId[ainfo.Owner], err = address.NewIDAddress(uint64(value))
|
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 {
|
if err := amap.Put(adt.AddrKey(ainfo.Owner), &value); err != nil {
|
||||||
return nil, nil, err
|
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()
|
amapaddr, err := amap.Root()
|
||||||
|
@ -1092,6 +1092,12 @@ func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.A
|
|||||||
return nil, err
|
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)
|
store := a.StateManager.ChainStore().Store(ctx)
|
||||||
|
|
||||||
var st verifreg.State
|
var st verifreg.State
|
||||||
@ -1105,7 +1111,7 @@ func (a *StateAPI) StateVerifiedClientStatus(ctx context.Context, addr address.A
|
|||||||
}
|
}
|
||||||
|
|
||||||
var dcap verifreg.DataCap
|
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
|
return nil, err
|
||||||
} else if !found {
|
} else if !found {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user