Skip to content

Commit 638efb1

Browse files
committed
Use tx index event parameter
We used to have our own counter for encrypted txs added to the sequencer contract. Under normal circumstances, this value is the same as the `txIndex` parameter on the TransactionSubmittedEvent. Using the latter is more resistant to reorgs, so we use that now.
1 parent e3e19bb commit 638efb1

File tree

3 files changed

+21
-19
lines changed

3 files changed

+21
-19
lines changed

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

Lines changed: 9 additions & 2 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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ INSERT INTO transaction_submitted_event (
1111
gas_limit
1212
)
1313
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
14-
ON CONFLICT DO NOTHING;
14+
ON CONFLICT (index, eon) DO UPDATE SET
15+
block_number = $2,
16+
block_hash = $3,
17+
tx_index = $4,
18+
log_index = $5,
19+
identity_prefix = $7,
20+
sender = $8,
21+
gas_limit = $9;
1522

1623
-- name: GetTransactionSubmittedEvents :many
1724
SELECT * FROM transaction_submitted_event
18-
WHERE eon = $1 AND index >= $2
25+
WHERE eon = $1 AND index >= $2 AND index < $2 + $3
1926
ORDER BY index ASC
2027
LIMIT $3;
2128

rolling-shutter/keyperimpl/gnosis/sequencersyncer.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,8 @@ func (s *SequencerSyncer) insertTransactionSubmittedEvents(
154154
queries := database.New(tx)
155155
nextEventIndices := make(map[uint64]int64)
156156
for _, event := range events {
157-
nextEventIndex, ok := nextEventIndices[event.Eon]
158-
if !ok {
159-
nextEventIndexFromDB, err := queries.GetTransactionSubmittedEventCount(ctx, int64(event.Eon))
160-
if err == pgx.ErrNoRows {
161-
nextEventIndexFromDB = 0
162-
} else if err != nil {
163-
return errors.Wrapf(err, "failed to query count of transaction submitted events for eon %d", event.Eon)
164-
}
165-
nextEventIndices[event.Eon] = nextEventIndexFromDB
166-
nextEventIndex = nextEventIndexFromDB
167-
}
168-
169157
_, err := queries.InsertTransactionSubmittedEvent(ctx, database.InsertTransactionSubmittedEventParams{
170-
Index: nextEventIndex,
158+
Index: int64(event.TxIndex),
171159
BlockNumber: int64(event.Raw.BlockNumber),
172160
BlockHash: event.Raw.BlockHash[:],
173161
TxIndex: int64(event.Raw.TxIndex),
@@ -180,10 +168,10 @@ func (s *SequencerSyncer) insertTransactionSubmittedEvents(
180168
if err != nil {
181169
return errors.Wrap(err, "failed to insert transaction submitted event into db")
182170
}
183-
metricsLatestTxSubmittedEventIndex.WithLabelValues(fmt.Sprint(event.Eon)).Set(float64(nextEventIndex))
171+
metricsLatestTxSubmittedEventIndex.WithLabelValues(fmt.Sprint(event.Eon)).Set(float64(event.TxIndex))
184172
nextEventIndices[event.Eon]++
185173
log.Debug().
186-
Int64("index", nextEventIndex).
174+
Uint64("index", event.TxIndex).
187175
Uint64("block", event.Raw.BlockNumber).
188176
Uint64("eon", event.Eon).
189177
Hex("identityPrefix", event.IdentityPrefix[:]).

0 commit comments

Comments
 (0)