Merge pull request #1461 from filecoin-project/fix/no-fatal-errors
dont use fatal errors in the vm
This commit is contained in:
commit
bb7820cfd7
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/chain/actors"
|
"github.com/filecoin-project/lotus/chain/actors"
|
||||||
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
||||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||||
|
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
@ -29,10 +30,10 @@ func init() {
|
|||||||
var EmptyObjectCid cid.Cid
|
var EmptyObjectCid cid.Cid
|
||||||
|
|
||||||
// Creates account actors from only BLS/SECP256K1 addresses.
|
// 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)
|
addrID, err := rt.state.RegisterNewAddress(addr)
|
||||||
if err != nil {
|
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 {
|
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 {
|
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)
|
p, err := actors.SerializeParams(&addr)
|
||||||
if err != nil {
|
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
|
// call constructor on account
|
||||||
|
|
||||||
_, aerr = rt.internalSend(builtin.SystemActorAddr, addrID, builtin.MethodsAccount.Constructor, big.Zero(), p)
|
_, aerr = rt.internalSend(builtin.SystemActorAddr, addrID, builtin.MethodsAccount.Constructor, big.Zero(), p)
|
||||||
|
|
||||||
if aerr != nil {
|
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)
|
act, err = rt.state.GetActor(addrID)
|
||||||
if err != nil {
|
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
|
return act, nil
|
||||||
}
|
}
|
||||||
|
@ -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))
|
rt.ChargeGas(rt.Pricelist().OnMethodInvocation(msg.Value, msg.Method))
|
||||||
if aerr != nil {
|
|
||||||
return nil, aerr, rt
|
|
||||||
}
|
|
||||||
|
|
||||||
toActor, err := st.GetActor(msg.To)
|
toActor, err := st.GetActor(msg.To)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if xerrors.Is(err, init_.ErrAddressNotFound) {
|
if xerrors.Is(err, init_.ErrAddressNotFound) {
|
||||||
a, err := TryCreateAccountActor(ctx, rt, msg.To)
|
a, err := TryCreateAccountActor(rt, msg.To)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, aerrors.Absorb(err, 1, "could not create account"), rt
|
return nil, aerrors.Absorb(err, 1, "could not create account"), rt
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user