Skip to content

Commit 1178aab

Browse files
committed
Store tx_pointer in db
1 parent c63b310 commit 1178aab

File tree

4 files changed

+115
-5
lines changed

4 files changed

+115
-5
lines changed

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

Lines changed: 67 additions & 0 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: 11 additions & 1 deletion
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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,22 @@ ON CONFLICT (enforce_one_row) DO UPDATE
1818
SET block_number = $1;
1919

2020
-- name: GetTransactionSubmittedEventsSyncedUntil :one
21-
SELECT block_number FROM transaction_submitted_events_synced_until LIMIT 1;
21+
SELECT block_number FROM transaction_submitted_events_synced_until LIMIT 1;
22+
23+
-- name: GetLocalTxPointer :one
24+
SELECT local, local_block FROM tx_pointer LIMIT 1;
25+
26+
-- name: GetConsensusTxPointer :one
27+
SELECT consensus, consensus_block FROM tx_pointer LIMIT 1;
28+
29+
-- name: UpdateLocalTxPointer :exec
30+
INSERT INTO tx_pointer (local, local_block)
31+
VALUES ($1, $2)
32+
ON CONFLICT (enforce_one_row) DO UPDATE
33+
SET local = $1, local_block = $2;
34+
35+
-- name: UpdateConsensusTxPointer :exec
36+
INSERT INTO tx_pointer (consensus, consensus_block)
37+
VALUES ($1, $2)
38+
ON CONFLICT (enforce_one_row) DO UPDATE
39+
SET consensus = $1, consensus_block = $2;

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,22 @@ CREATE TABLE transaction_submitted_event (
1414
PRIMARY KEY (block_number, block_hash, tx_index, log_index)
1515
);
1616

17-
create table transaction_submitted_events_synced_until(
18-
enforce_one_row bool primary key default true,
19-
block_number bigint not null CHECK (block_number > 0)
17+
CREATE TABLE transaction_submitted_events_synced_until(
18+
enforce_one_row bool PRIMARY KEY DEFAULT true,
19+
block_number bigint NOT NULL CHECK (block_number > 0)
20+
);
21+
22+
-- tx_pointer stores what we know about the current value of the tx pointer. There are two
23+
-- sources that are stored independently: The keyper itself (local) and the other keypers
24+
-- (consensus). The local value is updated whenever the keyper sends decryption key shares for some
25+
-- transactions. The consensus value is updated when decryption keys are received from other
26+
-- keypers. The values can be NULL if the keyper has lost track (e.g. after a restart or if no
27+
-- messages have been received recently). Each value is annotated with the number of the block at
28+
-- whose end the tx_pointer is valid.
29+
CREATE TABLE tx_pointer(
30+
enforce_one_row bool PRIMARY KEY DEFAULT true,
31+
local bigint DEFAULT NULL,
32+
local_block bigint NOT NULL DEFAULT 0,
33+
consensus bigint DEFAULT NULL,
34+
consensus_block bigint NOT NULL DEFAULT 0
2035
);

0 commit comments

Comments
 (0)