Skip to content
Open
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
2 changes: 1 addition & 1 deletion internal/data/models.sqlc.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions internal/metrics/tx_mapper_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"math"
"strings"
"sync"
"time"

Expand All @@ -31,6 +32,8 @@ import (

const ReceiptWaitTimeout = 1 * time.Hour

var errSendTransaction = errors.New("send transaction failed")

type TxMapperDB struct {
db *pgxpool.Pool
dbQuery *data.Queries
Expand Down Expand Up @@ -117,8 +120,8 @@ func (tm *TxMapperDB) AddDecryptionKeysAndMessages(
if err != nil {
return err
}
if len(decryptionKeyIDs) == 0 {
log.Debug().Msg("no decryption key was added")
if len(decryptionKeyIDs) == 0 || len(decryptionKeyIDs) != len(slots) {
log.Debug().Msg("no new decryption key was added")
return nil
}
err = qtx.CreateDecryptionKeyMessages(ctx, data.CreateDecryptionKeyMessagesParams{
Expand Down Expand Up @@ -458,18 +461,22 @@ func (tm *TxMapperDB) processTransactionExecution(
return
}
} else {
txStatus := data.TxStatusValInvalid
if isFeeTooLowError(err) {
txStatus = data.TxStatusValInvalidfeetoolow
}
err := tm.dbQuery.CreateDecryptedTX(ctx, data.CreateDecryptedTXParams{
Slot: slot,
TxIndex: txSubEvent.TxIndex,
TxHash: decryptedTx.Hash().Bytes(),
TxStatus: data.TxStatusValInvalid,
TxStatus: txStatus,
DecryptionKeyID: decryptionKeyID,
TransactionSubmittedEventID: txSubEvent.ID,
})
if err != nil {
log.Err(err).Msg("failed to create decrypted tx")
}
txErrorSignalCh <- fmt.Errorf("failed to send transaction: %w", err)
txErrorSignalCh <- fmt.Errorf("%w: %v", errSendTransaction, err)
return
}
} else {
Expand Down Expand Up @@ -498,6 +505,9 @@ func (tm *TxMapperDB) processTransactionExecution(
receipt, err := tm.waitForReceiptWithTimeout(ctx, txHash, ReceiptWaitTimeout, txErrorSignalCh)
if err != nil {
log.Err(err).Msg("")
if errors.Is(err, errSendTransaction) {
return
}
// update/create status to not included
err := tm.dbQuery.UpsertTX(ctx, data.UpsertTXParams{
Slot: slot,
Expand Down Expand Up @@ -748,6 +758,15 @@ func decryptTransaction(key []byte, encrypted []byte) (*types.Transaction, error
return tx, nil
}

func isFeeTooLowError(err error) bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should expand the fee-related error to include the below errors:
"replacement transaction underpriced"
"replacement underpriced"
"max fee per gas less than block base fee"

It would also be helpful to log the raw error string, so we can collect new variants and tighten patterns over time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all above errors are added to the check and we already log the raw error string here

if err == nil {
return false
}
return strings.Contains(strings.ToLower(err.Error()), "feetoolow") ||
strings.Contains(strings.ToLower(err.Error()), "underpriced") ||
strings.Contains(strings.ToLower(err.Error()), "maxfeepergaslessthanblockbasefee")
}

// waitForReceiptWithTimeout waits for a transaction receipt with a provided timeout.
func (tm *TxMapperDB) waitForReceiptWithTimeout(ctx context.Context, txHash common.Hash, receiptWaitTimeout time.Duration, txErrorSignalCh chan error) (*types.Receipt, error) {
ctx, cancel := context.WithTimeout(ctx, receiptWaitTimeout)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- +goose Up
-- +goose StatementBegin
ALTER TYPE tx_status_val ADD VALUE 'invalid fee too low';
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
-- +goose StatementEnd