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 failed rollup insertion on Host #1881

Merged
merged 1 commit into from
Apr 22, 2024
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
7 changes: 7 additions & 0 deletions go/host/storage/hostdb/hostdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ func (b *dbTransaction) Write() error {
}
return nil
}

func (b *dbTransaction) Rollback() error {
if err := b.tx.Rollback(); err != nil {
return fmt.Errorf("failed to rollback host transaction. Cause: %w", err)
}
return nil
}
9 changes: 9 additions & 0 deletions go/host/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func (s *storageImpl) AddBatch(batch *common.ExtBatch) error {
}

if err := hostdb.AddBatch(dbtx, s.db.GetSQLStatement(), batch); err != nil {
if err := dbtx.Rollback(); err != nil {
return err
}
return fmt.Errorf("could not add batch to host. Cause: %w", err)
}

Expand All @@ -56,6 +59,9 @@ func (s *storageImpl) AddRollup(rollup *common.ExtRollup, metadata *common.Publi
}

if err := hostdb.AddRollup(dbtx, s.db.GetSQLStatement(), rollup, metadata, block); err != nil {
if err := dbtx.Rollback(); err != nil {
return err
}
return fmt.Errorf("could not add rollup to host. Cause: %w", err)
}

Expand All @@ -72,6 +78,9 @@ func (s *storageImpl) AddBlock(b *types.Header, rollupHash common.L2RollupHash)
}

if err := hostdb.AddBlock(dbtx, s.db.GetSQLStatement(), b, rollupHash); err != nil {
if err := dbtx.Rollback(); err != nil {
return err
}
return fmt.Errorf("could not add block to host. Cause: %w", err)
}

Expand Down
Loading