Skip to content

Commit

Permalink
Do not retry 'cannot accuse empty batch' errors
Browse files Browse the repository at this point in the history
This prevents an infinite loop of trying to accuse an empty batch.

Also see #87
  • Loading branch information
schmir committed May 25, 2021
1 parent 1bcf8a3 commit b395fbc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion shuttermint/keyper/fx/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fx
import (
"encoding/gob"
"fmt"
"strings"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -152,7 +153,15 @@ type Accuse struct {
}

func (a Accuse) SendTX(caller *contract.Caller, auth *bind.TransactOpts) (*types.Transaction, error) {
return caller.KeyperSlasher.Accuse(auth, a.HalfStep, a.KeyperIndex)
tx, err := caller.KeyperSlasher.Accuse(auth, a.HalfStep, a.KeyperIndex)
// If we try to accuse an empty batch, we may have run into a fork. In an perfect world we
// would detect that and not try to run any actions that rely on obsolete information.
// Alas, we don't do that at the moment, but know for sure that we cannot accuse an empty
// batch, so there's no need to retry this action
if err != nil && strings.Contains(err.Error(), "cannot accuse empty batch") {
err = &NonRetriableError{Err: err}
}
return tx, err
}

func (a Accuse) String() string {
Expand Down
18 changes: 18 additions & 0 deletions shuttermint/keyper/fx/messagesender.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ type RemoteError struct {

var _ IRetriable = &RemoteError{}

type NonRetriableError struct {
Err error
}

func (*NonRetriableError) IsRetriable() bool {
return false
}

func (e *NonRetriableError) Error() string {
return e.Err.Error()
}

func (e *NonRetriableError) Unwrap() error {
return e.Err
}

var _ IRetriable = &NonRetriableError{}

// IsRetriable checks if we should retry an action that resulted in the given error.
func IsRetriable(err error) bool {
switch e := err.(type) {
Expand Down

0 comments on commit b395fbc

Please sign in to comment.