Eliminate use of SysErrInternal, some interop changes
This commit is contained in:
parent
0f0589bcf5
commit
832657edfb
@ -33,7 +33,7 @@ type Pricelist interface {
|
||||
// OnDeleteActor returns the gas used for deleting an actor
|
||||
OnDeleteActor() int64
|
||||
|
||||
OnVerifySignature(sigType crypto.SigType, planTextSize int) int64
|
||||
OnVerifySignature(sigType crypto.SigType, planTextSize int) (int64, error)
|
||||
OnHashing(dataSize int) int64
|
||||
OnComputeUnsealedSectorCid(proofType abi.RegisteredProof, pieces []abi.PieceInfo) int64
|
||||
OnVerifySeal(info abi.SealVerifyInfo) int64
|
||||
@ -97,7 +97,11 @@ type pricedSyscalls struct {
|
||||
|
||||
// Verifies that a signature is valid for an address and plaintext.
|
||||
func (ps pricedSyscalls) VerifySignature(signature crypto.Signature, signer addr.Address, plaintext []byte) error {
|
||||
ps.chargeGas(ps.pl.OnVerifySignature(signature.Type, len(plaintext)))
|
||||
c, err := ps.pl.OnVerifySignature(signature.Type, len(plaintext))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ps.chargeGas(c)
|
||||
return ps.under.VerifySignature(signature, signer, plaintext)
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,10 @@
|
||||
package vm
|
||||
|
||||
import (
|
||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||
"fmt"
|
||||
"github.com/filecoin-project/specs-actors/actors/abi"
|
||||
"github.com/filecoin-project/specs-actors/actors/builtin"
|
||||
"github.com/filecoin-project/specs-actors/actors/crypto"
|
||||
"github.com/filecoin-project/specs-actors/actors/runtime/exitcode"
|
||||
)
|
||||
|
||||
type pricelistV0 struct {
|
||||
@ -127,12 +126,12 @@ func (pl *pricelistV0) OnDeleteActor() int64 {
|
||||
}
|
||||
|
||||
// OnVerifySignature
|
||||
func (pl *pricelistV0) OnVerifySignature(sigType crypto.SigType, planTextSize int) int64 {
|
||||
func (pl *pricelistV0) OnVerifySignature(sigType crypto.SigType, planTextSize int) (int64, error) {
|
||||
costFn, ok := pl.verifySignature[sigType]
|
||||
if !ok {
|
||||
panic(aerrors.Newf(exitcode.SysErrInternal, "Cost function for signature type %d not supported", sigType))
|
||||
return 0, fmt.Errorf("cost function for signature type %d not supported", sigType)
|
||||
}
|
||||
return costFn(int64(planTextSize))
|
||||
return costFn(int64(planTextSize)), nil
|
||||
}
|
||||
|
||||
// OnHashing
|
||||
|
@ -13,7 +13,6 @@ import (
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
"github.com/filecoin-project/lotus/chain/actors/aerrors"
|
||||
"github.com/filecoin-project/lotus/chain/state"
|
||||
"github.com/filecoin-project/lotus/chain/types"
|
||||
)
|
||||
|
||||
@ -33,25 +32,26 @@ var EmptyObjectCid cid.Cid
|
||||
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, exitcode.SysErrInternal, "registering actor address")
|
||||
return nil, aerrors.Escalate(err, "registering actor address")
|
||||
}
|
||||
|
||||
if err := rt.chargeGasSafe(PricelistByEpoch(rt.height).OnCreateActor()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
act, aerr := makeActor(rt.state, addr)
|
||||
act, aerr := makeActor(addr)
|
||||
if aerr != nil {
|
||||
return nil, aerr
|
||||
}
|
||||
|
||||
if err := rt.state.SetActor(addrID, act); err != nil {
|
||||
return nil, aerrors.Absorb(err, exitcode.SysErrInternal, "creating new actor failed")
|
||||
return nil, aerrors.Escalate(err, "creating new actor failed")
|
||||
}
|
||||
|
||||
p, err := actors.SerializeParams(&addr)
|
||||
if err != nil {
|
||||
return nil, aerrors.Absorb(err, exitcode.SysErrInternal, "registering actor address")
|
||||
// TODO: Unsure whether this should be fatal
|
||||
return nil, aerrors.Absorb(err, exitcode.SysErrInvalidParameters, "registering actor address")
|
||||
}
|
||||
// call constructor on account
|
||||
|
||||
@ -62,42 +62,42 @@ func TryCreateAccountActor(rt *Runtime, addr address.Address) (*types.Actor, aer
|
||||
|
||||
act, err = rt.state.GetActor(addrID)
|
||||
if err != nil {
|
||||
return nil, aerrors.Absorb(err, exitcode.SysErrInternal, "loading newly created actor failed")
|
||||
return nil, aerrors.Escalate(err, "loading newly created actor failed")
|
||||
}
|
||||
return act, nil
|
||||
}
|
||||
|
||||
func makeActor(st *state.StateTree, addr address.Address) (*types.Actor, aerrors.ActorError) {
|
||||
func makeActor(addr address.Address) (*types.Actor, aerrors.ActorError) {
|
||||
switch addr.Protocol() {
|
||||
case address.BLS:
|
||||
return NewBLSAccountActor()
|
||||
return NewBLSAccountActor(), nil
|
||||
case address.SECP256K1:
|
||||
return NewSecp256k1AccountActor()
|
||||
return NewSecp256k1AccountActor(), nil
|
||||
case address.ID:
|
||||
return nil, aerrors.Newf(1, "no actor with given ID: %s", addr)
|
||||
return nil, aerrors.Newf(exitcode.SysErrInvalidReceiver, "no actor with given ID: %s", addr)
|
||||
case address.Actor:
|
||||
return nil, aerrors.Newf(1, "no such actor: %s", addr)
|
||||
return nil, aerrors.Newf(exitcode.SysErrInvalidReceiver, "no such actor: %s", addr)
|
||||
default:
|
||||
return nil, aerrors.Newf(1, "address has unsupported protocol: %d", addr.Protocol())
|
||||
return nil, aerrors.Newf(exitcode.SysErrInvalidReceiver, "address has unsupported protocol: %d", addr.Protocol())
|
||||
}
|
||||
}
|
||||
|
||||
func NewBLSAccountActor() (*types.Actor, aerrors.ActorError) {
|
||||
func NewBLSAccountActor() *types.Actor {
|
||||
nact := &types.Actor{
|
||||
Code: builtin.AccountActorCodeID,
|
||||
Balance: types.NewInt(0),
|
||||
Head: EmptyObjectCid,
|
||||
}
|
||||
|
||||
return nact, nil
|
||||
return nact
|
||||
}
|
||||
|
||||
func NewSecp256k1AccountActor() (*types.Actor, aerrors.ActorError) {
|
||||
func NewSecp256k1AccountActor() *types.Actor {
|
||||
nact := &types.Actor{
|
||||
Code: builtin.AccountActorCodeID,
|
||||
Balance: types.NewInt(0),
|
||||
Head: EmptyObjectCid,
|
||||
}
|
||||
|
||||
return nact, nil
|
||||
return nact
|
||||
}
|
||||
|
@ -407,15 +407,19 @@ func (ssh *shimStateHandle) Create(obj vmr.CBORMarshaler) {
|
||||
func (ssh *shimStateHandle) Readonly(obj vmr.CBORUnmarshaler) {
|
||||
act, err := ssh.rs.state.GetActor(ssh.rs.Message().Receiver())
|
||||
if err != nil {
|
||||
ssh.rs.Abortf(exitcode.SysErrInternal, "failed to get actor for Readonly state: %s", err)
|
||||
ssh.rs.Abortf(exitcode.SysErrorIllegalArgument, "failed to get actor for Readonly state: %s", err)
|
||||
}
|
||||
ssh.rs.Get(act.Head, obj)
|
||||
}
|
||||
|
||||
func (ssh *shimStateHandle) Transaction(obj vmr.CBORer, f func() interface{}) interface{} {
|
||||
if obj == nil {
|
||||
ssh.rs.Abortf(exitcode.SysErrorIllegalActor, "Must not pass nil to Transaction()")
|
||||
}
|
||||
|
||||
act, err := ssh.rs.state.GetActor(ssh.rs.Message().Receiver())
|
||||
if err != nil {
|
||||
ssh.rs.Abortf(exitcode.SysErrInternal, "failed to get actor for Readonly state: %s", err)
|
||||
ssh.rs.Abortf(exitcode.SysErrorIllegalActor, "failed to get actor for Transaction: %s", err)
|
||||
}
|
||||
baseState := act.Head
|
||||
ssh.rs.Get(baseState, obj)
|
||||
@ -445,17 +449,17 @@ func (rt *Runtime) stateCommit(oldh, newh cid.Cid) aerrors.ActorError {
|
||||
// TODO: we can make this more efficient in the future...
|
||||
act, err := rt.state.GetActor(rt.Message().Receiver())
|
||||
if err != nil {
|
||||
rt.Abortf(exitcode.SysErrInternal, "failed to get actor to commit state: %s", err)
|
||||
return aerrors.Escalate(err, "failed to get actor to commit state")
|
||||
}
|
||||
|
||||
if act.Head != oldh {
|
||||
rt.Abortf(exitcode.ErrIllegalState, "failed to update, inconsistent base reference")
|
||||
return aerrors.Fatal("failed to update, inconsistent base reference")
|
||||
}
|
||||
|
||||
act.Head = newh
|
||||
|
||||
if err := rt.state.SetActor(rt.Message().Receiver(), act); err != nil {
|
||||
rt.Abortf(exitcode.SysErrInternal, "failed to set actor in commit state: %s", err)
|
||||
return aerrors.Fatalf("failed to set actor in commit state: %s", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -44,16 +44,16 @@ func ResolveToKeyAddr(state types.StateTree, cst cbor.IpldStore, addr address.Ad
|
||||
|
||||
act, err := state.GetActor(addr)
|
||||
if err != nil {
|
||||
return address.Undef, aerrors.Newf(exitcode.SysErrInternal, "failed to find actor: %s", addr)
|
||||
return address.Undef, aerrors.Newf(exitcode.SysErrInvalidParameters, "failed to find actor: %s", addr)
|
||||
}
|
||||
|
||||
if act.Code != builtin.AccountActorCodeID {
|
||||
return address.Undef, aerrors.Fatalf("address %s was not for an account actor", addr)
|
||||
return address.Undef, aerrors.Newf(exitcode.SysErrInvalidParameters, "address %s was not for an account actor", addr)
|
||||
}
|
||||
|
||||
var aast account.State
|
||||
if err := cst.Get(context.TODO(), act.Head, &aast); err != nil {
|
||||
return address.Undef, aerrors.Escalate(err, fmt.Sprintf("failed to get account actor state for %s", addr))
|
||||
return address.Undef, aerrors.Absorb(err, exitcode.SysErrInvalidParameters, fmt.Sprintf("failed to get account actor state for %s", addr))
|
||||
}
|
||||
|
||||
return aast.Address, nil
|
||||
|
Loading…
Reference in New Issue
Block a user