Skip to content

Commit 4b160de

Browse files
committed
Trigger decryption based on slots not blocks
1 parent 11c4ae6 commit 4b160de

File tree

17 files changed

+591
-297
lines changed

17 files changed

+591
-297
lines changed

rolling-shutter/keyperimpl/gnosis/config.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@ package gnosis
22

33
import (
44
"io"
5+
"math"
56

67
"github.com/ethereum/go-ethereum/common"
8+
"github.com/pkg/errors"
79

810
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/kprconfig"
911
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/configuration"
1012
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/metricsserver"
1113
"github.com/shutter-network/rolling-shutter/rolling-shutter/p2p"
1214
)
1315

16+
const (
17+
maxSecondsPerSlot = 60 * 60
18+
maxChainAge = 100 * 365 * 24 * 60 * 60
19+
)
20+
1421
var _ configuration.Config = &Config{}
1522

1623
func NewConfig() *Config {
@@ -38,9 +45,12 @@ type Config struct {
3845
Shuttermint *kprconfig.ShuttermintConfig
3946
Metrics *metricsserver.MetricsConfig
4047

48+
// TODO: put these in a child config
4149
GnosisContracts *GnosisContracts `shconfig:",required"`
4250
EncryptedGasLimit uint64 `shconfig:",required"`
4351
MinGasPerTransaction uint64 `shconfig:",required"`
52+
SecondsPerSlot uint64 `shconfig:",required"`
53+
GenesisSlotTimestamp uint64 `shconfig:",required"`
4454
}
4555

4656
type GnosisContracts struct {
@@ -50,6 +60,13 @@ type GnosisContracts struct {
5060
}
5161

5262
func (c *Config) Validate() error {
63+
if c.SecondsPerSlot > maxSecondsPerSlot {
64+
return errors.Errorf("seconds per slot is too big (%d > %d)", c.SecondsPerSlot, maxSecondsPerSlot)
65+
}
66+
maxGenesisSlotTime := uint64(math.MaxInt64 - maxChainAge)
67+
if c.GenesisSlotTimestamp > maxGenesisSlotTime {
68+
return errors.Errorf("genesis slot timestamp is too big (%d > %d)", c.GenesisSlotTimestamp, maxGenesisSlotTime)
69+
}
5370
return nil
5471
}
5572

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

Lines changed: 34 additions & 23 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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ ORDER BY index ASC
2020
LIMIT $3;
2121

2222
-- name: SetTransactionSubmittedEventsSyncedUntil :exec
23-
INSERT INTO transaction_submitted_events_synced_until (block_number) VALUES ($1)
23+
INSERT INTO transaction_submitted_events_synced_until (block_hash, block_number, slot) VALUES ($1, $2, $3)
2424
ON CONFLICT (enforce_one_row) DO UPDATE
25-
SET block_number = $1;
25+
SET block_hash = $1, block_number = $2, slot = $3;
2626

2727
-- name: GetTransactionSubmittedEventsSyncedUntil :one
28-
SELECT block_number FROM transaction_submitted_events_synced_until LIMIT 1;
28+
SELECT * FROM transaction_submitted_events_synced_until LIMIT 1;
2929

3030
-- name: SetTransactionSubmittedEventCount :exec
3131
INSERT INTO transaction_submitted_event_count (eon, event_count)
@@ -54,21 +54,21 @@ ON CONFLICT (eon) DO UPDATE
5454
SET block = $2, value = $3;
5555

5656
-- name: SetCurrentDecryptionTrigger :exec
57-
INSERT INTO current_decryption_trigger (eon, block, tx_pointer, identities_hash)
57+
INSERT INTO current_decryption_trigger (eon, slot, tx_pointer, identities_hash)
5858
VALUES ($1, $2, $3, $4)
5959
ON CONFLICT (eon) DO UPDATE
60-
SET block = $2, tx_pointer = $3, identities_hash = $4;
60+
SET slot = $2, tx_pointer = $3, identities_hash = $4;
6161

6262
-- name: GetCurrentDecryptionTrigger :one
6363
SELECT * FROM current_decryption_trigger
6464
WHERE eon = $1;
6565

6666
-- name: InsertSlotDecryptionSignature :exec
67-
INSERT INTO slot_decryption_signatures (eon, block, keyper_index, tx_pointer, identities_hash, signature)
67+
INSERT INTO slot_decryption_signatures (eon, slot, keyper_index, tx_pointer, identities_hash, signature)
6868
VALUES ($1, $2, $3, $4, $5, $6);
6969

7070
-- name: GetSlotDecryptionSignatures :many
7171
SELECT * FROM slot_decryption_signatures
72-
WHERE eon = $1 AND block = $2 AND tx_pointer = $3 AND identities_hash = $4
72+
WHERE eon = $1 AND slot = $2 AND tx_pointer = $3 AND identities_hash = $4
7373
ORDER BY keyper_index ASC
7474
LIMIT $5;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ CREATE TABLE transaction_submitted_event (
1717

1818
CREATE TABLE transaction_submitted_events_synced_until(
1919
enforce_one_row bool PRIMARY KEY DEFAULT true,
20-
block_number bigint NOT NULL CHECK (block_number >= 0)
20+
block_hash bytea NOT NULL,
21+
block_number bigint NOT NULL CHECK (block_number >= 0),
22+
slot bigint NOT NULL CHECK (slot >= 0)
2123
);
2224

2325
CREATE TABLE transaction_submitted_event_count(
@@ -33,17 +35,17 @@ CREATE TABLE tx_pointer(
3335

3436
CREATE TABLE current_decryption_trigger(
3537
eon bigint PRIMARY KEY CHECK (eon >= 0),
36-
block bigint NOT NULL CHECK (block >= 0),
38+
slot bigint NOT NULL CHECK (slot >= 0),
3739
tx_pointer bigint NOT NULL CHECK (tx_pointer >= 0),
3840
identities_hash bytea NOT NULL
3941
);
4042

4143
CREATE TABLE slot_decryption_signatures(
4244
eon bigint NOT NULL CHECK (eon >= 0),
43-
block bigint NOT NULL CHECK (block >= 0),
45+
slot bigint NOT NULL CHECK (slot >= 0),
4446
keyper_index bigint NOT NULL,
4547
tx_pointer bigint NOT NULL CHECK (tx_pointer >= 0),
4648
identities_hash bytea NOT NULL,
4749
signature bytea NOT NULL,
48-
PRIMARY KEY (eon, block, keyper_index)
50+
PRIMARY KEY (eon, slot, keyper_index)
4951
);

rolling-shutter/keyperimpl/gnosis/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (h *DecryptionKeySharesHandler) HandleMessage(ctx context.Context, msg p2pm
106106
identitiesHash := computeIdentitiesHashFromShares(keyShares.Shares)
107107
err := gnosisDB.InsertSlotDecryptionSignature(ctx, database.InsertSlotDecryptionSignatureParams{
108108
Eon: int64(keyShares.Eon),
109-
Block: int64(extra.Slot),
109+
Slot: int64(extra.Slot),
110110
KeyperIndex: int64(keyShares.KeyperIndex),
111111
TxPointer: int64(extra.TxPointer),
112112
IdentitiesHash: identitiesHash,
@@ -127,7 +127,7 @@ func (h *DecryptionKeySharesHandler) HandleMessage(ctx context.Context, msg p2pm
127127

128128
signaturesDB, err := gnosisDB.GetSlotDecryptionSignatures(ctx, database.GetSlotDecryptionSignaturesParams{
129129
Eon: int64(keyShares.Eon),
130-
Block: int64(extra.Slot),
130+
Slot: int64(extra.Slot),
131131
TxPointer: int64(extra.TxPointer),
132132
IdentitiesHash: identitiesHash,
133133
Limit: keyperSet.Threshold,

0 commit comments

Comments
 (0)