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

delete failed txs during pool cleanup #2733

Merged
merged 3 commits into from
Oct 31, 2023
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
1 change: 1 addition & 0 deletions pool/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type storage interface {
IsTxPending(ctx context.Context, hash common.Hash) (bool, error)
SetGasPrices(ctx context.Context, l2GasPrice uint64, l1GasPrice uint64) error
DeleteGasPricesHistoryOlderThan(ctx context.Context, date time.Time) error
DeleteFailedTransactionsOlderThan(ctx context.Context, date time.Time) error
UpdateTxsStatus(ctx context.Context, updateInfo []TxStatusUpdateInfo) error
UpdateTxStatus(ctx context.Context, updateInfo TxStatusUpdateInfo) error
UpdateTxWIPStatus(ctx context.Context, hash common.Hash, isWIP bool) error
Expand Down
10 changes: 10 additions & 0 deletions pool/pgpoolstorage/pgpoolstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ func (p *PostgresPoolStorage) DeleteTransactionsByHashes(ctx context.Context, ha
return nil
}

// DeleteFailedTransactionsOlderThan deletes all failed transactions older than the given date
func (p *PostgresPoolStorage) DeleteFailedTransactionsOlderThan(ctx context.Context, date time.Time) error {
sql := `DELETE FROM pool.transaction WHERE status = 'failed' and received_at < $1`

if _, err := p.db.Exec(ctx, sql, date); err != nil {
return err
}
return nil
}

// SetGasPrices sets the latest l2 and l1 gas prices
func (p *PostgresPoolStorage) SetGasPrices(ctx context.Context, l2GasPrice, l1GasPrice uint64) error {
sql := "INSERT INTO pool.gas_price (price, l1_price, timestamp) VALUES ($1, $2, $3)"
Expand Down
1 change: 1 addition & 0 deletions sequencer/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
// txPool contains the methods required to interact with the tx pool.
type txPool interface {
DeleteTransactionsByHashes(ctx context.Context, hashes []common.Hash) error
DeleteFailedTransactionsOlderThan(ctx context.Context, date time.Time) error
DeleteTransactionByHash(ctx context.Context, hash common.Hash) error
MarkWIPTxsAsPending(ctx context.Context) error
GetNonWIPPendingTxs(ctx context.Context) ([]pool.Transaction, error)
Expand Down
16 changes: 16 additions & 0 deletions sequencer/mock_pool.go

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

13 changes: 11 additions & 2 deletions sequencer/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,22 @@ func (s *Sequencer) purgeOldPoolTxs(ctx context.Context) {
log.Errorf("failed to get txs hashes to delete, err: %v", err)
continue
}
log.Infof("will try to delete %d redundant txs", len(txHashes))
log.Infof("trying to delete %d selected txs", len(txHashes))
err = s.pool.DeleteTransactionsByHashes(ctx, txHashes)
if err != nil {
log.Errorf("failed to delete txs from the pool, err: %v", err)
log.Errorf("failed to delete selected txs from the pool, err: %v", err)
continue
}
log.Infof("deleted %d selected txs from the pool", len(txHashes))

log.Infof("trying to delete failed txs from the pool")
// Delete failed txs older than a certain date (14 seconds per L1 block)
err = s.pool.DeleteFailedTransactionsOlderThan(ctx, time.Now().Add(-time.Duration(s.cfg.BlocksAmountForTxsToBeDeleted*14)*time.Second)) //nolint:gomnd
ToniRamirezM marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Errorf("failed to delete failed txs from the pool, err: %v", err)
continue
}
log.Infof("failed txs deleted from the pool")
}
}

Expand Down