fix: actor method params deserialization error exit code
This commit is contained in:
parent
dff88b63b2
commit
ce9146916a
@ -6,6 +6,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
"github.com/filecoin-project/lotus/chain/actors/builtin"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
@ -173,9 +175,14 @@ func (*ActorRegistry) transform(instance invokee) (nativeCode, error) {
|
|||||||
paramT := meth.Type().In(1).Elem()
|
paramT := meth.Type().In(1).Elem()
|
||||||
param := reflect.New(paramT)
|
param := reflect.New(paramT)
|
||||||
|
|
||||||
|
rt := in[0].Interface().(*Runtime)
|
||||||
inBytes := in[1].Interface().([]byte)
|
inBytes := in[1].Interface().([]byte)
|
||||||
if err := DecodeParams(inBytes, param.Interface()); err != nil {
|
if err := DecodeParams(inBytes, param.Interface()); err != nil {
|
||||||
aerr := aerrors.Absorb(err, 1, "failed to decode parameters")
|
ec := exitcode.ErrSerialization
|
||||||
|
if rt.NetworkVersion() < network.Version7 {
|
||||||
|
ec = 1
|
||||||
|
}
|
||||||
|
aerr := aerrors.Absorb(err, ec, "failed to decode parameters")
|
||||||
return []reflect.Value{
|
return []reflect.Value{
|
||||||
reflect.ValueOf([]byte{}),
|
reflect.ValueOf([]byte{}),
|
||||||
// Below is a hack, fixed in Go 1.13
|
// Below is a hack, fixed in Go 1.13
|
||||||
@ -183,7 +190,6 @@ func (*ActorRegistry) transform(instance invokee) (nativeCode, error) {
|
|||||||
reflect.ValueOf(&aerr).Elem(),
|
reflect.ValueOf(&aerr).Elem(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rt := in[0].Interface().(*Runtime)
|
|
||||||
rval, aerror := rt.shimCall(func() interface{} {
|
rval, aerror := rt.shimCall(func() interface{} {
|
||||||
ret := meth.Call([]reflect.Value{
|
ret := meth.Call([]reflect.Value{
|
||||||
reflect.ValueOf(rt),
|
reflect.ValueOf(rt),
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-state-types/network"
|
||||||
|
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
cbg "github.com/whyrusleeping/cbor-gen"
|
cbg "github.com/whyrusleeping/cbor-gen"
|
||||||
@ -105,10 +108,27 @@ func TestInvokerBasic(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, aerr := code[1](&Runtime{}, []byte{99})
|
{
|
||||||
|
_, aerr := code[1](&Runtime{
|
||||||
|
vm: &VM{ntwkVersion: func(ctx context.Context, epoch abi.ChainEpoch) network.Version {
|
||||||
|
return network.Version0
|
||||||
|
}},
|
||||||
|
}, []byte{99})
|
||||||
if aerrors.IsFatal(aerr) {
|
if aerrors.IsFatal(aerr) {
|
||||||
t.Fatal("err should not be fatal")
|
t.Fatal("err should not be fatal")
|
||||||
}
|
}
|
||||||
assert.Equal(t, exitcode.ExitCode(1), aerrors.RetCode(aerr), "return code should be 1")
|
assert.Equal(t, exitcode.ExitCode(1), aerrors.RetCode(aerr), "return code should be 1")
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
_, aerr := code[1](&Runtime{
|
||||||
|
vm: &VM{ntwkVersion: func(ctx context.Context, epoch abi.ChainEpoch) network.Version {
|
||||||
|
return network.Version7
|
||||||
|
}},
|
||||||
|
}, []byte{99})
|
||||||
|
if aerrors.IsFatal(aerr) {
|
||||||
|
t.Fatal("err should not be fatal")
|
||||||
|
}
|
||||||
|
assert.Equal(t, exitcode.ErrSerialization, aerrors.RetCode(aerr), "return code should be %s", 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,20 +244,23 @@ func (rt *Runtime) NewActorAddress() address.Address {
|
|||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rt *Runtime) CreateActor(codeID cid.Cid, address address.Address) {
|
func (rt *Runtime) CreateActor(codeID cid.Cid, addr address.Address) {
|
||||||
|
if addr == address.Undef && rt.NetworkVersion() >= network.Version7 {
|
||||||
|
rt.Abortf(exitcode.SysErrorIllegalArgument, "CreateActor with Undef address")
|
||||||
|
}
|
||||||
act, aerr := rt.vm.areg.Create(codeID, rt)
|
act, aerr := rt.vm.areg.Create(codeID, rt)
|
||||||
if aerr != nil {
|
if aerr != nil {
|
||||||
rt.Abortf(aerr.RetCode(), aerr.Error())
|
rt.Abortf(aerr.RetCode(), aerr.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := rt.state.GetActor(address)
|
_, err := rt.state.GetActor(addr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
rt.Abortf(exitcode.SysErrorIllegalArgument, "Actor address already exists")
|
rt.Abortf(exitcode.SysErrorIllegalArgument, "Actor address already exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
rt.chargeGas(rt.Pricelist().OnCreateActor())
|
rt.chargeGas(rt.Pricelist().OnCreateActor())
|
||||||
|
|
||||||
err = rt.state.SetActor(address, act)
|
err = rt.state.SetActor(addr, act)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(aerrors.Fatalf("creating actor entry: %v", err))
|
panic(aerrors.Fatalf("creating actor entry: %v", err))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user