migrate lotus-shed/genesis-verify to actor abstraction

This commit is contained in:
Steven Allen 2020-09-21 15:18:30 -07:00
parent 4bab784e40
commit 3f0106cfe5
5 changed files with 43 additions and 37 deletions

View File

@ -18,15 +18,6 @@ import (
"github.com/filecoin-project/lotus/chain/types"
)
// Returns true if the specified actor code ID is a miner actor.
func Is(code cid.Cid) bool {
switch code {
case builtin0.StorageMinerActorCodeID:
return true
}
return false
}
func Load(store adt.Store, act *types.Actor) (st State, err error) {
switch act.Code {
case builtin0.StorageMinerActorCodeID:

View File

@ -5,7 +5,7 @@ import (
"github.com/ipfs/go-cid"
"github.com/filecoin-project/specs-actors/actors/builtin"
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
)
var ErrActorNotFound = errors.New("actor not found")
@ -19,5 +19,13 @@ type Actor struct {
}
func (a *Actor) IsAccountActor() bool {
return a.Code == builtin.AccountActorCodeID
return a.Code == builtin0.AccountActorCodeID
}
func (a *Actor) IsStorageMinerActor() bool {
return a.Code == builtin0.StorageMinerActorCodeID
}
func (a *Actor) IsMultisigActor() bool {
return a.Code == builtin0.MultisigActorCodeID
}

View File

@ -89,7 +89,7 @@ var chainBalanceCmd = &cli.Command{
Type: string(act.Code.Hash()[2:]),
}
if miner.Is(act.Code) {
if act.IsStorageMinerActor() {
pow, err := api.StateMinerPower(ctx, addr, tsk)
if err != nil {
return xerrors.Errorf("failed to get power: %w", err)
@ -191,7 +191,7 @@ var chainBalanceStateCmd = &cli.Command{
PreCommits: types.FIL(big.NewInt(0)),
}
if minerInfo && miner.Is(act.Code) {
if minerInfo && act.IsStorageMinerActor() {
pow, _, _, err := stmgr.GetPowerRaw(ctx, sm, sroot, addr)
if err != nil {
return xerrors.Errorf("failed to get power: %w", err)

View File

@ -14,16 +14,17 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/actors/adt"
"github.com/filecoin-project/lotus/chain/actors/builtin/account"
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/actors/builtin/multisig"
"github.com/filecoin-project/lotus/chain/state"
"github.com/filecoin-project/lotus/chain/stmgr"
"github.com/filecoin-project/lotus/chain/store"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/lib/blockstore"
"github.com/filecoin-project/specs-actors/actors/builtin"
saacc "github.com/filecoin-project/specs-actors/actors/builtin/account"
saminer "github.com/filecoin-project/specs-actors/actors/builtin/miner"
samsig "github.com/filecoin-project/specs-actors/actors/builtin/multisig"
)
type addrInfo struct {
@ -90,36 +91,41 @@ var genesisVerifyCmd = &cli.Command{
kminers := make(map[address.Address]minerInfo)
ctx := context.TODO()
store := adt.WrapStore(ctx, cst)
if err := stree.ForEach(func(addr address.Address, act *types.Actor) error {
switch act.Code {
case builtin.StorageMinerActorCodeID:
var st saminer.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
return err
switch {
case act.IsStorageMinerActor():
_, err := miner.Load(store, act)
if err != nil {
return xerrors.Errorf("miner actor: %w", err)
}
// TODO: actually verify something here?
kminers[addr] = minerInfo{}
case builtin.MultisigActorCodeID:
var st samsig.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
case act.IsMultisigActor():
st, err := multisig.Load(store, act)
if err != nil {
return xerrors.Errorf("multisig actor: %w", err)
}
kmultisigs[addr] = msigInfo{
Balance: types.FIL(act.Balance),
Signers: st.Signers,
Threshold: st.NumApprovalsThreshold,
Signers: st.Signers(),
Threshold: st.Threshold(),
}
msigAddrs = append(msigAddrs, addr)
case builtin.AccountActorCodeID:
var st saacc.State
if err := cst.Get(ctx, act.Head, &st); err != nil {
log.Warn(xerrors.Errorf("account actor %s: %w", addr, err))
case act.IsAccountActor():
st, err := account.Load(store, act)
if err != nil {
// TODO: magik6k: this _used_ to log instead of failing, why?
return xerrors.Errorf("account actor %s: %w", addr, err)
}
pkaddr, err := st.PubkeyAddress()
if err != nil {
return xerrors.Errorf("failed to get actor pk address %s: %w", addr, err)
}
kaccounts[addr] = addrInfo{
Key: st.Address,
Key: pkaddr,
Balance: types.FIL(act.Balance.Copy()),
}
accAddrs = append(accAddrs, addr)

View File

@ -14,11 +14,12 @@ import (
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
builtin0 "github.com/filecoin-project/specs-actors/actors/builtin"
"github.com/filecoin-project/go-address"
lapi "github.com/filecoin-project/lotus/api"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/specs-actors/actors/builtin"
)
var (
@ -121,7 +122,7 @@ var mpoolStatsCmd = &cli.Command{
return false, err
}
ism := act.Code == builtin.StorageMinerActorCodeID
ism := act.IsStorageMinerActor()
mcache[addr] = ism
return ism, nil
}
@ -143,7 +144,7 @@ var mpoolStatsCmd = &cli.Command{
seen: time.Now(),
}
if u.Message.Message.Method == builtin.MethodsMiner.SubmitWindowedPoSt {
if u.Message.Message.Method == builtin0.MethodsMiner.SubmitWindowedPoSt {
miner, err := isMiner(u.Message.Message.To)
if err != nil {