Setup remainder msig signers when parsing genesis template

This commit is contained in:
Aayush Rajasekaran 2020-11-18 02:56:30 -05:00
parent 9305947547
commit adee4b2a5e
2 changed files with 36 additions and 22 deletions

View File

@ -21,7 +21,7 @@ import (
bstore "github.com/filecoin-project/lotus/lib/blockstore" bstore "github.com/filecoin-project/lotus/lib/blockstore"
) )
func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesis.Actor, rootVerifier genesis.Actor) (int64, *types.Actor, map[address.Address]address.Address, error) { func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesis.Actor, rootVerifier genesis.Actor, remainder genesis.Actor) (int64, *types.Actor, map[address.Address]address.Address, error) {
if len(initialActors) > MaxAccounts { if len(initialActors) > MaxAccounts {
return 0, nil, nil, xerrors.New("too many initial actors") return 0, nil, nil, xerrors.New("too many initial actors")
} }
@ -90,6 +90,33 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi
} }
} }
setupMsig := func(meta json.RawMessage) error {
var ainfo genesis.MultisigMeta
if err := json.Unmarshal(meta, &ainfo); err != nil {
return 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(abi.AddrKey(e), &value); err != nil {
return err
}
counter = counter + 1
var err error
keyToId[e], err = address.NewIDAddress(uint64(value))
if err != nil {
return err
}
}
return nil
}
if rootVerifier.Type == genesis.TAccount { if rootVerifier.Type == genesis.TAccount {
var ainfo genesis.AccountMeta var ainfo genesis.AccountMeta
if err := json.Unmarshal(rootVerifier.Meta, &ainfo); err != nil { if err := json.Unmarshal(rootVerifier.Meta, &ainfo); err != nil {
@ -100,28 +127,15 @@ func SetupInitActor(bs bstore.Blockstore, netname string, initialActors []genesi
return 0, nil, nil, err return 0, nil, nil, err
} }
} else if rootVerifier.Type == genesis.TMultisig { } else if rootVerifier.Type == genesis.TMultisig {
var ainfo genesis.MultisigMeta err := setupMsig(rootVerifier.Meta)
if err := json.Unmarshal(rootVerifier.Meta, &ainfo); err != nil { if err != nil {
return 0, nil, nil, xerrors.Errorf("unmarshaling account meta: %w", err) return 0, nil, nil, xerrors.Errorf("setting up root verifier msig: %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) err := setupMsig(remainder.Meta)
if err := amap.Put(abi.AddrKey(e), &value); err != nil { if err != nil {
return 0, nil, nil, err return 0, nil, nil, xerrors.Errorf("setting up remainder msig: %w", err)
}
counter = counter + 1
var err error
keyToId[e], err = address.NewIDAddress(uint64(value))
if err != nil {
return 0, nil, nil, err
}
}
} }
amapaddr, err := amap.Root() amapaddr, err := amap.Root()

View File

@ -134,7 +134,7 @@ func MakeInitialStateTree(ctx context.Context, bs bstore.Blockstore, template ge
// Create init actor // Create init actor
idStart, initact, keyIDs, err := SetupInitActor(bs, template.NetworkName, template.Accounts, template.VerifregRootKey) idStart, initact, keyIDs, err := SetupInitActor(bs, template.NetworkName, template.Accounts, template.VerifregRootKey, template.RemainderAccount)
if err != nil { if err != nil {
return nil, nil, xerrors.Errorf("setup init actor: %w", err) return nil, nil, xerrors.Errorf("setup init actor: %w", err)
} }