diff --git a/cmd/multisig.go b/cmd/multisig.go index d7549cc13c..23d3cb358e 100644 --- a/cmd/multisig.go +++ b/cmd/multisig.go @@ -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 { diff --git a/go.mod b/go.mod index fb7d99114a..ae14e0e373 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 03fa822065..af8b3b1785 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/vm/dispatch/dispatch.go b/pkg/vm/dispatch/dispatch.go index ae80c33957..393bc3456f 100644 --- a/pkg/vm/dispatch/dispatch.go +++ b/pkg/vm/dispatch/dispatch.go @@ -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`. diff --git a/venus-devtool/go.mod b/venus-devtool/go.mod index 319e0d75a4..fafc86e870 100644 --- a/venus-devtool/go.mod +++ b/venus-devtool/go.mod @@ -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 diff --git a/venus-devtool/go.sum b/venus-devtool/go.sum index 8e601d45f3..e8831d15e0 100644 --- a/venus-devtool/go.sum +++ b/venus-devtool/go.sum @@ -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= diff --git a/venus-shared/actors/builtin/registry.go b/venus-shared/actors/builtin/registry.go index 7a5b7b7db0..e80db3ef39 100644 --- a/venus-shared/actors/builtin/registry.go +++ b/venus-shared/actors/builtin/registry.go @@ -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" @@ -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 } @@ -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(), @@ -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") diff --git a/venus-shared/actors/builtin/registry.go.template b/venus-shared/actors/builtin/registry.go.template index 288605c98d..d3ef0d2187 100644 --- a/venus-shared/actors/builtin/registry.go.template +++ b/venus-shared/actors/builtin/registry.go.template @@ -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" @@ -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 } @@ -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, @@ -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") diff --git a/venus-shared/utils/method_map.go b/venus-shared/utils/method_map.go index 3365b3d13a..51993454a5 100644 --- a/venus-shared/utils/method_map.go +++ b/venus-shared/utils/method_map.go @@ -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" @@ -21,7 +18,6 @@ import ( ) type MethodMeta struct { - Num string Name string Params reflect.Type @@ -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)), @@ -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 }