feat: actors: add the evm to the builtin actors shims (#9672)
This commit is contained in:
parent
3a23ae6ea4
commit
348494d7c8
@ -28,6 +28,7 @@ var actors = map[string][]int{
|
||||
"reward": lotusactors.Versions,
|
||||
"verifreg": lotusactors.Versions,
|
||||
"datacap": lotusactors.Versions[8:],
|
||||
"evm": lotusactors.Versions[9:],
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
51
chain/actors/builtin/evm/actor.go.template
Normal file
51
chain/actors/builtin/evm/actor.go.template
Normal file
@ -0,0 +1,51 @@
|
||||
package evm
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
||||
"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"
|
||||
|
||||
builtin{{.latestVersion}} "github.com/filecoin-project/go-state-types/builtin"
|
||||
)
|
||||
|
||||
var Methods = builtin{{.latestVersion}}.MethodsEVM
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
|
||||
if name != actors.EvmKey {
|
||||
return nil, xerrors.Errorf("actor code is not evm: %s", name)
|
||||
}
|
||||
|
||||
switch av {
|
||||
{{range .versions}}
|
||||
case actorstypes.Version{{.}}:
|
||||
return load{{.}}(store, act.Head)
|
||||
{{end}}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
|
||||
func MakeState(store adt.Store, av actorstypes.Version, bytecode cid.Cid) (State, error) {
|
||||
switch av {
|
||||
{{range .versions}}
|
||||
case actorstypes.Version{{.}}:
|
||||
return make{{.}}(store, bytecode)
|
||||
{{end}}
|
||||
default: return nil, xerrors.Errorf("evm actor only valid for actors v10 and above, got %d", av)
|
||||
}
|
||||
}
|
||||
|
||||
type State interface {
|
||||
cbor.Marshaler
|
||||
|
||||
Nonce() (uint64, error)
|
||||
GetState() interface{}
|
||||
}
|
51
chain/actors/builtin/evm/evm.go
Normal file
51
chain/actors/builtin/evm/evm.go
Normal file
@ -0,0 +1,51 @@
|
||||
package evm
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
actorstypes "github.com/filecoin-project/go-state-types/actors"
|
||||
builtin10 "github.com/filecoin-project/go-state-types/builtin"
|
||||
"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"
|
||||
)
|
||||
|
||||
var Methods = builtin10.MethodsEVM
|
||||
|
||||
func Load(store adt.Store, act *types.Actor) (State, error) {
|
||||
if name, av, ok := actors.GetActorMetaByCode(act.Code); ok {
|
||||
if name != actors.EvmKey {
|
||||
return nil, xerrors.Errorf("actor code is not evm: %s", name)
|
||||
}
|
||||
|
||||
switch av {
|
||||
|
||||
case actorstypes.Version10:
|
||||
return load10(store, act.Head)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return nil, xerrors.Errorf("unknown actor code %s", act.Code)
|
||||
}
|
||||
|
||||
func MakeState(store adt.Store, av actorstypes.Version, bytecode cid.Cid) (State, error) {
|
||||
switch av {
|
||||
|
||||
case actorstypes.Version10:
|
||||
return make10(store, bytecode)
|
||||
|
||||
default:
|
||||
return nil, xerrors.Errorf("evm actor only valid for actors v10 and above, got %d", av)
|
||||
}
|
||||
}
|
||||
|
||||
type State interface {
|
||||
cbor.Marshaler
|
||||
|
||||
Nonce() (uint64, error)
|
||||
GetState() interface{}
|
||||
}
|
45
chain/actors/builtin/evm/state.go.template
Normal file
45
chain/actors/builtin/evm/state.go.template
Normal file
@ -0,0 +1,45 @@
|
||||
package evm
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
|
||||
evm{{.v}} "github.com/filecoin-project/go-state-types/builtin{{.import}}evm"
|
||||
)
|
||||
|
||||
var _ State = (*state{{.v}})(nil)
|
||||
|
||||
func load{{.v}}(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state{{.v}}{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make{{.v}}(store adt.Store, bytecode cid.Cid) (State, error) {
|
||||
out := state{{.v}}{store: store}
|
||||
s, err := evm{{.v}}.ConstructState(store, bytecode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State = *s
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state{{.v}} struct {
|
||||
evm{{.v}}.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state{{.v}}) Nonce() (uint64, error) {
|
||||
return s.State.Nonce, nil
|
||||
}
|
||||
|
||||
func (s *state{{.v}}) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
45
chain/actors/builtin/evm/v10.go
Normal file
45
chain/actors/builtin/evm/v10.go
Normal file
@ -0,0 +1,45 @@
|
||||
package evm
|
||||
|
||||
import (
|
||||
"github.com/ipfs/go-cid"
|
||||
|
||||
evm10 "github.com/filecoin-project/go-state-types/builtin/v10/evm"
|
||||
|
||||
"github.com/filecoin-project/lotus/chain/actors/adt"
|
||||
)
|
||||
|
||||
var _ State = (*state10)(nil)
|
||||
|
||||
func load10(store adt.Store, root cid.Cid) (State, error) {
|
||||
out := state10{store: store}
|
||||
err := store.Get(store.Context(), root, &out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func make10(store adt.Store, bytecode cid.Cid) (State, error) {
|
||||
out := state10{store: store}
|
||||
s, err := evm10.ConstructState(store, bytecode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out.State = *s
|
||||
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
type state10 struct {
|
||||
evm10.State
|
||||
store adt.Store
|
||||
}
|
||||
|
||||
func (s *state10) Nonce() (uint64, error) {
|
||||
return s.State.Nonce, nil
|
||||
}
|
||||
|
||||
func (s *state10) GetState() interface{} {
|
||||
return &s.State
|
||||
}
|
2
go.mod
2
go.mod
@ -42,7 +42,7 @@ require (
|
||||
github.com/filecoin-project/go-legs v0.4.4
|
||||
github.com/filecoin-project/go-padreader v0.0.1
|
||||
github.com/filecoin-project/go-paramfetch v0.0.4
|
||||
github.com/filecoin-project/go-state-types v0.9.10-0.20221109071515-5536f160fe27
|
||||
github.com/filecoin-project/go-state-types v0.9.10-0.20221116233942-e49c83ccf23b
|
||||
github.com/filecoin-project/go-statemachine v1.0.2
|
||||
github.com/filecoin-project/go-statestore v0.2.0
|
||||
github.com/filecoin-project/go-storedcounter v0.1.0
|
||||
|
4
go.sum
4
go.sum
@ -343,8 +343,8 @@ github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psS
|
||||
github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
|
||||
github.com/filecoin-project/go-state-types v0.1.8/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
|
||||
github.com/filecoin-project/go-state-types v0.1.10/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q=
|
||||
github.com/filecoin-project/go-state-types v0.9.10-0.20221109071515-5536f160fe27 h1:1/o3al2zThas9rW6xqPKAzjs4q2tiBHaBNBP2sx0Vc4=
|
||||
github.com/filecoin-project/go-state-types v0.9.10-0.20221109071515-5536f160fe27/go.mod h1:7ty480tvttEAqWKywhAaDCElk7ksTqEXtXWAzTSdEKo=
|
||||
github.com/filecoin-project/go-state-types v0.9.10-0.20221116233942-e49c83ccf23b h1:seLs+8DkIOu5k01y2RLygOqH8F/NWjXSkzhlVK6tZaA=
|
||||
github.com/filecoin-project/go-state-types v0.9.10-0.20221116233942-e49c83ccf23b/go.mod h1:7ty480tvttEAqWKywhAaDCElk7ksTqEXtXWAzTSdEKo=
|
||||
github.com/filecoin-project/go-statemachine v0.0.0-20200925024713-05bd7c71fbfe/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
|
||||
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
|
||||
github.com/filecoin-project/go-statemachine v1.0.2/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54=
|
||||
|
Loading…
Reference in New Issue
Block a user