a few more fixes
This commit is contained in:
parent
cf2eefdfbe
commit
1a07cb7bbf
@ -12,6 +12,7 @@ import (
|
|||||||
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
|
init_ "github.com/filecoin-project/specs-actors/actors/builtin/init"
|
||||||
"github.com/filecoin-project/specs-actors/actors/runtime"
|
"github.com/filecoin-project/specs-actors/actors/runtime"
|
||||||
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
"github.com/filecoin-project/specs-actors/actors/util/adt"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
@ -57,7 +58,7 @@ func (tas *testActorState) UnmarshalCBOR(r io.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if t != cbg.MajUnsignedInt {
|
if t != cbg.MajUnsignedInt {
|
||||||
return fmt.Errorf("wrong type in test actor state")
|
return fmt.Errorf("wrong type in test actor state (got %d)", t)
|
||||||
}
|
}
|
||||||
tas.HasUpgraded = v
|
tas.HasUpgraded = v
|
||||||
return nil
|
return nil
|
||||||
@ -70,38 +71,29 @@ func (ta *testActor) Exports() []interface{} {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ta *testActor) Constructor(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) {
|
func (ta *testActor) Constructor(rt runtime.Runtime, params *adt.EmptyValue) *adt.EmptyValue {
|
||||||
c, err := vmctx.Storage().Put(&testActorState{11})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
empty, err := vmctx.Storage().Put(&adt.EmptyValue{})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Println("NEW ACTOR ADDRESS IS: ", vmctx.Message().To.String())
|
rt.State().Create(&testActorState{11})
|
||||||
|
fmt.Println("NEW ACTOR ADDRESS IS: ", rt.Message().Receiver())
|
||||||
|
|
||||||
return nil, vmctx.Storage().Commit(empty, c)
|
return &adt.EmptyValue{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ta *testActor) TestMethod(act *types.Actor, vmctx types.VMContext, params *struct{}) ([]byte, aerrors.ActorError) {
|
func (ta *testActor) TestMethod(rt runtime.Runtime, params *adt.EmptyValue) *adt.EmptyValue {
|
||||||
var st testActorState
|
var st testActorState
|
||||||
if err := vmctx.Storage().Get(vmctx.Storage().GetHead(), &st); err != nil {
|
rt.State().Readonly(&st)
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if vmctx.BlockHeight() > testForkHeight {
|
if rt.CurrEpoch() > testForkHeight {
|
||||||
if st.HasUpgraded != 55 {
|
if st.HasUpgraded != 55 {
|
||||||
return nil, aerrors.Fatal("fork updating applied in wrong order")
|
panic(aerrors.Fatal("fork updating applied in wrong order"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if st.HasUpgraded != 11 {
|
if st.HasUpgraded != 11 {
|
||||||
return nil, aerrors.Fatal("fork updating happened too early")
|
panic(aerrors.Fatal("fork updating happened too early"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return &adt.EmptyValue{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestForkHeightTriggers(t *testing.T) {
|
func TestForkHeightTriggers(t *testing.T) {
|
||||||
@ -125,7 +117,7 @@ func TestForkHeightTriggers(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// predicting the address here... may break if other assumptions change
|
// predicting the address here... may break if other assumptions change
|
||||||
taddr, err := address.NewIDAddress(1000)
|
taddr, err := address.NewIDAddress(1002)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -144,7 +136,7 @@ func TestForkHeightTriggers(t *testing.T) {
|
|||||||
|
|
||||||
var tas testActorState
|
var tas testActorState
|
||||||
if err := cst.Get(ctx, act.Head, &tas); err != nil {
|
if err := cst.Get(ctx, act.Head, &tas); err != nil {
|
||||||
return cid.Undef, err
|
return cid.Undef, xerrors.Errorf("in fork handler, failed to run get: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tas.HasUpgraded = 55
|
tas.HasUpgraded = 55
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
@ -89,17 +88,7 @@ type Invokee interface {
|
|||||||
var tVMContext = reflect.TypeOf((*types.VMContext)(nil)).Elem()
|
var tVMContext = reflect.TypeOf((*types.VMContext)(nil)).Elem()
|
||||||
var tAError = reflect.TypeOf((*aerrors.ActorError)(nil)).Elem()
|
var tAError = reflect.TypeOf((*aerrors.ActorError)(nil)).Elem()
|
||||||
|
|
||||||
func (i *invoker) transform(instance Invokee) (nativeCode, error) {
|
func (*invoker) transform(instance Invokee) (nativeCode, error) {
|
||||||
itype := reflect.TypeOf(instance)
|
|
||||||
if strings.Contains(itype.PkgPath(), "github.com/filecoin-project/specs-actors/") {
|
|
||||||
return i.transformSpec(instance)
|
|
||||||
} else {
|
|
||||||
return i.transformLotus(instance)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (*invoker) transformSpec(instance Invokee) (nativeCode, error) {
|
|
||||||
itype := reflect.TypeOf(instance)
|
itype := reflect.TypeOf(instance)
|
||||||
exports := instance.Exports()
|
exports := instance.Exports()
|
||||||
for i, m := range exports {
|
for i, m := range exports {
|
||||||
@ -178,81 +167,6 @@ func (*invoker) transformSpec(instance Invokee) (nativeCode, error) {
|
|||||||
return code, nil
|
return code, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*invoker) transformLotus(instance Invokee) (nativeCode, error) {
|
|
||||||
itype := reflect.TypeOf(instance)
|
|
||||||
exports := instance.Exports()
|
|
||||||
for i, m := range exports {
|
|
||||||
i := i
|
|
||||||
newErr := func(format string, args ...interface{}) error {
|
|
||||||
str := fmt.Sprintf(format, args...)
|
|
||||||
return fmt.Errorf("transform(%s) export(%d): %s", itype.Name(), i, str)
|
|
||||||
}
|
|
||||||
if m == nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
meth := reflect.ValueOf(m)
|
|
||||||
t := meth.Type()
|
|
||||||
if t.Kind() != reflect.Func {
|
|
||||||
return nil, newErr("is not a function")
|
|
||||||
}
|
|
||||||
if t.NumIn() != 3 {
|
|
||||||
return nil, newErr("wrong number of inputs should be: " +
|
|
||||||
"*types.Actor, *VMContext, <type of parameter>")
|
|
||||||
}
|
|
||||||
if t.In(0) != reflect.TypeOf(&types.Actor{}) {
|
|
||||||
return nil, newErr("first arguemnt should be *types.Actor")
|
|
||||||
}
|
|
||||||
if t.In(1) != tVMContext {
|
|
||||||
return nil, newErr("second argument should be types.VMContext")
|
|
||||||
}
|
|
||||||
|
|
||||||
if t.In(2).Kind() != reflect.Ptr {
|
|
||||||
return nil, newErr("parameter has to be a pointer to parameter, is: %s",
|
|
||||||
t.In(2).Kind())
|
|
||||||
}
|
|
||||||
|
|
||||||
if t.NumOut() != 2 {
|
|
||||||
return nil, newErr("wrong number of outputs should be: " +
|
|
||||||
"(InvokeRet, error)")
|
|
||||||
}
|
|
||||||
if t.Out(0) != reflect.TypeOf([]byte{}) {
|
|
||||||
return nil, newErr("first output should be slice of bytes")
|
|
||||||
}
|
|
||||||
if !t.Out(1).Implements(tAError) {
|
|
||||||
return nil, newErr("second output should be ActorError type")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
code := make(nativeCode, len(exports))
|
|
||||||
for id, m := range exports {
|
|
||||||
meth := reflect.ValueOf(m)
|
|
||||||
code[id] = reflect.MakeFunc(reflect.TypeOf((invokeFunc)(nil)),
|
|
||||||
func(in []reflect.Value) []reflect.Value {
|
|
||||||
paramT := meth.Type().In(2).Elem()
|
|
||||||
param := reflect.New(paramT)
|
|
||||||
|
|
||||||
inBytes := in[2].Interface().([]byte)
|
|
||||||
if len(inBytes) > 0 {
|
|
||||||
if err := DecodeParams(inBytes, param.Interface()); err != nil {
|
|
||||||
aerr := aerrors.Absorb(err, 1, "failed to decode parameters")
|
|
||||||
return []reflect.Value{
|
|
||||||
reflect.ValueOf([]byte{}),
|
|
||||||
// Below is a hack, fixed in Go 1.13
|
|
||||||
// https://git.io/fjXU6
|
|
||||||
reflect.ValueOf(&aerr).Elem(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return meth.Call([]reflect.Value{
|
|
||||||
in[0], in[1], param,
|
|
||||||
})
|
|
||||||
}).Interface().(invokeFunc)
|
|
||||||
|
|
||||||
}
|
|
||||||
return code, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func DecodeParams(b []byte, out interface{}) error {
|
func DecodeParams(b []byte, out interface{}) error {
|
||||||
um, ok := out.(cbg.CBORUnmarshaler)
|
um, ok := out.(cbg.CBORUnmarshaler)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
6
go.mod
6
go.mod
@ -23,7 +23,7 @@ require (
|
|||||||
github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663
|
github.com/filecoin-project/go-paramfetch v0.0.2-0.20200218225740-47c639bab663
|
||||||
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200228181617-f00e2c4cc050
|
github.com/filecoin-project/go-sectorbuilder v0.0.2-0.20200228181617-f00e2c4cc050
|
||||||
github.com/filecoin-project/go-statestore v0.1.0
|
github.com/filecoin-project/go-statestore v0.1.0
|
||||||
github.com/filecoin-project/specs-actors v0.0.0-20200228215954-2c5be7cfad99
|
github.com/filecoin-project/specs-actors v0.0.0-20200229011003-1d726e3afd04
|
||||||
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1
|
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1
|
||||||
github.com/go-ole/go-ole v1.2.4 // indirect
|
github.com/go-ole/go-ole v1.2.4 // indirect
|
||||||
github.com/google/uuid v1.1.1
|
github.com/google/uuid v1.1.1
|
||||||
@ -114,7 +114,3 @@ require (
|
|||||||
replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v1.18.0
|
replace github.com/golangci/golangci-lint => github.com/golangci/golangci-lint v1.18.0
|
||||||
|
|
||||||
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
|
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi
|
||||||
|
|
||||||
replace github.com/filecoin-project/specs-actors => ../specs-actors
|
|
||||||
|
|
||||||
replace github.com/filecoin-project/go-fil-markets => ../go-fil-markets
|
|
||||||
|
6
go.sum
6
go.sum
@ -99,6 +99,7 @@ github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGj
|
|||||||
github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E=
|
github.com/fd/go-nat v1.0.0/go.mod h1:BTBu/CKvMmOMUPkKVef1pngt2WFH/lg7E6yQnulfp6E=
|
||||||
github.com/filecoin-project/chain-validation v0.0.3 h1:luT/8kJ0WdMIqQ9Bm31W4JkuYCW0wUb26AvnD4WK59M=
|
github.com/filecoin-project/chain-validation v0.0.3 h1:luT/8kJ0WdMIqQ9Bm31W4JkuYCW0wUb26AvnD4WK59M=
|
||||||
github.com/filecoin-project/chain-validation v0.0.3/go.mod h1:NCEGFjcWRjb8akWFSOXvU6n2efkWIqAeOKU6o5WBGQw=
|
github.com/filecoin-project/chain-validation v0.0.3/go.mod h1:NCEGFjcWRjb8akWFSOXvU6n2efkWIqAeOKU6o5WBGQw=
|
||||||
|
github.com/filecoin-project/go-address v0.0.0-20200107215422-da8eea2842b5/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
|
||||||
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be h1:TooKBwR/g8jG0hZ3lqe9S5sy2vTUcLOZLlz3M5wGn2E=
|
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be h1:TooKBwR/g8jG0hZ3lqe9S5sy2vTUcLOZLlz3M5wGn2E=
|
||||||
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
|
github.com/filecoin-project/go-address v0.0.2-0.20200218010043-eb9bb40ed5be/go.mod h1:SAOwJoakQ8EPjwNIsiakIQKsoKdkcbx8U3IapgCg9R0=
|
||||||
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e h1:IOoff6yAZSJ5zHCPY2jzGNwQYQU6ygsRVe/cSnJrY+o=
|
github.com/filecoin-project/go-amt-ipld/v2 v2.0.1-0.20200131012142-05d80eeccc5e h1:IOoff6yAZSJ5zHCPY2jzGNwQYQU6ygsRVe/cSnJrY+o=
|
||||||
@ -125,6 +126,11 @@ github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9 h
|
|||||||
github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
|
github.com/filecoin-project/go-statemachine v0.0.0-20200226041606-2074af6d51d9/go.mod h1:FGwQgZAt2Gh5mjlwJUlVB62JeYdo+if0xWxSEfBD9ig=
|
||||||
github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ=
|
github.com/filecoin-project/go-statestore v0.1.0 h1:t56reH59843TwXHkMcwyuayStBIiWBRilQjQ+5IiwdQ=
|
||||||
github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI=
|
github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI=
|
||||||
|
github.com/filecoin-project/specs-actors v0.0.0-20200210130641-2d1fbd8672cf/go.mod h1:xtDZUB6pe4Pksa/bAJbJ693OilaC5Wbot9jMhLm3cZA=
|
||||||
|
github.com/filecoin-project/specs-actors v0.0.0-20200226200336-94c9b92b2775/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||||
|
github.com/filecoin-project/specs-actors v0.0.0-20200228215954-2c5be7cfad99/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||||
|
github.com/filecoin-project/specs-actors v0.0.0-20200229011003-1d726e3afd04 h1:O343OeQLkLWLj5ZqQ5nhevAGBTeB5LioiA53ddScqdY=
|
||||||
|
github.com/filecoin-project/specs-actors v0.0.0-20200229011003-1d726e3afd04/go.mod h1:0HAWYrvajFHDgRaKbF0rl+IybVLZL5z4gQ8koCMPhoU=
|
||||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 h1:EzDjxMg43q1tA2c0MV3tNbaontnHLplHyFF6M5KiVP0=
|
github.com/gbrlsnchs/jwt/v3 v3.0.0-beta.1 h1:EzDjxMg43q1tA2c0MV3tNbaontnHLplHyFF6M5KiVP0=
|
||||||
|
Loading…
Reference in New Issue
Block a user