Skip to content

Commit f781a73

Browse files
committed
fix: tx pointer reset with empty tx table
If the tx pointer becomes outdated, we want to reset it to the end of the tx queue, so that we start decrypting at the next submitted tx. To do that, we query the index of the latest tx and add 1. If the table is empty, the SQL query will return NULL. However, SQLC will not pick up on that and try to scan into an int32 value, resulting in an error. This commit circumvents this by explicitly returning 0 instead of NULL in the cases of an empty table and casting into a bigint, communicating the expected type to SQLC.
1 parent 07037b2 commit f781a73

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

rolling-shutter/keyperimpl/gnosis/database/gnosiskeyper.sqlc.gen.go

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rolling-shutter/keyperimpl/gnosis/database/sql/queries/gnosiskeyper.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ SET block_hash = $1, block_number = $2, slot = $3;
3535
SELECT * FROM transaction_submitted_events_synced_until LIMIT 1;
3636

3737
-- name: GetTransactionSubmittedEventCount :one
38-
SELECT max(index) + 1 FROM transaction_submitted_event
38+
SELECT
39+
cast(coalesce(max(index) + 1, 0) AS bigint)
40+
FROM transaction_submitted_event
3941
WHERE eon = $1;
4042

4143
-- name: DeleteTransactionSubmittedEventsFromBlockNumber :exec

rolling-shutter/keyperimpl/gnosis/newslot.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,8 @@ func getTxPointer(ctx context.Context, db *pgxpool.Pool, eon int64, maxTxPointer
209209
Int64("tx-pointer", txPointer).
210210
Int64("tx-pointer-age", txPointerAge).
211211
Msg("outdated tx pointer")
212-
txPointerInt32, err := gnosisKeyperDB.GetTransactionSubmittedEventCount(ctx, eon)
213-
txPointer = int64(txPointerInt32)
214-
if err == pgx.ErrNoRows {
215-
txPointer = 0
216-
} else if err != nil {
212+
txPointer, err = gnosisKeyperDB.GetTransactionSubmittedEventCount(ctx, eon)
213+
if err != nil {
217214
return 0, errors.Wrap(err, "failed to query transaction submitted event count from db")
218215
}
219216
}

0 commit comments

Comments
 (0)