From 770608aef14de882894db05d9aa9c0806688a6ea Mon Sep 17 00:00:00 2001 From: vyzo Date: Mon, 4 Apr 2022 14:23:13 +0300 Subject: [PATCH] update templates for actor shims --- .../actors/builtin/account/actor.go.template | 25 +++++++++++++++ chain/actors/builtin/builtin.go.template | 31 +++++++++++++++++++ chain/actors/builtin/cron/actor.go.template | 4 +++ chain/actors/builtin/init/actor.go.template | 25 +++++++++++++++ chain/actors/builtin/market/actor.go.template | 25 +++++++++++++++ chain/actors/builtin/miner/actor.go.template | 25 +++++++++++++++ .../actors/builtin/multisig/actor.go.template | 25 +++++++++++++++ chain/actors/builtin/paych/actor.go.template | 25 +++++++++++++++ chain/actors/builtin/power/actor.go.template | 25 +++++++++++++++ chain/actors/builtin/reward/actor.go.template | 25 +++++++++++++++ chain/actors/builtin/system/actor.go.template | 4 +++ .../actors/builtin/verifreg/actor.go.template | 25 +++++++++++++++ 12 files changed, 264 insertions(+) diff --git a/chain/actors/builtin/account/actor.go.template b/chain/actors/builtin/account/actor.go.template index 53962cc94..603d7c0ae 100644 --- a/chain/actors/builtin/account/actor.go.template +++ b/chain/actors/builtin/account/actor.go.template @@ -21,11 +21,32 @@ func init() { builtin.RegisterActorState(builtin{{.}}.AccountActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load{{.}}(store, root) }) + + if c, ok := actors.GetActorCodeID(actors.Version{{.}}, "account"); ok { + builtin.RegisterActorState(c, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load{{.}}(store, root) + }) + } {{end}}} var Methods = builtin4.MethodsAccount func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != "account" { + return nil, xerrors.Errorf("actor code is not account: %s", name) + } + + switch av { + {{range .versions}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + default: + return nil, xerrors.Errorf("unknown actor version: %d", av) + } + } + switch act.Code { {{range .versions}} case builtin{{.}}.AccountActorCodeID: @@ -46,6 +67,10 @@ func MakeState(store adt.Store, av actors.Version, addr address.Address) (State, } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "account"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: diff --git a/chain/actors/builtin/builtin.go.template b/chain/actors/builtin/builtin.go.template index f5d5eb77b..bee8e1363 100644 --- a/chain/actors/builtin/builtin.go.template +++ b/chain/actors/builtin/builtin.go.template @@ -13,6 +13,7 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/cbor" + "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/lotus/chain/actors/adt" "github.com/filecoin-project/lotus/chain/types" @@ -80,6 +81,11 @@ func Load(store adt.Store, act *types.Actor) (cbor.Marshaler, error) { } func ActorNameByCode(c cid.Cid) string { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name + } + switch { {{range .versions}} case builtin{{.}}.IsBuiltinActor(c): @@ -91,6 +97,11 @@ func ActorNameByCode(c cid.Cid) string { } func IsBuiltinActor(c cid.Cid) bool { + _, _, ok := actors.GetActorMetaByCode(c) + if ok { + return true + } + {{range .versions}} if builtin{{.}}.IsBuiltinActor(c) { return true @@ -100,6 +111,11 @@ func IsBuiltinActor(c cid.Cid) bool { } func IsAccountActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == "account" + } + {{range .versions}} if c == builtin{{.}}.AccountActorCodeID { return true @@ -109,6 +125,11 @@ func IsAccountActor(c cid.Cid) bool { } func IsStorageMinerActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == "storageminer" + } + {{range .versions}} if c == builtin{{.}}.StorageMinerActorCodeID { return true @@ -118,6 +139,11 @@ func IsStorageMinerActor(c cid.Cid) bool { } func IsMultisigActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == "multisig" + } + {{range .versions}} if c == builtin{{.}}.MultisigActorCodeID { return true @@ -127,6 +153,11 @@ func IsMultisigActor(c cid.Cid) bool { } func IsPaymentChannelActor(c cid.Cid) bool { + name, _, ok := actors.GetActorMetaByCode(c) + if ok { + return name == "paymentchannel" + } + {{range .versions}} if c == builtin{{.}}.PaymentChannelActorCodeID { return true diff --git a/chain/actors/builtin/cron/actor.go.template b/chain/actors/builtin/cron/actor.go.template index d73808556..6d15f693e 100644 --- a/chain/actors/builtin/cron/actor.go.template +++ b/chain/actors/builtin/cron/actor.go.template @@ -21,6 +21,10 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "cron"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: diff --git a/chain/actors/builtin/init/actor.go.template b/chain/actors/builtin/init/actor.go.template index f825eb9fa..3c1457fdf 100644 --- a/chain/actors/builtin/init/actor.go.template +++ b/chain/actors/builtin/init/actor.go.template @@ -23,6 +23,12 @@ func init() { builtin.RegisterActorState(builtin{{.}}.InitActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load{{.}}(store, root) }) + + if c, ok := actors.GetActorCodeID(actors.Version{{.}}, "init"); ok { + builtin.RegisterActorState(c, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load{{.}}(store, root) + }) + } {{end}}} var ( @@ -31,6 +37,21 @@ var ( ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != "init" { + return nil, xerrors.Errorf("actor code is not init: %s", name) + } + + switch av { + {{range .versions}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + default: + return nil, xerrors.Errorf("unknown actor version: %d", av) + } + } + switch act.Code { {{range .versions}} case builtin{{.}}.InitActorCodeID: @@ -51,6 +72,10 @@ func MakeState(store adt.Store, av actors.Version, networkName string) (State, e } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "init"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: diff --git a/chain/actors/builtin/market/actor.go.template b/chain/actors/builtin/market/actor.go.template index 72b0bd322..cf618bd73 100644 --- a/chain/actors/builtin/market/actor.go.template +++ b/chain/actors/builtin/market/actor.go.template @@ -27,6 +27,12 @@ func init() { builtin.RegisterActorState(builtin{{.}}.StorageMarketActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load{{.}}(store, root) }) + + if c, ok := actors.GetActorCodeID(actors.Version{{.}}, "storagemarket"); ok { + builtin.RegisterActorState(c, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load{{.}}(store, root) + }) + } {{end}}} var ( @@ -35,6 +41,21 @@ var ( ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != "storagemarket" { + return nil, xerrors.Errorf("actor code is not storagemarket: %s", name) + } + + switch av { + {{range .versions}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + default: + return nil, xerrors.Errorf("unknown actor version: %d", av) + } + } + switch act.Code { {{range .versions}} case builtin{{.}}.StorageMarketActorCodeID: @@ -55,6 +76,10 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "storagemarket"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: diff --git a/chain/actors/builtin/miner/actor.go.template b/chain/actors/builtin/miner/actor.go.template index 74c16be36..278213237 100644 --- a/chain/actors/builtin/miner/actor.go.template +++ b/chain/actors/builtin/miner/actor.go.template @@ -34,6 +34,12 @@ func init() { builtin.RegisterActorState(builtin{{.}}.StorageMinerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load{{.}}(store, root) }) + + if c, ok := actors.GetActorCodeID(actors.Version{{.}}, "storageminer"); ok { + builtin.RegisterActorState(c, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load{{.}}(store, root) + }) + } {{end}} } @@ -54,6 +60,21 @@ var DeclarationsMax = miner2.DeclarationsMax var AddressedSectorsMax = miner2.AddressedSectorsMax func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != "storageminer" { + return nil, xerrors.Errorf("actor code is not storageminer: %s", name) + } + + switch av { + {{range .versions}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + default: + return nil, xerrors.Errorf("unknown actor version: %d", av) + } + } + switch act.Code { {{range .versions}} case builtin{{.}}.StorageMinerActorCodeID: @@ -74,6 +95,10 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "storageminer"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: diff --git a/chain/actors/builtin/multisig/actor.go.template b/chain/actors/builtin/multisig/actor.go.template index b899815a6..6a4062900 100644 --- a/chain/actors/builtin/multisig/actor.go.template +++ b/chain/actors/builtin/multisig/actor.go.template @@ -29,9 +29,30 @@ func init() { builtin.RegisterActorState(builtin{{.}}.MultisigActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load{{.}}(store, root) }) + + if c, ok := actors.GetActorCodeID(actors.Version{{.}}, "multisig"); ok { + builtin.RegisterActorState(c, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load{{.}}(store, root) + }) + } {{end}}} func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != "multisig" { + return nil, xerrors.Errorf("actor code is not multisig: %s", name) + } + + switch av { + {{range .versions}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + default: + return nil, xerrors.Errorf("unknown actor version: %d", av) + } + } + switch act.Code { {{range .versions}} case builtin{{.}}.MultisigActorCodeID: @@ -52,6 +73,10 @@ func MakeState(store adt.Store, av actors.Version, signers []address.Address, th } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "multisig"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: diff --git a/chain/actors/builtin/paych/actor.go.template b/chain/actors/builtin/paych/actor.go.template index 7699e76b6..7f39eb8c6 100644 --- a/chain/actors/builtin/paych/actor.go.template +++ b/chain/actors/builtin/paych/actor.go.template @@ -29,10 +29,31 @@ func init() { builtin.RegisterActorState(builtin{{.}}.PaymentChannelActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load{{.}}(store, root) }) + + if c, ok := actors.GetActorCodeID(actors.Version{{.}}, "paymentchannel"); ok { + builtin.RegisterActorState(c, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load{{.}}(store, root) + }) + } {{end}}} // Load returns an abstract copy of payment channel state, irregardless of actor version func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != "paymentchannel" { + return nil, xerrors.Errorf("actor code is not paymentchannel: %s", name) + } + + switch av { + {{range .versions}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + default: + return nil, xerrors.Errorf("unknown actor version: %d", av) + } + } + switch act.Code { {{range .versions}} case builtin{{.}}.PaymentChannelActorCodeID: @@ -53,6 +74,10 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "paymentchannel"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: diff --git a/chain/actors/builtin/power/actor.go.template b/chain/actors/builtin/power/actor.go.template index fe11fc160..2feb764e5 100644 --- a/chain/actors/builtin/power/actor.go.template +++ b/chain/actors/builtin/power/actor.go.template @@ -24,6 +24,12 @@ func init() { builtin.RegisterActorState(builtin{{.}}.StoragePowerActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load{{.}}(store, root) }) + + if c, ok := actors.GetActorCodeID(actors.Version{{.}}, "storagepower"); ok { + builtin.RegisterActorState(c, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load{{.}}(store, root) + }) + } {{end}}} var ( @@ -32,6 +38,21 @@ var ( ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != "storagepower" { + return nil, xerrors.Errorf("actor code is not storagepower: %s", name) + } + + switch av { + {{range .versions}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + default: + return nil, xerrors.Errorf("unknown actor version: %d", av) + } + } + switch act.Code { {{range .versions}} case builtin{{.}}.StoragePowerActorCodeID: @@ -52,6 +73,10 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "storagepower"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: diff --git a/chain/actors/builtin/reward/actor.go.template b/chain/actors/builtin/reward/actor.go.template index 89cdddaec..dbd69d937 100644 --- a/chain/actors/builtin/reward/actor.go.template +++ b/chain/actors/builtin/reward/actor.go.template @@ -22,6 +22,12 @@ func init() { builtin.RegisterActorState(builtin{{.}}.RewardActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load{{.}}(store, root) }) + + if c, ok := actors.GetActorCodeID(actors.Version{{.}}, "reward"); ok { + builtin.RegisterActorState(c, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load{{.}}(store, root) + }) + } {{end}}} var ( @@ -30,6 +36,21 @@ var ( ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != "reward" { + return nil, xerrors.Errorf("actor code is not reward: %s", name) + } + + switch av { + {{range .versions}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + default: + return nil, xerrors.Errorf("unknown actor version: %d", av) + } + } + switch act.Code { {{range .versions}} case builtin{{.}}.RewardActorCodeID: @@ -50,6 +71,10 @@ func MakeState(store adt.Store, av actors.Version, currRealizedPower abi.Storage } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "reward"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: diff --git a/chain/actors/builtin/system/actor.go.template b/chain/actors/builtin/system/actor.go.template index 925319970..1b25e45af 100644 --- a/chain/actors/builtin/system/actor.go.template +++ b/chain/actors/builtin/system/actor.go.template @@ -26,6 +26,10 @@ func MakeState(store adt.Store, av actors.Version) (State, error) { } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "system"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: diff --git a/chain/actors/builtin/verifreg/actor.go.template b/chain/actors/builtin/verifreg/actor.go.template index 715dd6d61..d2f212fff 100644 --- a/chain/actors/builtin/verifreg/actor.go.template +++ b/chain/actors/builtin/verifreg/actor.go.template @@ -24,6 +24,12 @@ func init() { builtin.RegisterActorState(builtin{{.}}.VerifiedRegistryActorCodeID, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { return load{{.}}(store, root) }) + + if c, ok := actors.GetActorCodeID(actors.Version{{.}}, "verifiedregistry"); ok { + builtin.RegisterActorState(c, func(store adt.Store, root cid.Cid) (cbor.Marshaler, error) { + return load{{.}}(store, root) + }) + } {{end}} } @@ -33,6 +39,21 @@ var ( ) func Load(store adt.Store, act *types.Actor) (State, error) { + if name, av, ok := actors.GetActorMetaByCode(act.Code); ok { + if name != "verifiedregistry" { + return nil, xerrors.Errorf("actor code is not verifiedregistry: %s", name) + } + + switch av { + {{range .versions}} + case actors.Version{{.}}: + return load{{.}}(store, act.Head) + {{end}} + default: + return nil, xerrors.Errorf("unknown actor version: %d", av) + } + } + switch act.Code { {{range .versions}} case builtin{{.}}.VerifiedRegistryActorCodeID: @@ -53,6 +74,10 @@ func MakeState(store adt.Store, av actors.Version, rootKeyAddress address.Addres } func GetActorCodeID(av actors.Version) (cid.Cid, error) { + if c, ok := actors.GetActorCodeID(av, "verifiedregistry"); ok { + return c, nil + } + switch av { {{range .versions}} case actors.Version{{.}}: