Skip to content

Commit

Permalink
Merge pull request #5635 from filecoin-project/fix/fevm-registry
Browse files Browse the repository at this point in the history
chore: Add new FEVM actors to the registry
  • Loading branch information
diwufeiwen authored Jan 9, 2023
2 parents 878b115 + aa273ae commit 9ef2a65
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 56 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/filecoin-project/go-fil-markets v1.25.2
github.com/filecoin-project/go-jsonrpc v0.1.5
github.com/filecoin-project/go-paramfetch v0.0.4
github.com/filecoin-project/go-state-types v0.10.0-alpha.7
github.com/filecoin-project/go-state-types v0.10.0-alpha-8
github.com/filecoin-project/pubsub v1.0.0
github.com/filecoin-project/specs-actors v0.9.15
github.com/filecoin-project/specs-actors/v2 v2.3.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ github.com/filecoin-project/go-state-types v0.1.4/go.mod h1:xCA/WfKlC2zcn3fUmDv4
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.10.0-alpha.7 h1:CnHwzDJpeixx1FLHtlp3iDv2j346qFDYa0w99mSt9A4=
github.com/filecoin-project/go-state-types v0.10.0-alpha.7/go.mod h1:FPgQE05BFwZxKw/vCuIaIrzfJKo4RPQQMMPGd43dAFI=
github.com/filecoin-project/go-state-types v0.10.0-alpha-8 h1:BPUEnjs4eBjhX+WCeG/Mfpoc7umYVgXENur73PJ1cNc=
github.com/filecoin-project/go-state-types v0.10.0-alpha-8/go.mod h1:FPgQE05BFwZxKw/vCuIaIrzfJKo4RPQQMMPGd43dAFI=
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=
Expand Down
8 changes: 4 additions & 4 deletions pkg/vm/register/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ func GetDefaultActros() *dispatch.CodeLoader {
}

func DumpActorState(codeLoader *dispatch.CodeLoader, act *types.Actor, b []byte) (interface{}, error) {
if builtin.IsAccountActor(act.Code) || builtin.IsEmbryoActor(act.Code) { // Account code special case
return nil, nil
}

vmActor, err := codeLoader.GetVMActor(act.Code)
if err != nil {
return nil, fmt.Errorf("state type for actor %s not found", act.Code)
}

um := vmActor.State()
if um == nil {
// TODO: I would like to assert that we have the empty object here
return nil, nil
}
if err := um.UnmarshalCBOR(bytes.NewReader(b)); err != nil {
return nil, fmt.Errorf("unmarshaling actor state: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions venus-devtool/api-gen/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ func init() {
ethFeeHistoryReward := [][]types.EthBigInt{}
addExample(&ethFeeHistoryReward)

filterid, _ := types.EthHashFromHex("0x5CbEeC012345673f25E309Cc264f240bb0664031")
filterid, _ := types.NewEthHashFromHex("0x5CbEeC012345673f25E309Cc264f240bb0664031")
addExample(types.EthFilterID(filterid))

subid, _ := types.EthHashFromHex("0x5CbEeCF99d3fDB301234567c264f240bb0664031")
subid, _ := types.NewEthHashFromHex("0x5CbEeCF99d3fDB301234567c264f240bb0664031")
addExample(types.EthSubscriptionID(subid))

pstring := func(s string) *string { return &s }
Expand Down
4 changes: 2 additions & 2 deletions venus-devtool/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ require (
github.com/filecoin-project/go-data-transfer v1.15.2
github.com/filecoin-project/go-fil-markets v1.25.2
github.com/filecoin-project/go-jsonrpc v0.1.9
github.com/filecoin-project/go-state-types v0.10.0-alpha.7
github.com/filecoin-project/lotus v1.18.2-0.20221222182453-336a0e5b85d3
github.com/filecoin-project/go-state-types v0.10.0-alpha-8
github.com/filecoin-project/lotus v1.18.2-0.20230108083103-402173ea1680
github.com/filecoin-project/venus v0.0.0-00010101000000-000000000000
github.com/google/uuid v1.3.0
github.com/ipfs/go-block-format v0.0.3
Expand Down
8 changes: 4 additions & 4 deletions venus-devtool/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,14 @@ github.com/filecoin-project/go-state-types v0.1.4/go.mod h1:xCA/WfKlC2zcn3fUmDv4
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.10.0-alpha.7 h1:CnHwzDJpeixx1FLHtlp3iDv2j346qFDYa0w99mSt9A4=
github.com/filecoin-project/go-state-types v0.10.0-alpha.7/go.mod h1:FPgQE05BFwZxKw/vCuIaIrzfJKo4RPQQMMPGd43dAFI=
github.com/filecoin-project/go-state-types v0.10.0-alpha-8 h1:BPUEnjs4eBjhX+WCeG/Mfpoc7umYVgXENur73PJ1cNc=
github.com/filecoin-project/go-state-types v0.10.0-alpha-8/go.mod h1:FPgQE05BFwZxKw/vCuIaIrzfJKo4RPQQMMPGd43dAFI=
github.com/filecoin-project/go-statemachine v1.0.2 h1:421SSWBk8GIoCoWYYTE/d+qCWccgmRH0uXotXRDjUbc=
github.com/filecoin-project/go-statestore v0.2.0 h1:cRRO0aPLrxKQCZ2UOQbzFGn4WDNdofHZoGPjfNaAo5Q=
github.com/filecoin-project/go-statestore v0.2.0/go.mod h1:8sjBYbS35HwPzct7iT4lIXjLlYyPor80aU7t7a/Kspo=
github.com/filecoin-project/index-provider v0.9.1 h1:Jnh9dviIHvQxZ2baNoYu3n8z6F9O62ksnVlyREgPyyM=
github.com/filecoin-project/lotus v1.18.2-0.20221222182453-336a0e5b85d3 h1:KB6DslfOUGKWbq/Jk6gANVZx8OyjbjwZ9yjT0RyKE4I=
github.com/filecoin-project/lotus v1.18.2-0.20221222182453-336a0e5b85d3/go.mod h1:Wp01KhlNEu5aWIxW3lBK7mX3FxzfAmYH/2CsCmdW+rA=
github.com/filecoin-project/lotus v1.18.2-0.20230108083103-402173ea1680 h1:nDy+HQCrybXXc5nrpx7pMn5WTMDiptZqaP9piM7695Y=
github.com/filecoin-project/lotus v1.18.2-0.20230108083103-402173ea1680/go.mod h1:emiDF53AY1WZ0QdE69odrL4hsS/9NZqs2qP1hT4LIF8=
github.com/filecoin-project/pubsub v1.0.0 h1:ZTmT27U07e54qV1mMiQo4HDr0buo8I1LDHBYLXlsNXM=
github.com/filecoin-project/pubsub v1.0.0/go.mod h1:GkpB33CcUtUNrLPhJgfdy4FDx4OMNR9k+46DHx/Lqrg=
github.com/filecoin-project/specs-actors v0.9.13/go.mod h1:TS1AW/7LbG+615j4NsjMK1qlpAwaFsG9w0V2tg2gSao=
Expand Down
32 changes: 32 additions & 0 deletions venus-shared/actors/builtin/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ import (

datacap10 "github.com/filecoin-project/go-state-types/builtin/v10/datacap"

eam10 "github.com/filecoin-project/go-state-types/builtin/v10/eam"
embryo10 "github.com/filecoin-project/go-state-types/builtin/v10/embryo"
ethaccount10 "github.com/filecoin-project/go-state-types/builtin/v10/ethaccount"
evm10 "github.com/filecoin-project/go-state-types/builtin/v10/evm"

"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/cbor"
"github.com/filecoin-project/go-state-types/manifest"
Expand Down Expand Up @@ -272,6 +277,7 @@ func MakeRegistry(av actorstypes.Version) []RegistryEntry {
methods: datacap9.Methods,
state: new(datacap9.State),
})

}
}

Expand Down Expand Up @@ -350,6 +356,32 @@ func MakeRegistry(av actorstypes.Version) []RegistryEntry {
methods: datacap10.Methods,
state: new(datacap10.State),
})

case manifest.EvmKey:
registry = append(registry, RegistryEntry{
code: codeID,
methods: evm10.Methods,
state: new(evm10.State),
})
case manifest.EamKey:
registry = append(registry, RegistryEntry{
code: codeID,
methods: eam10.Methods,
state: nil,
})
case manifest.EmbryoKey:
registry = append(registry, RegistryEntry{
code: codeID,
methods: embryo10.Methods,
state: nil,
})
case manifest.EthAccountKey:
registry = append(registry, RegistryEntry{
code: codeID,
methods: ethaccount10.Methods,
state: nil,
})

}
}

Expand Down
32 changes: 32 additions & 0 deletions venus-shared/actors/builtin/registry.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import (
{{if (ge . 9)}}
datacap{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/datacap"
{{end}}
{{if (ge . 10)}}
evm{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/evm"
eam{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/eam"
embryo{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/embryo"
ethaccount{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/ethaccount"
{{end}}
{{end}}
"github.com/filecoin-project/go-state-types/cbor"
rtt "github.com/filecoin-project/go-state-types/rt"
Expand Down Expand Up @@ -176,6 +182,32 @@ func MakeRegistry(av actorstypes.Version) []RegistryEntry {
methods: datacap{{.}}.Methods,
state: new(datacap{{.}}.State),
}){{end}}
{{if (ge . 10)}}
case manifest.EvmKey:
registry = append(registry, RegistryEntry{
code: codeID,
methods: evm{{.}}.Methods,
state: new(evm{{.}}.State),
})
case manifest.EamKey:
registry = append(registry, RegistryEntry{
code: codeID,
methods: eam{{.}}.Methods,
state: nil,
})
case manifest.EmbryoKey:
registry = append(registry, RegistryEntry{
code: codeID,
methods: embryo{{.}}.Methods,
state: nil,
})
case manifest.EthAccountKey:
registry = append(registry, RegistryEntry{
code: codeID,
methods: ethaccount{{.}}.Methods,
state: nil,
})
{{end}}
}
}
{{end}}
Expand Down
3 changes: 0 additions & 3 deletions venus-shared/compatible-checks/api-diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ github.com/filecoin-project/venus/venus-shared/api/chain/v1.FullNode <> github.c
+ Concurrent
- CreateBackup
- Discover
> EthGetTransactionByBlockHashAndIndex {[func(context.Context, types.EthHash, types.EthUint64) (types.EthTx, error) <> func(context.Context, ethtypes.EthHash, ethtypes.EthUint64) (ethtypes.EthTx, error)] base=func out type: #0 input; nested={[types.EthTx <> ethtypes.EthTx] base=struct field; nested={[types.EthTx <> ethtypes.EthTx] base=exported field type: #3 field named BlockHash; nested={[*types.EthHash <> ethtypes.EthHash] base=type kinds: ptr != array; nested=nil}}}}
> EthGetTransactionByBlockNumberAndIndex {[func(context.Context, types.EthUint64, types.EthUint64) (types.EthTx, error) <> func(context.Context, ethtypes.EthUint64, ethtypes.EthUint64) (ethtypes.EthTx, error)] base=func out type: #0 input; nested={[types.EthTx <> ethtypes.EthTx] base=struct field; nested={[types.EthTx <> ethtypes.EthTx] base=exported field type: #3 field named BlockHash; nested={[*types.EthHash <> ethtypes.EthHash] base=type kinds: ptr != array; nested=nil}}}}
> EthGetTransactionByHash {[func(context.Context, *types.EthHash) (*types.EthTx, error) <> func(context.Context, *ethtypes.EthHash) (*ethtypes.EthTx, error)] base=func out type: #0 input; nested={[*types.EthTx <> *ethtypes.EthTx] base=pointed type; nested={[types.EthTx <> ethtypes.EthTx] base=struct field; nested={[types.EthTx <> ethtypes.EthTx] base=exported field type: #3 field named BlockHash; nested={[*types.EthHash <> ethtypes.EthHash] base=type kinds: ptr != array; nested=nil}}}}}
+ GasBatchEstimateMessageGas
> GasEstimateMessageGas {[func(context.Context, *internal.Message, *types.MessageSendSpec, types.TipSetKey) (*internal.Message, error) <> func(context.Context, *types.Message, *api.MessageSendSpec, types.TipSetKey) (*types.Message, error)] base=func in type: #2 input; nested={[*types.MessageSendSpec <> *api.MessageSendSpec] base=pointed type; nested={[types.MessageSendSpec <> api.MessageSendSpec] base=struct field; nested={[types.MessageSendSpec <> api.MessageSendSpec] base=exported fields count: 3 != 2; nested=nil}}}}
+ GetActor
Expand Down
6 changes: 3 additions & 3 deletions venus-shared/types/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (h *EthHash) UnmarshalJSON(b []byte) error {
if err := json.Unmarshal(b, &s); err != nil {
return err
}
hash, err := EthHashFromHex(s)
hash, err := NewEthHashFromHex(s)
if err != nil {
return err
}
Expand Down Expand Up @@ -381,10 +381,10 @@ func decodeHexString(s string, length int) ([]byte, error) {
}

func NewEthHashFromCid(c cid.Cid) (EthHash, error) {
return EthHashFromHex(c.Hash().HexString()[8:])
return NewEthHashFromHex(c.Hash().HexString()[8:])
}

func EthHashFromHex(s string) (EthHash, error) {
func NewEthHashFromHex(s string) (EthHash, error) {
handlePrefix(&s)
b, err := decodeHexString(s, EthHashLength)
if err != nil {
Expand Down
34 changes: 4 additions & 30 deletions venus-shared/utils/method_map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"testing"

"github.com/filecoin-project/go-state-types/manifest"
tf "github.com/filecoin-project/venus/pkg/testhelpers/testflags"
"github.com/filecoin-project/venus/venus-shared/actors"
"github.com/filecoin-project/venus/venus-shared/types"
Expand All @@ -16,49 +15,24 @@ func TestMethodMap(t *testing.T) {
t.Run("Default to load mainnet actors", func(t *testing.T) {
for _, actorsMetadata := range actors.EmbeddedBuiltinActorsMetadata {
if actorsMetadata.Network == string(types.NetworkNameMain) {
for name, actor := range actorsMetadata.Actors {
for _, actor := range actorsMetadata.Actors {
_, ok := MethodsMap[actor]
if skipEvmActor(name) {
assert.False(t, ok)
} else {
assert.True(t, ok)
}
assert.True(t, ok)
}
}
}
})

t.Run("ReLoad butterflynet actors", func(t *testing.T) {
for _, actorsMetadata := range actors.EmbeddedBuiltinActorsMetadata {
if actorsMetadata.Network == string(types.NetworkNameButterfly) {
for _, actor := range actorsMetadata.Actors {
_, ok := MethodsMap[actor]
assert.False(t, ok)
}
}
}

assert.Nil(t, actors.SetNetworkBundle(int(types.NetworkButterfly)))
ReloadMethodsMap()
for _, actorsMetadata := range actors.EmbeddedBuiltinActorsMetadata {
if actorsMetadata.Network == string(types.NetworkNameButterfly) {
for name, actor := range actorsMetadata.Actors {
for _, actor := range actorsMetadata.Actors {
_, ok := MethodsMap[actor]
if skipEvmActor(name) {
assert.False(t, ok)
} else {
assert.True(t, ok)
}
assert.True(t, ok)
}
}
}
})
}

// 没有把 v10 actor注入,等注入后移除
func skipEvmActor(name string) bool {
if name == manifest.EamKey || name == manifest.EvmKey || name == manifest.EmbryoKey || name == manifest.EthAccountKey {
return true
}
return false
}
6 changes: 1 addition & 5 deletions venus-shared/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ func TestLoadBuiltinActors(t *testing.T) {
assert.Equal(t, actor, res)

_, ok2 := MethodsMap[actor]
if skipEvmActor(name) {
assert.False(t, ok2)
} else {
assert.True(t, ok2)
}
assert.True(t, ok2)
}
}
}
Expand Down

0 comments on commit 9ef2a65

Please sign in to comment.