Skip to content

Commit

Permalink
Remove the need to pass a transaction when upserting to known_gaps
Browse files Browse the repository at this point in the history
Thanks Ian :D
  • Loading branch information
Abdul Rabbani committed Mar 22, 2022
1 parent bca12f9 commit 73f46a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 15 deletions.
12 changes: 1 addition & 11 deletions statediff/indexer/database/sql/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,18 +562,8 @@ func (sdi *StateDiffIndexer) PushKnownGaps(startingBlockNumber *big.Int, endingB
CheckedOut: checkedOut,
ProcessingKey: processingKey,
}
tx, err := sdi.dbWriter.db.Begin(sdi.ctx)
if err != nil {
return err
}

if err := sdi.dbWriter.upsertKnownGaps(tx, knownGap); err != nil {
if err := sdi.dbWriter.upsertKnownGaps(knownGap); err != nil {
return err
}

if err := tx.Commit(sdi.ctx); err != nil {
return err
}

return nil
}
7 changes: 3 additions & 4 deletions statediff/indexer/database/sql/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package sql

import (
"context"
"fmt"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -183,14 +184,12 @@ func (w *Writer) upsertStorageCID(tx Tx, storageCID models.StorageNodeModel) err
return nil
}

func (w *Writer) upsertKnownGaps(tx Tx, knownGaps models.KnownGapsModel) error {
res, err := tx.Exec(w.db.Context(), w.db.InsertKnownGapsStm(),
func (w *Writer) upsertKnownGaps(knownGaps models.KnownGapsModel) error {
_, err := w.db.Exec(context.Background(), w.db.InsertKnownGapsStm(),
knownGaps.StartingBlockNumber, knownGaps.EndingBlockNumber, knownGaps.CheckedOut, knownGaps.ProcessingKey)
if err != nil {
return fmt.Errorf("error upserting known_gaps entry: %v", err)
}

ret, _ := res.RowsAffected()
fmt.Println("Res:", ret)
return nil
}

0 comments on commit 73f46a5

Please sign in to comment.