From 73f46a59ef4c95c1887b8b46c40d30c3672b1efd Mon Sep 17 00:00:00 2001 From: Abdul Rabbani Date: Tue, 22 Mar 2022 11:52:35 -0400 Subject: [PATCH] Remove the need to pass a transaction when upserting to known_gaps Thanks Ian :D --- statediff/indexer/database/sql/indexer.go | 12 +----------- statediff/indexer/database/sql/writer.go | 7 +++---- 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/statediff/indexer/database/sql/indexer.go b/statediff/indexer/database/sql/indexer.go index 6c33140ab986..512d7f772f48 100644 --- a/statediff/indexer/database/sql/indexer.go +++ b/statediff/indexer/database/sql/indexer.go @@ -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 } diff --git a/statediff/indexer/database/sql/writer.go b/statediff/indexer/database/sql/writer.go index 0e13a8ed89fa..ff06a424a36f 100644 --- a/statediff/indexer/database/sql/writer.go +++ b/statediff/indexer/database/sql/writer.go @@ -17,6 +17,7 @@ package sql import ( + "context" "fmt" "github.com/ethereum/go-ethereum/common" @@ -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 }