Skip to content

Commit 152a30d

Browse files
committed
feat(op): allow to retrieve keyperset by index for op-bootstrap
1 parent 9566cdb commit 152a30d

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

rolling-shutter/keyperimpl/optimism/bootstrap/config.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ func NewConfig() *Config {
1919

2020
func (c *Config) Init() {
2121
c.SigningKey = &keys.ECDSAPrivate{}
22-
c.ActivationBlockNumber = number.NewBlockNumber()
22+
c.ByActivationBlockNumber = number.NewBlockNumber()
2323
}
2424

2525
type Config struct {
2626
InstanceID uint64 `shconfig:",required"`
2727

28-
JSONRPCURL string ` comment:"The op-geth JSON RPC endpoint"`
29-
ActivationBlockNumber *number.BlockNumber
30-
KeyperSetFilePath string
28+
JSONRPCURL string ` comment:"The op-geth JSON RPC endpoint"`
29+
ByActivationBlockNumber *number.BlockNumber
30+
ByIndex *uint64
31+
KeyperSetFilePath string
3132

3233
ShuttermintURL string
3334
SigningKey *keys.ECDSAPrivate `shconfig:",required"`
@@ -45,7 +46,9 @@ func (c *Config) SetDefaultValues() error {
4546
c.JSONRPCURL = "http://localhost:8545"
4647
c.ShuttermintURL = "http://localhost:26657"
4748
c.KeyperSetFilePath = "keyperset.json"
48-
c.ActivationBlockNumber = number.LatestBlock
49+
c.ByActivationBlockNumber = nil
50+
i := uint64(1)
51+
c.ByIndex = &i
4952
return nil
5053
}
5154

rolling-shutter/keyperimpl/optimism/bootstrap/keyperset.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package bootstrap
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"os"
78

89
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync"
10+
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/event"
911
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/encodeable/number"
1012
)
1113

@@ -17,7 +19,19 @@ func GetKeyperSet(ctx context.Context, config *Config) error {
1719
if err != nil {
1820
return err
1921
}
20-
keyperSet, err := sl2.GetKeyperSetForBlock(ctx, number.LatestBlock)
22+
var keyperSet *event.KeyperSet
23+
switch {
24+
case config.ByIndex == nil && config.ByActivationBlockNumber == nil:
25+
keyperSet, err = sl2.GetKeyperSetForBlock(ctx, number.LatestBlock)
26+
case config.ByIndex == nil && config.ByActivationBlockNumber != nil:
27+
keyperSet, err = sl2.GetKeyperSetForBlock(ctx, config.ByActivationBlockNumber)
28+
case config.ByIndex != nil && config.ByActivationBlockNumber == nil:
29+
keyperSet, err = sl2.GetKeyperSetByIndex(ctx, *config.ByIndex)
30+
case config.ByIndex != nil && config.ByActivationBlockNumber != nil:
31+
return errors.New("can only retrieve keyper set by either index or activation-blocknumber")
32+
default:
33+
return nil
34+
}
2135
if err != nil {
2236
return err
2337
}

rolling-shutter/keyperimpl/optimism/sync/client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ func (s *ShutterL2Client) GetShutterState(ctx context.Context) (*event.ShutterSt
104104
return s.sssync.GetShutterState(ctx, opts)
105105
}
106106

107+
func (s *ShutterL2Client) GetKeyperSetByIndex(ctx context.Context, index uint64) (*event.KeyperSet, error) {
108+
if s.kssync == nil {
109+
return nil, errors.Wrap(ErrServiceNotInstantiated, "KeyperSetSyncer service not instantiated")
110+
}
111+
opts := &bind.CallOpts{
112+
Context: ctx,
113+
}
114+
return s.kssync.GetKeyperSetByIndex(ctx, opts, index)
115+
}
116+
107117
func (s *ShutterL2Client) GetKeyperSetForBlock(ctx context.Context, b *number.BlockNumber) (*event.KeyperSet, error) {
108118
if s.kssync == nil {
109119
return nil, errors.Wrap(ErrServiceNotInstantiated, "KeyperSetSyncer service not instantiated")

rolling-shutter/keyperimpl/optimism/sync/syncer/keyperset.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@ func (s *KeyperSetSyncer) Start(ctx context.Context, runner service.Runner) erro
5555
return nil
5656
}
5757

58+
func (s *KeyperSetSyncer) GetKeyperSetByIndex(ctx context.Context, opts *bind.CallOpts, index uint64) (*event.KeyperSet, error) {
59+
if opts == nil {
60+
opts = &bind.CallOpts{
61+
Context: ctx,
62+
}
63+
}
64+
actBl, err := s.Contract.GetKeyperSetActivationBlock(opts, index)
65+
if err != nil {
66+
return nil, errors.Wrap(err, "could not retrieve keyper set activation block")
67+
}
68+
addr, err := s.Contract.GetKeyperSetAddress(opts, index)
69+
if err != nil {
70+
return nil, errors.Wrap(err, "could not retrieve keyper set address")
71+
}
72+
return s.newEvent(ctx, opts, addr, actBl)
73+
}
74+
5875
func (s *KeyperSetSyncer) GetKeyperSetForBlock(ctx context.Context, opts *bind.CallOpts, b *number.BlockNumber) (*event.KeyperSet, error) {
5976
if b.Equal(number.LatestBlock) {
6077
latestBlock, err := s.Client.BlockNumber(ctx)
@@ -73,15 +90,7 @@ func (s *KeyperSetSyncer) GetKeyperSetForBlock(ctx context.Context, opts *bind.C
7390
if err != nil {
7491
return nil, errors.Wrap(err, "could not retrieve keyper set index")
7592
}
76-
actBl, err := s.Contract.GetKeyperSetActivationBlock(opts, idx)
77-
if err != nil {
78-
return nil, errors.Wrap(err, "could not retrieve keyper set activation block")
79-
}
80-
addr, err := s.Contract.GetKeyperSetAddress(opts, idx)
81-
if err != nil {
82-
return nil, errors.Wrap(err, "could not retrieve keyper set address")
83-
}
84-
return s.newEvent(ctx, opts, addr, actBl)
93+
return s.GetKeyperSetByIndex(ctx, opts, idx)
8594
}
8695

8796
func (s *KeyperSetSyncer) newEvent(

0 commit comments

Comments
 (0)