Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log more call context during errors #6918

Merged
merged 4 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions chain/vm/invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io"
"testing"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/network"

cbor "github.com/ipfs/go-ipld-cbor"
Expand Down Expand Up @@ -80,6 +82,30 @@ func (basicContract) InvokeSomething10(rt runtime2.Runtime, params *basicParams)
return nil
}

type basicRtMessage struct{}

var _ runtime2.Message = (*basicRtMessage)(nil)

func (*basicRtMessage) Caller() address.Address {
a, err := address.NewIDAddress(0)
if err != nil {
panic(err)
}
return a
}

func (*basicRtMessage) Receiver() address.Address {
a, err := address.NewIDAddress(1)
if err != nil {
panic(err)
}
return a
}

func (*basicRtMessage) ValueReceived() abi.TokenAmount {
return big.NewInt(0)
}

func TestInvokerBasic(t *testing.T) {
inv := ActorRegistry{}
code, err := inv.transform(basicContract{})
Expand All @@ -89,7 +115,7 @@ func TestInvokerBasic(t *testing.T) {
bParam, err := actors.SerializeParams(&basicParams{B: 1})
assert.NoError(t, err)

_, aerr := code[0](&Runtime{}, bParam)
_, aerr := code[0](&Runtime{Message: &basicRtMessage{}}, bParam)

assert.Equal(t, exitcode.ExitCode(1), aerrors.RetCode(aerr), "return code should be 1")
if aerrors.IsFatal(aerr) {
Expand All @@ -101,7 +127,7 @@ func TestInvokerBasic(t *testing.T) {
bParam, err := actors.SerializeParams(&basicParams{B: 2})
assert.NoError(t, err)

_, aerr := code[10](&Runtime{}, bParam)
_, aerr := code[10](&Runtime{Message: &basicRtMessage{}}, bParam)
assert.Equal(t, exitcode.ExitCode(12), aerrors.RetCode(aerr), "return code should be 12")
if aerrors.IsFatal(aerr) {
t.Fatal("err should not be fatal")
Expand All @@ -113,6 +139,7 @@ func TestInvokerBasic(t *testing.T) {
vm: &VM{ntwkVersion: func(ctx context.Context, epoch abi.ChainEpoch) network.Version {
return network.Version0
}},
Message: &basicRtMessage{},
}, []byte{99})
if aerrors.IsFatal(aerr) {
t.Fatal("err should not be fatal")
Expand All @@ -125,6 +152,7 @@ func TestInvokerBasic(t *testing.T) {
vm: &VM{ntwkVersion: func(ctx context.Context, epoch abi.ChainEpoch) network.Version {
return network.Version7
}},
Message: &basicRtMessage{},
}, []byte{99})
if aerrors.IsFatal(aerr) {
t.Fatal("err should not be fatal")
Expand Down
4 changes: 2 additions & 2 deletions chain/vm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (rt *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.Act
defer func() {
if r := recover(); r != nil {
if ar, ok := r.(aerrors.ActorError); ok {
log.Warnf("VM.Call failure: %+v", ar)
log.Warnf("VM.Call failure in call from: %s to %s: %+v", rt.Caller(), rt.Receiver(), ar)
aerr = ar
return
}
Expand Down Expand Up @@ -391,7 +391,7 @@ func (rt *Runtime) Send(to address.Address, method abi.MethodNum, m cbor.Marshal
if err.IsFatal() {
panic(err)
}
log.Warnf("vmctx send failed: to: %s, method: %d: ret: %d, err: %s", to, method, ret, err)
log.Warnf("vmctx send failed: from: %s to: %s, method: %d: err: %s", rt.Receiver(), to, method, err)
return err.RetCode()
}
_ = rt.chargeGasSafe(gasOnActorExec)
Expand Down