Skip to content

Commit 06556d7

Browse files
committed
Fix outdated tx pointer issue
See #449
1 parent 73b846e commit 06556d7

File tree

9 files changed

+236
-91
lines changed

9 files changed

+236
-91
lines changed

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

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

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

Lines changed: 4 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: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,25 @@ SELECT * FROM tx_pointer
4343
WHERE eon = $1;
4444

4545
-- name: InitTxPointer :exec
46-
INSERT INTO tx_pointer (eon, slot, value)
47-
VALUES ($1, $2, 0)
46+
INSERT INTO tx_pointer (eon, age, value)
47+
VALUES ($1, $2, $3)
4848
ON CONFLICT DO NOTHING;
4949

5050
-- name: SetTxPointer :exec
51-
INSERT INTO tx_pointer (eon, slot, value)
51+
INSERT INTO tx_pointer (eon, age, value)
5252
VALUES ($1, $2, $3)
5353
ON CONFLICT (eon) DO UPDATE
54-
SET slot = $2, value = $3;
54+
SET age = $2, value = $3;
5555

56-
-- name: SetTxPointerSlot :exec
56+
-- name: IncrementTxPointerAge :one
5757
UPDATE tx_pointer
58-
SET slot = $2
59-
WHERE eon = $1;
58+
SET age = age + 1
59+
WHERE eon = $1
60+
RETURNING age;
61+
62+
-- name: ResetAllTxPointerAges :exec
63+
UPDATE tx_pointer
64+
SET age = NULL;
6065

6166
-- name: SetCurrentDecryptionTrigger :exec
6267
INSERT INTO current_decryption_trigger (eon, slot, tx_pointer, identities_hash)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ CREATE TABLE transaction_submitted_event_count(
2929

3030
CREATE TABLE tx_pointer(
3131
eon bigint PRIMARY KEY,
32-
slot bigint NOT NULL DEFAULT 0,
32+
age bigint,
3333
value bigint NOT NULL DEFAULT 0
3434
);
3535

rolling-shutter/keyperimpl/gnosis/handlers.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gnosis
22

33
import (
44
"context"
5+
"database/sql"
56
"math"
67

78
"github.com/jackc/pgx/v4"
@@ -279,8 +280,11 @@ func (h *DecryptionKeysHandler) HandleMessage(ctx context.Context, msg p2pmsg.Me
279280
Int64("tx-pointer-updated", newTxPointer).
280281
Msg("updating tx pointer")
281282
err := gnosisDB.SetTxPointer(ctx, database.SetTxPointerParams{
282-
Eon: int64(keys.Eon),
283-
Slot: int64(extra.Slot),
283+
Eon: int64(keys.Eon),
284+
Age: sql.NullInt64{
285+
Int64: 0,
286+
Valid: true,
287+
},
284288
Value: newTxPointer,
285289
})
286290
if err != nil {

rolling-shutter/keyperimpl/gnosis/keyper.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ func (kpr *Keyper) Start(ctx context.Context, runner service.Runner) error {
164164
return err
165165
}
166166

167+
// Set all transaction pointer ages to infinity. They will be reset to zero when the next
168+
// decryption keys arrive, telling us the agreed upon pointer value. Pointer values that are
169+
// not in the db yet are not affected. They will be initialized to zero when we first access
170+
// them. This is most importantly the case for the pointer value of not yet started eons.
171+
gnosisDB := database.New(kpr.dbpool)
172+
err = gnosisDB.ResetAllTxPointerAges(ctx)
173+
if err != nil {
174+
return errors.Wrap(err, "failed to reset transaction pointer age")
175+
}
176+
167177
runner.Go(func() error { return kpr.processInputs(ctx) })
168178
return runner.StartService(kpr.core, kpr.chainSyncClient, kpr.slotTicker, kpr.eonKeyPublisher)
169179
}

rolling-shutter/keyperimpl/gnosis/messagingmiddleware.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gnosis
33
import (
44
"bytes"
55
"context"
6+
"database/sql"
67

78
"github.com/jackc/pgx/v4"
89
"github.com/jackc/pgx/v4/pgxpool"
@@ -283,8 +284,11 @@ func (i *MessagingMiddleware) advanceTxPointer(ctx context.Context, msg *p2pmsg.
283284
Int64("tx-pointer-updated", newTxPointer).
284285
Msg("updating tx pointer")
285286
err := gnosisDB.SetTxPointer(ctx, database.SetTxPointerParams{
286-
Eon: int64(msg.Eon),
287-
Slot: int64(extra.Slot),
287+
Eon: int64(msg.Eon),
288+
Age: sql.NullInt64{
289+
Int64: 0,
290+
Valid: true,
291+
},
288292
Value: newTxPointer,
289293
})
290294
if err != nil {

0 commit comments

Comments
 (0)