Skip to content

Commit 14961a1

Browse files
committed
Add Gnosis config section
1 parent aa66bfc commit 14961a1

File tree

5 files changed

+120
-44
lines changed

5 files changed

+120
-44
lines changed

rolling-shutter/gnosiskeyperwatcher/blocks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func NewBlocksWatcher(config *keyper.Config, blocksChannel chan *BlockReceivedEv
3131

3232
func (w *BlocksWatcher) Start(ctx context.Context, runner service.Runner) error {
3333
runner.Go(func() error {
34-
ethClient, err := ethclient.Dial(w.config.Gnosis.EthereumURL)
34+
ethClient, err := ethclient.Dial(w.config.Gnosis.Node.EthereumURL)
3535
if err != nil {
3636
return err
3737
}

rolling-shutter/keyperimpl/gnosis/config.go

Lines changed: 104 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ const (
1818
maxChainAge = 100 * 365 * 24 * 60 * 60
1919
)
2020

21-
var _ configuration.Config = &Config{}
21+
var (
22+
_ configuration.Config = &Config{}
23+
_ configuration.Config = &GnosisConfig{}
24+
_ configuration.Config = &GnosisContractsConfig{}
25+
)
2226

2327
func NewConfig() *Config {
2428
c := &Config{}
@@ -28,7 +32,7 @@ func NewConfig() *Config {
2832

2933
func (c *Config) Init() {
3034
c.P2P = p2p.NewConfig()
31-
c.Gnosis = configuration.NewEthnodeConfig()
35+
c.Gnosis = NewGnosisConfig()
3236
c.Shuttermint = kprconfig.NewShuttermintConfig()
3337
c.Metrics = metricsserver.NewConfig()
3438
}
@@ -40,32 +44,19 @@ type Config struct {
4044
HTTPEnabled bool
4145
HTTPListenAddress string
4246

47+
Gnosis *GnosisConfig
4348
P2P *p2p.Config
44-
Gnosis *configuration.EthnodeConfig
4549
Shuttermint *kprconfig.ShuttermintConfig
4650
Metrics *metricsserver.MetricsConfig
47-
48-
// TODO: put these in a child config
49-
GnosisContracts *GnosisContracts `shconfig:",required"`
50-
EncryptedGasLimit uint64 `shconfig:",required"`
51-
MinGasPerTransaction uint64 `shconfig:",required"`
52-
SecondsPerSlot uint64 `shconfig:",required"`
53-
GenesisSlotTimestamp uint64 `shconfig:",required"`
54-
}
55-
56-
type GnosisContracts struct {
57-
KeyperSetManager common.Address `shconfig:",required"`
58-
KeyBroadcastContract common.Address `shconfig:",required"`
59-
Sequencer common.Address `shconfig:",required"`
6051
}
6152

6253
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)
54+
if c.Gnosis.SecondsPerSlot > maxSecondsPerSlot {
55+
return errors.Errorf("seconds per slot is too big (%d > %d)", c.Gnosis.SecondsPerSlot, maxSecondsPerSlot)
6556
}
6657
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)
58+
if c.Gnosis.GenesisSlotTimestamp > maxGenesisSlotTime {
59+
return errors.Errorf("genesis slot timestamp is too big (%d > %d)", c.Gnosis.GenesisSlotTimestamp, maxGenesisSlotTime)
6960
}
7061
return nil
7162
}
@@ -77,13 +68,8 @@ func (c *Config) Name() string {
7768
func (c *Config) SetDefaultValues() error {
7869
c.HTTPEnabled = false
7970
c.HTTPListenAddress = ":3000"
80-
c.GnosisContracts = &GnosisContracts{
81-
KeyperSetManager: common.Address{},
82-
KeyBroadcastContract: common.Address{},
83-
Sequencer: common.Address{},
84-
}
85-
c.EncryptedGasLimit = 1_000_000
86-
c.MinGasPerTransaction = 21_000
71+
c.Gnosis.EncryptedGasLimit = 1_000_000
72+
c.Gnosis.MinGasPerTransaction = 21_000
8773
return nil
8874
}
8975

@@ -103,5 +89,95 @@ func (c Config) TOMLWriteHeader(_ io.Writer) (int, error) {
10389
}
10490

10591
func (c *Config) GetAddress() common.Address {
106-
return c.Gnosis.PrivateKey.EthereumAddress()
92+
return c.Gnosis.Node.PrivateKey.EthereumAddress()
93+
}
94+
95+
type GnosisConfig struct {
96+
Node *configuration.EthnodeConfig `shconfig:",required"`
97+
Contracts *GnosisContractsConfig `shconfig:",required"`
98+
EncryptedGasLimit uint64 `shconfig:",required"`
99+
MinGasPerTransaction uint64 `shconfig:",required"`
100+
SecondsPerSlot uint64 `shconfig:",required"`
101+
GenesisSlotTimestamp uint64 `shconfig:",required"`
102+
}
103+
104+
func NewGnosisConfig() *GnosisConfig {
105+
c := &GnosisConfig{
106+
Node: configuration.NewEthnodeConfig(),
107+
Contracts: NewGnosisContractsConfig(),
108+
EncryptedGasLimit: 0,
109+
MinGasPerTransaction: 0,
110+
SecondsPerSlot: 0,
111+
GenesisSlotTimestamp: 0,
112+
}
113+
c.Init()
114+
return c
115+
}
116+
117+
func (c *GnosisConfig) Init() {
118+
c.Node.Init()
119+
c.Contracts.Init()
120+
}
121+
122+
func (c *GnosisConfig) Name() string {
123+
return "gnosis"
124+
}
125+
126+
func (c *GnosisConfig) Validate() error {
127+
if c.SecondsPerSlot == 0 {
128+
return errors.Errorf("seconds per slot must not be zero")
129+
}
130+
return nil
131+
}
132+
133+
func (c *GnosisConfig) SetDefaultValues() error {
134+
return nil
135+
}
136+
137+
func (c *GnosisConfig) SetExampleValues() error {
138+
c.EncryptedGasLimit = 1_000_000
139+
c.MinGasPerTransaction = 21_000
140+
c.SecondsPerSlot = 5
141+
c.GenesisSlotTimestamp = 1665410700
142+
return nil
143+
}
144+
145+
func (c *GnosisConfig) TOMLWriteHeader(_ io.Writer) (int, error) {
146+
return 0, nil
147+
}
148+
149+
type GnosisContractsConfig struct {
150+
KeyperSetManager common.Address `shconfig:",required"`
151+
KeyBroadcastContract common.Address `shconfig:",required"`
152+
Sequencer common.Address `shconfig:",required"`
153+
}
154+
155+
func NewGnosisContractsConfig() *GnosisContractsConfig {
156+
return &GnosisContractsConfig{
157+
KeyperSetManager: common.Address{},
158+
KeyBroadcastContract: common.Address{},
159+
Sequencer: common.Address{},
160+
}
161+
}
162+
163+
func (c *GnosisContractsConfig) Init() {}
164+
165+
func (c *GnosisContractsConfig) Name() string {
166+
return "gnosiscontracts"
167+
}
168+
169+
func (c *GnosisContractsConfig) Validate() error {
170+
return nil
171+
}
172+
173+
func (c *GnosisContractsConfig) SetDefaultValues() error {
174+
return nil
175+
}
176+
177+
func (c *GnosisContractsConfig) SetExampleValues() error {
178+
return nil
179+
}
180+
181+
func (c *GnosisContractsConfig) TOMLWriteHeader(_ io.Writer) (int, error) {
182+
return 0, nil
107183
}

rolling-shutter/keyperimpl/gnosis/keyper.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (kpr *Keyper) Start(ctx context.Context, runner service.Runner) error {
6565
runner.Defer(func() { close(kpr.decryptionTriggerChannel) })
6666

6767
kpr.slotTicker = slotticker.NewSlotTicker(
68-
time.Duration(kpr.config.SecondsPerSlot*uint64(time.Second)),
69-
time.Unix(int64(kpr.config.GenesisSlotTimestamp), 0),
68+
time.Duration(kpr.config.Gnosis.SecondsPerSlot*uint64(time.Second)),
69+
time.Unix(int64(kpr.config.Gnosis.GenesisSlotTimestamp), 0),
7070
)
7171

7272
kpr.dbpool, err = db.Connect(ctx, runner, kpr.config.DatabaseURL, database.Definition.Name())
@@ -89,7 +89,7 @@ func (kpr *Keyper) Start(ctx context.Context, runner service.Runner) error {
8989
HTTPEnabled: kpr.config.HTTPEnabled,
9090
HTTPListenAddress: kpr.config.HTTPListenAddress,
9191
P2P: kpr.config.P2P,
92-
Ethereum: kpr.config.Gnosis,
92+
Ethereum: kpr.config.Gnosis.Node,
9393
Shuttermint: kpr.config.Shuttermint,
9494
Metrics: kpr.config.Metrics,
9595
},
@@ -105,12 +105,12 @@ func (kpr *Keyper) Start(ctx context.Context, runner service.Runner) error {
105105

106106
kpr.chainSyncClient, err = chainsync.NewClient(
107107
ctx,
108-
chainsync.WithClientURL(kpr.config.Gnosis.EthereumURL),
109-
chainsync.WithKeyperSetManager(kpr.config.GnosisContracts.KeyperSetManager),
110-
chainsync.WithKeyBroadcastContract(kpr.config.GnosisContracts.KeyBroadcastContract),
108+
chainsync.WithClientURL(kpr.config.Gnosis.Node.EthereumURL),
109+
chainsync.WithKeyperSetManager(kpr.config.Gnosis.Contracts.KeyperSetManager),
110+
chainsync.WithKeyBroadcastContract(kpr.config.Gnosis.Contracts.KeyBroadcastContract),
111111
chainsync.WithSyncNewBlock(kpr.channelNewBlock),
112112
chainsync.WithSyncNewKeyperSet(kpr.channelNewKeyperSet),
113-
chainsync.WithPrivateKey(kpr.config.Gnosis.PrivateKey.Key),
113+
chainsync.WithPrivateKey(kpr.config.Gnosis.Node.PrivateKey.Key),
114114
chainsync.WithLogger(gethLog.NewLogger(slog.Default().Handler())),
115115
)
116116
if err != nil {
@@ -164,22 +164,22 @@ func (kpr *Keyper) ensureSequencerSyncing(ctx context.Context, eon uint64) error
164164
if kpr.sequencerSyncer == nil {
165165
log.Info().
166166
Uint64("eon", eon).
167-
Str("contract-address", kpr.config.GnosisContracts.KeyperSetManager.Hex()).
167+
Str("contract-address", kpr.config.Gnosis.Contracts.KeyperSetManager.Hex()).
168168
Msg("initializing sequencer syncer")
169-
client, err := ethclient.DialContext(ctx, kpr.config.Gnosis.ContractsURL)
169+
client, err := ethclient.DialContext(ctx, kpr.config.Gnosis.Node.ContractsURL)
170170
if err != nil {
171171
return err
172172
}
173-
contract, err := sequencerBindings.NewSequencer(kpr.config.GnosisContracts.Sequencer, client)
173+
contract, err := sequencerBindings.NewSequencer(kpr.config.Gnosis.Contracts.Sequencer, client)
174174
if err != nil {
175175
return err
176176
}
177177
kpr.sequencerSyncer = &SequencerSyncer{
178178
Contract: contract,
179179
DBPool: kpr.dbpool,
180180
StartEon: eon,
181-
GenesisSlotTimestamp: kpr.config.GenesisSlotTimestamp,
182-
SecondsPerSlot: kpr.config.SecondsPerSlot,
181+
GenesisSlotTimestamp: kpr.config.Gnosis.GenesisSlotTimestamp,
182+
SecondsPerSlot: kpr.config.Gnosis.SecondsPerSlot,
183183
}
184184

185185
// TODO: perform an initial sync without blocking and/or set start block

rolling-shutter/keyperimpl/gnosis/messagingmiddleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (i *MessagingMiddleware) interceptDecryptionKeyShares(
146146
TxPointer: uint64(currentDecryptionTrigger.TxPointer),
147147
IdentityPreimages: identityPreimages,
148148
}
149-
signature, err := ComputeSlotDecryptionSignature(&slotDecryptionSignatureData, i.config.Gnosis.PrivateKey.Key)
149+
signature, err := ComputeSlotDecryptionSignature(&slotDecryptionSignatureData, i.config.Gnosis.Node.PrivateKey.Key)
150150
if err != nil {
151151
return nil, errors.Wrapf(err, "failed to compute slot decryption signature")
152152
}

rolling-shutter/keyperimpl/gnosis/newslot.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (kpr *Keyper) getDecryptionIdentityPreimages(
195195
identityPreimages := []identitypreimage.IdentityPreimage{}
196196

197197
queries := gnosisdatabase.New(kpr.dbpool)
198-
limitUint64 := kpr.config.EncryptedGasLimit/kpr.config.MinGasPerTransaction + 1
198+
limitUint64 := kpr.config.Gnosis.EncryptedGasLimit/kpr.config.Gnosis.MinGasPerTransaction + 1
199199
if limitUint64 > math.MaxInt32 {
200200
return identityPreimages, errors.New("gas limit too big")
201201
}
@@ -216,7 +216,7 @@ func (kpr *Keyper) getDecryptionIdentityPreimages(
216216
gas := uint64(0)
217217
for _, event := range events {
218218
gas += uint64(event.GasLimit)
219-
if gas > kpr.config.EncryptedGasLimit {
219+
if gas > kpr.config.Gnosis.EncryptedGasLimit {
220220
break
221221
}
222222
identityPreimage, err := transactionSubmittedEventToIdentityPreimage(event)

0 commit comments

Comments
 (0)