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

fix(rollup_relayer): retry CommitFailed batches #911

Closed
wants to merge 3 commits into from
Closed
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 bridge/internal/controller/relayer/l2_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (r *Layer2Relayer) ProcessGasPriceOracle() {
// ProcessPendingBatches processes the pending batches by sending commitBatch transactions to layer 1.
func (r *Layer2Relayer) ProcessPendingBatches() {
// get pending batches from database in ascending order by their index.
pendingBatches, err := r.batchOrm.GetPendingBatches(r.ctx, 5)
pendingBatches, err := r.batchOrm.GetPendingAndCommitFailedBatches(r.ctx, 5)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not keep retrying forever. If it's a gas limit issue, then it should succeed the 2nd time. If it's a bug (e.g. Golang batch hash does not match Solidity batch hash), then retrying again and again will just burn ETH, in this case we need human intervention to fix the bug

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see.

if err != nil {
log.Error("Failed to fetch pending L2 batches", "err", err)
return
Expand Down
10 changes: 6 additions & 4 deletions bridge/internal/orm/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,24 @@ func (o *Batch) GetRollupStatusByHashList(ctx context.Context, hashes []string)
return statuses, nil
}

// GetPendingBatches retrieves pending batches up to the specified limit.
// GetPendingAndCommitFailedBatches retrieves pending and commitFailed batches up to the specified limit.
// Pending batches because we need to process unprocessed batches,
// commitFailed because we want to retry failed batches.
// The returned batches are sorted in ascending order by their index.
func (o *Batch) GetPendingBatches(ctx context.Context, limit int) ([]*Batch, error) {
func (o *Batch) GetPendingAndCommitFailedBatches(ctx context.Context, limit int) ([]*Batch, error) {
if limit <= 0 {
return nil, errors.New("limit must be greater than zero")
}

db := o.db.WithContext(ctx)
db = db.Model(&Batch{})
db = db.Where("rollup_status = ?", types.RollupPending)
db = db.Where("rollup_status = ? OR rollup_status = ?", types.RollupPending, types.RollupCommitFailed)
db = db.Order("index ASC")
db = db.Limit(limit)

var batches []*Batch
if err := db.Find(&batches).Error; err != nil {
return nil, fmt.Errorf("Batch.GetPendingBatches error: %w", err)
return nil, fmt.Errorf("Batch.GetPendingAndCommitFailedBatches error: %w", err)
}
return batches, nil
}
Expand Down
2 changes: 1 addition & 1 deletion bridge/internal/orm/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func TestBatchOrm(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, uint64(2), count)

pendingBatches, err := batchOrm.GetPendingBatches(context.Background(), 100)
pendingBatches, err := batchOrm.GetPendingAndCommitFailedBatches(context.Background(), 100)
assert.NoError(t, err)
assert.Equal(t, 2, len(pendingBatches))

Expand Down
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.2.14"
var tag = "v4.2.15"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
Loading