Skip to content

Commit

Permalink
chore: return compass errors processing messages
Browse files Browse the repository at this point in the history
  • Loading branch information
maharifu committed Sep 20, 2024
1 parent 04ec000 commit 28bd68c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
33 changes: 14 additions & 19 deletions chain/evm/compass.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,16 @@ func (t compass) uploadUserSmartContract(
return tx, valsetID, nil
}

func (t compass) SetErrorData(ctx context.Context, queueTypeName string, msgID uint64, errToProcess error) (bool, error) {
func (t compass) SetErrorData(
ctx context.Context,
queueTypeName string,
msgID uint64,
errToProcess error,
) error {
data := []byte(errToProcess.Error())

var jsonRpcErr rpc.DataError
if !errors.As(errToProcess, &jsonRpcErr) {
return false, t.paloma.SetErrorData(ctx, queueTypeName, msgID, []byte(errToProcess.Error()))
} else {
if errors.As(errToProcess, &jsonRpcErr) {
liblog.WithContext(ctx).WithFields(
log.Fields{
"queue-type-name": queueTypeName,
Expand All @@ -471,13 +476,10 @@ func (t compass) SetErrorData(ctx context.Context, queueTypeName string, msgID u
},
).Warn("smart contract returned an error")

err := t.paloma.SetErrorData(ctx, queueTypeName, msgID, []byte(jsonRpcErr.Error()))
if err != nil {
return false, err
}

return true, nil
data = []byte(jsonRpcErr.Error())
}

return t.paloma.SetErrorData(ctx, queueTypeName, msgID, data)
}

func (t compass) findLastValsetMessageID(ctx context.Context) (uint64, error) {
Expand Down Expand Up @@ -817,19 +819,12 @@ func (t compass) processMessages(ctx context.Context, queueTypeName string, msgs
default:
logger.WithError(processingErr).Error("processing error")

var isContractErr bool
var setErr error

if !opts.estimateOnly {
// If we're not just estimating, we want to set the error data
// on the message
isContractErr, setErr = t.SetErrorData(ctx, queueTypeName, rawMsg.ID, processingErr)
}

if setErr == nil && isContractErr {
// If it's a smart contract error we just ignore it, as we want
// to retry it
continue
setErr = t.SetErrorData(ctx, queueTypeName, rawMsg.ID, processingErr)
}

if setErr != nil {
Expand Down Expand Up @@ -1680,7 +1675,7 @@ func (t compass) getFeeArgs(

if userFunds.Cmp(totalFundsNeeded) < 0 {
err := fmt.Errorf("insufficient funds for fees: %s < %s", userFunds, totalFundsNeeded)
if _, sendErr := t.SetErrorData(ctx, queueTypeName, origMessage.ID, err); sendErr != nil {
if sendErr := t.SetErrorData(ctx, queueTypeName, origMessage.ID, err); sendErr != nil {
err = fmt.Errorf("failed to set error data: %w", sendErr)
}
return feeArgs, err
Expand Down
7 changes: 4 additions & 3 deletions chain/evm/compass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func TestIsArbitraryCallAlreadyExecuted(t *testing.T) {

func TestMessageProcessing(t *testing.T) {
dummyErr := whoops.String("dummy")
rpcErr := fakeJsonRpcError("bla")

addValidSignature := func(pk *ecdsa.PrivateKey) chain.ValidatorSignature {
return signMessage(ethCompatibleBytesToSign, pk)
Expand Down Expand Up @@ -1648,7 +1649,6 @@ func TestMessageProcessing(t *testing.T) {
},
setup: func(t *testing.T) (*mockEvmClienter, *evmmocks.PalomaClienter) {
evm, paloma := newMockEvmClienter(t), evmmocks.NewPalomaClienter(t)
fakeErr := fakeJsonRpcError("bla")

paloma.On("QueryGetEVMValsetByID", mock.Anything, uint64(0), "internal-chain-id").Return(
&types.Valset{
Expand All @@ -1658,11 +1658,12 @@ func TestMessageProcessing(t *testing.T) {
},
nil,
)
evm.On("DeployContract", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, fakeErr)
evm.On("DeployContract", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, rpcErr)
paloma.On("NewStatus").Return(&StatusUpdater{})
paloma.On("SetErrorData", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
return evm, paloma
},
expErr: nil,
expErr: rpcErr,
},
{
name: "upload_smart_contract/when smart contract returns an error and sending it to paloma fails, it returns it back",
Expand Down

0 comments on commit 28bd68c

Please sign in to comment.