Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use MethodMeta from go-state-types #5397

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ var msigInspectCmd = &cmds.Command{
}
paramStr = string(b)
}
fmt.Fprintf(w, "%d\t%s\t%d\t%s\t%s\t%s(%d)\t%s\n", txid, "pending", len(tx.Approved), target, types.FIL(tx.Value), method.Num, tx.Method, paramStr)
fmt.Fprintf(w, "%d\t%s\t%d\t%s\t%s\t%s(%d)\t%s\n", txid, "pending", len(tx.Approved), target, types.FIL(tx.Value), method.Name, tx.Method, paramStr)
}
}
if err := w.Flush(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/filecoin-project/go-fil-markets v1.24.0-v17
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.9.1
github.com/filecoin-project/go-state-types v0.9.2
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 @@ -343,8 +343,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.9.1 h1:Dr++Hy+tm8RC5jLQBPfFIvThPCa6uEJ4NwlCWh3V85Q=
github.com/filecoin-project/go-state-types v0.9.1/go.mod h1:+HCZifUV+e8TlQkgll22Ucuiq8OrVJkK+4Kh4u75iiw=
github.com/filecoin-project/go-state-types v0.9.2 h1:zbhib/addhqVihN7yZPkBMvkpS6v5PQFtBllDIxdUS4=
github.com/filecoin-project/go-state-types v0.9.2/go.mod h1:+HCZifUV+e8TlQkgll22Ucuiq8OrVJkK+4Kh4u75iiw=
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
9 changes: 4 additions & 5 deletions pkg/vm/dispatch/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,13 @@ func (d *actorDispatcher) Dispatch(methodNum abi.MethodNum, nvk network.Version,
func (d *actorDispatcher) signature(methodID abi.MethodNum) (*methodSignature, *ExcuteError) {
exports := d.actor.Exports()

// get method entry
entry := exports[(uint64)(methodID)]
if entry == nil {
// get method
method := exports[(uint64)(methodID)].Method
if method == nil {
return nil, NewExcuteError(exitcode.SysErrInvalidMethod, "Method undefined. method: %d, code: %s", methodID, d.code)
}

ventry := reflect.ValueOf(entry)
return &methodSignature{method: ventry}, nil
return &methodSignature{method: reflect.ValueOf(method)}, nil
}

// Signature implements `Dispatcher`.
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.24.1-rc1
github.com/filecoin-project/go-jsonrpc v0.1.8
github.com/filecoin-project/go-state-types v0.9.1
github.com/filecoin-project/lotus v1.18.0-rc2
github.com/filecoin-project/go-state-types v0.9.2
github.com/filecoin-project/lotus v1.18.0-rc3.0.20221019204926-84050170b922
github.com/filecoin-project/venus v0.0.0-00010101000000-000000000000
github.com/ipfs/go-block-format v0.0.3
github.com/ipfs/go-cid v0.2.0
Expand Down
8 changes: 4 additions & 4 deletions venus-devtool/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,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.9.1 h1:Dr++Hy+tm8RC5jLQBPfFIvThPCa6uEJ4NwlCWh3V85Q=
github.com/filecoin-project/go-state-types v0.9.1/go.mod h1:+HCZifUV+e8TlQkgll22Ucuiq8OrVJkK+4Kh4u75iiw=
github.com/filecoin-project/go-state-types v0.9.2 h1:zbhib/addhqVihN7yZPkBMvkpS6v5PQFtBllDIxdUS4=
github.com/filecoin-project/go-state-types v0.9.2/go.mod h1:+HCZifUV+e8TlQkgll22Ucuiq8OrVJkK+4Kh4u75iiw=
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.8.1 h1:ggoBWvMSWR91HZQCWfv8SZjoTGNyJBwNMLuN9bJZrbU=
github.com/filecoin-project/lotus v1.18.0-rc2 h1:Cl71y/aOL/SSlYRKMvC/NhdEeShc+qhfJuWrIz2n6ps=
github.com/filecoin-project/lotus v1.18.0-rc2/go.mod h1:DdCQv+QB/XIGCOMsCf58Agyyta+/c1Du8hy5JKkxQKY=
github.com/filecoin-project/lotus v1.18.0-rc3.0.20221019204926-84050170b922 h1:kI8N7+iIqpfOjhImNaZJT6MHIB66NcK6qQteNF8E8t8=
github.com/filecoin-project/lotus v1.18.0-rc3.0.20221019204926-84050170b922/go.mod h1:/kWfuN/hzqOvdzbYxaBrvN82HAQ85nRMli7KcnoSE6E=
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
30 changes: 26 additions & 4 deletions venus-shared/actors/builtin/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
package builtin

import (
"reflect"
"runtime"
"strings"

actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/ipfs/go-cid"

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

account8 "github.com/filecoin-project/go-state-types/builtin/v8/account"
cron8 "github.com/filecoin-project/go-state-types/builtin/v8/cron"
_init8 "github.com/filecoin-project/go-state-types/builtin/v8/init"
Expand Down Expand Up @@ -40,14 +46,14 @@ import (
type RegistryEntry struct {
state cbor.Er
code cid.Cid
methods map[uint64]interface{}
methods map[uint64]builtin.MethodMeta
}

func (r RegistryEntry) State() cbor.Er {
return r.state
}

func (r RegistryEntry) Exports() map[uint64]interface{} {
func (r RegistryEntry) Exports() map[uint64]builtin.MethodMeta {
return r.methods
}

Expand All @@ -59,9 +65,11 @@ func MakeRegistryLegacy(actors []rtt.VMActor) []RegistryEntry {
registry := make([]RegistryEntry, 0)

for _, actor := range actors {
methodMap := make(map[uint64]interface{})
methodMap := make(map[uint64]builtin.MethodMeta)
for methodNum, method := range actor.Exports() {
methodMap[uint64(methodNum)] = method
if method != nil {
methodMap[uint64(methodNum)] = makeMethodMeta(method)
}
}
registry = append(registry, RegistryEntry{
code: actor.Code(),
Expand All @@ -73,6 +81,20 @@ func MakeRegistryLegacy(actors []rtt.VMActor) []RegistryEntry {
return registry
}

func makeMethodMeta(method interface{}) builtin.MethodMeta {
ev := reflect.ValueOf(method)
// Extract the method names using reflection. These
// method names always match the field names in the
// `builtin.Method*` structs (tested in the specs-actors
// tests).
fnName := runtime.FuncForPC(ev.Pointer()).Name()
fnName = strings.TrimSuffix(fnName[strings.LastIndexByte(fnName, '.')+1:], "-fm")
return builtin.MethodMeta{
Name: fnName,
Method: method,
}
}

func MakeRegistry(av actorstypes.Version) []RegistryEntry {
if av < actorstypes.Version8 {
panic("expected version v8 and up only, use specs-actors for v0-7")
Expand Down
31 changes: 26 additions & 5 deletions venus-shared/actors/builtin/registry.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ package builtin
import (
actorstypes "github.com/filecoin-project/go-state-types/actors"
"github.com/ipfs/go-cid"
"reflect"
"runtime"
"strings"

"github.com/filecoin-project/go-state-types/builtin"
{{range .versions}}
{{if (ge . 8)}}
account{{.}} "github.com/filecoin-project/go-state-types/builtin/v{{.}}/account"
Expand All @@ -31,14 +36,14 @@ import (
type RegistryEntry struct {
state cbor.Er
code cid.Cid
methods map[uint64]interface{}
methods map[uint64]builtin.MethodMeta
}

func (r RegistryEntry) State() cbor.Er {
return r.state
}

func (r RegistryEntry) Exports() map[uint64]interface{} {
func (r RegistryEntry) Exports() map[uint64]builtin.MethodMeta {
return r.methods
}

Expand All @@ -50,10 +55,12 @@ func MakeRegistryLegacy(actors []rtt.VMActor) []RegistryEntry {
registry := make([]RegistryEntry, 0)

for _, actor := range actors {
methodMap := make(map[uint64]interface{})
methodMap := make(map[uint64]builtin.MethodMeta)
for methodNum, method := range actor.Exports() {
methodMap[uint64(methodNum)] = method
}
if method != nil {
methodMap[uint64(methodNum)] = makeMethodMeta(method)
}
}
registry = append(registry, RegistryEntry{
code: actor.Code(),
methods: methodMap,
Expand All @@ -64,6 +71,20 @@ func MakeRegistryLegacy(actors []rtt.VMActor) []RegistryEntry {
return registry
}

func makeMethodMeta(method interface{}) builtin.MethodMeta {
ev := reflect.ValueOf(method)
// Extract the method names using reflection. These
// method names always match the field names in the
// `builtin.Method*` structs (tested in the specs-actors
// tests).
fnName := runtime.FuncForPC(ev.Pointer()).Name()
fnName = strings.TrimSuffix(fnName[strings.LastIndexByte(fnName, '.')+1:], "-fm")
return builtin.MethodMeta{
Name: fnName,
Method: method,
}
}

func MakeRegistry(av actorstypes.Version) []RegistryEntry {
if av < actorstypes.Version8 {
panic("expected version v8 and up only, use specs-actors for v0-7")
Expand Down
40 changes: 11 additions & 29 deletions venus-shared/utils/method_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package utils

import (
"reflect"
"runtime"
"strconv"
"strings"

"github.com/filecoin-project/go-state-types/abi"
actorstypes "github.com/filecoin-project/go-state-types/actors"
Expand All @@ -21,7 +18,6 @@ import (
)

type MethodMeta struct {
Num string
Name string

Params reflect.Type
Expand Down Expand Up @@ -77,7 +73,6 @@ func loadMethodsMap() {

// Explicitly add send, it's special.
methods[builtin.MethodSend] = MethodMeta{
Num: "0",
Name: "Send",
Params: reflect.TypeOf(new(abi.EmptyValue)),
Ret: reflect.TypeOf(new(abi.EmptyValue)),
Expand All @@ -86,39 +81,26 @@ func loadMethodsMap() {
// Iterate over exported methods. Some of these _may_ be nil and
// must be skipped.
for number, export := range exports {
if export == nil {
if export.Method == nil {
continue
}

ev := reflect.ValueOf(export)
ev := reflect.ValueOf(export.Method)
et := ev.Type()

methodMeta := MethodMeta{
Num: strconv.Itoa(int(number)),
Params: et.In(1),
Ret: et.Out(0),
Name: export.Name,
Ret: et.Out(0),
}

// if actor version grater than Version8, we could not get method name.
// venus-wallet need `fnName`
if awv.av < actorstypes.Version8 {
// Extract the method names using reflection. These
// method names always match the field names in the
// `builtin.Method*` structs (tested in the specs-actors
// tests).
fnName := runtime.FuncForPC(ev.Pointer()).Name()
fnName = strings.TrimSuffix(fnName[strings.LastIndexByte(fnName, '.')+1:], "-fm")

switch abi.MethodNum(number) {
case builtin.MethodSend:
panic("method 0 is reserved for Send")
case builtin.MethodConstructor:
if fnName != "Constructor" {
panic("method 1 is reserved for Constructor")
}
}
methodMeta.Name = fnName
if awv.av <= actorstypes.Version7 {
// methods exported from specs-actors have the runtime as the first param, so we want et.In(1)
methodMeta.Params = et.In(1)
} else {
// methods exported from go-state-types do not, so we want et.In(0)
methodMeta.Params = et.In(0)
}

methods[abi.MethodNum(number)] = methodMeta
}

Expand Down