Merge pull request #1461 from filecoin-project/fix/no-fatal-errors

dont  use fatal errors in the vm
This commit is contained in:
Whyrusleeping 2020-03-26 20:22:08 -07:00 committed by GitHub
commit bb7820cfd7
2 changed files with 9 additions and 12 deletions

View File

@ -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"
@ -29,10 +30,10 @@ 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.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
}

View File

@ -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
}