From 1b50be09af498944fffa9914ac1ae5b7cf9cb62d Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 26 Mar 2020 20:03:04 -0700 Subject: [PATCH 1/2] dont use fatal errors in the vm --- chain/vm/mkactor.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/chain/vm/mkactor.go b/chain/vm/mkactor.go index 632c5ff4a..ee4601b10 100644 --- a/chain/vm/mkactor.go +++ b/chain/vm/mkactor.go @@ -6,6 +6,7 @@ import ( "github.com/filecoin-project/lotus/chain/actors" "github.com/filecoin-project/specs-actors/actors/abi/big" "github.com/filecoin-project/specs-actors/actors/builtin" + "github.com/filecoin-project/specs-actors/actors/runtime/exitcode" "github.com/ipfs/go-cid" cbor "github.com/ipfs/go-ipld-cbor" @@ -32,7 +33,7 @@ var EmptyObjectCid cid.Cid func TryCreateAccountActor(ctx context.Context, rt *Runtime, addr address.Address) (*types.Actor, aerrors.ActorError) { addrID, err := rt.state.RegisterNewAddress(addr) if err != nil { - return nil, aerrors.Escalate(err, "registering actor address") + return nil, aerrors.Absorb(err, byte(exitcode.SysErrInternal), "registering actor address") } if err := rt.chargeGasSafe(PricelistByEpoch(rt.height).OnCreateActor()); err != nil { @@ -45,24 +46,23 @@ func TryCreateAccountActor(ctx context.Context, rt *Runtime, addr address.Addres } if err := rt.state.SetActor(addrID, act); err != nil { - return nil, aerrors.Escalate(err, "creating new actor failed") + return nil, aerrors.Absorb(err, byte(exitcode.SysErrInternal), "creating new actor failed") } p, err := actors.SerializeParams(&addr) if err != nil { - return nil, aerrors.Escalate(err, "registering actor address") + return nil, aerrors.Absorb(err, byte(exitcode.SysErrInternal), "registering actor address") } // call constructor on account _, aerr = rt.internalSend(builtin.SystemActorAddr, addrID, builtin.MethodsAccount.Constructor, big.Zero(), p) - if aerr != nil { - return nil, aerrors.Fatal("failed to invoke account constructor") + return nil, aerrors.Wrap(aerr, "failed to invoke account constructor") } act, err = rt.state.GetActor(addrID) if err != nil { - return nil, aerrors.Escalate(err, "loading newly created actor failed") + return nil, aerrors.Absorb(err, byte(exitcode.SysErrInternal), "loading newly created actor failed") } return act, nil } From 672956af5d0b64af3df1eaeaa8f48ba31632195b Mon Sep 17 00:00:00 2001 From: Jeromy Date: Thu, 26 Mar 2020 20:13:32 -0700 Subject: [PATCH 2/2] addressing review --- chain/vm/mkactor.go | 2 +- chain/vm/vm.go | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/chain/vm/mkactor.go b/chain/vm/mkactor.go index ee4601b10..9633a9baa 100644 --- a/chain/vm/mkactor.go +++ b/chain/vm/mkactor.go @@ -30,7 +30,7 @@ func init() { var EmptyObjectCid cid.Cid // Creates account actors from only BLS/SECP256K1 addresses. -func TryCreateAccountActor(ctx context.Context, rt *Runtime, addr address.Address) (*types.Actor, aerrors.ActorError) { +func TryCreateAccountActor(rt *Runtime, addr address.Address) (*types.Actor, aerrors.ActorError) { addrID, err := rt.state.RegisterNewAddress(addr) if err != nil { return nil, aerrors.Absorb(err, byte(exitcode.SysErrInternal), "registering actor address") diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 07b85a063..f7749ef15 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -210,15 +210,12 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime, }() } - aerr := rt.chargeGasSafe(rt.Pricelist().OnMethodInvocation(msg.Value, msg.Method)) - if aerr != nil { - return nil, aerr, rt - } + rt.ChargeGas(rt.Pricelist().OnMethodInvocation(msg.Value, msg.Method)) toActor, err := st.GetActor(msg.To) if err != nil { if xerrors.Is(err, init_.ErrAddressNotFound) { - a, err := TryCreateAccountActor(ctx, rt, msg.To) + a, err := TryCreateAccountActor(rt, msg.To) if err != nil { return nil, aerrors.Absorb(err, 1, "could not create account"), rt }