Skip to content

Commit

Permalink
Rename error parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dimriou committed Oct 16, 2023
1 parent 2234144 commit 2b800b2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
11 changes: 4 additions & 7 deletions common/client/multi_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type multiNode[
chStop utils.StopChan
wg sync.WaitGroup

sendOnlyErrorParser func(err error) (client.SendTxReturnCode, error)
sendOnlyErrorParser func(err error) client.SendTxReturnCode
}

func NewMultiNode[
Expand All @@ -146,7 +146,7 @@ func NewMultiNode[
chainID CHAIN_ID,
chainType config.ChainType,
chainFamily string,
sendOnlyErrorParser func(err error) (client.SendTxReturnCode, error),
sendOnlyErrorParser func(err error) client.SendTxReturnCode,
) MultiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OPS, TX_RECEIPT, FEE, HEAD, RPC_CLIENT] {
nodeSelector := func() NodeSelector[CHAIN_ID, HEAD, RPC_CLIENT] {
switch selectionMode {
Expand Down Expand Up @@ -603,13 +603,10 @@ func (c *multiNode[CHAIN_ID, SEQ, ADDR, BLOCK_HASH, TX, TX_HASH, EVENT, EVENT_OP

txErr := n.RPC().SendTransaction(ctx, tx)
c.logger.Debugw("Sendonly node sent transaction", "name", n.String(), "tx", tx, "err", txErr)
sendOnlyError, err := c.sendOnlyErrorParser(txErr)
sendOnlyError := c.sendOnlyErrorParser(txErr)
if sendOnlyError != client.Successful {
c.logger.Warnw("RPC returned error", "name", n.String(), "err", err, "tx", tx)
return
c.logger.Warnw("RPC returned error", "name", n.String(), "tx", tx, "err", txErr)
}

c.logger.Warnw("RPC returned error", "name", n.String(), "err", err, "tx", tx)
}(n)
})
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/client/chain_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewChainClient(
chainID,
chainType,
"EVM",
NewSendOnlyErrorReturnCode,
SendOnlyErrorParse,
)
return &chainClient{
multiNode: multiNode,
Expand Down Expand Up @@ -215,7 +215,7 @@ func (c *chainClient) SendTransaction(ctx context.Context, tx *types.Transaction

func (c *chainClient) SendTransactionReturnCode(ctx context.Context, tx *types.Transaction, fromAddress common.Address) (commontypes.SendTxReturnCode, error) {
err := c.SendTransaction(ctx, tx)
return NewSendErrorReturnCode(err, c.logger, tx, fromAddress, c.IsL2())
return SendErrorParse(err, c.logger, tx, fromAddress, c.IsL2())
}

func (c *chainClient) SequenceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (evmtypes.Nonce, error) {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (client *client) HeaderByHash(ctx context.Context, h common.Hash) (*types.H

func (client *client) SendTransactionReturnCode(ctx context.Context, tx *types.Transaction, fromAddress common.Address) (clienttypes.SendTxReturnCode, error) {
err := client.SendTransaction(ctx, tx)
return NewSendErrorReturnCode(err, client.logger, tx, fromAddress, client.pool.ChainType().IsL2())
return SendErrorParse(err, client.logger, tx, fromAddress, client.pool.ChainType().IsL2())
}

// SendTransaction also uses the sendonly HTTP RPC URLs if set
Expand Down
10 changes: 5 additions & 5 deletions core/chains/evm/client/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func ExtractRPCError(baseErr error) (*JsonError, error) {
return &jErr, nil
}

func NewSendErrorReturnCode(err error, lggr logger.Logger, tx *types.Transaction, fromAddress common.Address, isL2 bool) (clienttypes.SendTxReturnCode, error) {
func SendErrorParse(err error, lggr logger.Logger, tx *types.Transaction, fromAddress common.Address, isL2 bool) (clienttypes.SendTxReturnCode, error) {
sendError := NewSendError(err)
if sendError == nil {
return clienttypes.Successful, err
Expand Down Expand Up @@ -466,14 +466,14 @@ func NewSendErrorReturnCode(err error, lggr logger.Logger, tx *types.Transaction
return clienttypes.Unknown, err
}

// NewSendOnlyErrorReturnCode handles SendOnly nodes error codes. In that case, we don't assume there is another transaction that will be correctly
// SendOnlyErrorParse handles SendOnly nodes error codes. In that case, we don't assume there is another transaction that will be correctly
// priced.
func NewSendOnlyErrorReturnCode(err error) (clienttypes.SendTxReturnCode, error) {
func SendOnlyErrorParse(err error) clienttypes.SendTxReturnCode {
sendError := NewSendError(err)
if sendError == nil || sendError.IsNonceTooLowError() || sendError.IsTransactionAlreadyMined() || sendError.IsTransactionAlreadyInMempool() {
// Nonce too low or transaction known errors are expected since
// the primary SendTransaction may well have succeeded already
return clienttypes.Successful, err
return clienttypes.Successful
}
return clienttypes.Fatal, err
return clienttypes.Fatal
}
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *evmTxmClient) BatchSendTransactions(
processingErr[i] = fmt.Errorf("failed to process tx (index %d): %w", i, signedErr)
return
}
codes[i], txErrs[i] = evmclient.NewSendErrorReturnCode(reqs[i].Error, lggr, tx, attempts[i].Tx.FromAddress, c.client.IsL2())
codes[i], txErrs[i] = evmclient.SendErrorParse(reqs[i].Error, lggr, tx, attempts[i].Tx.FromAddress, c.client.IsL2())
}(index)
}
wg.Wait()
Expand Down

0 comments on commit 2b800b2

Please sign in to comment.