Skip to content

Commit 0a0280e

Browse files
committed
chore!: move syncer to medley
1 parent 1806f0d commit 0a0280e

File tree

13 files changed

+49
-57
lines changed

13 files changed

+49
-57
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/tendermint/tendermint/rpc/client/http"
1111

1212
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/fx"
13-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/event"
13+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/event"
1414
"github.com/shutter-network/rolling-shutter/rolling-shutter/shmsg"
1515
)
1616

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66
"errors"
77
"os"
88

9-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync"
10-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/event"
9+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync"
10+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/event"
1111
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/encodeable/number"
1212
)
1313

1414
func GetKeyperSet(ctx context.Context, config *Config) error {
15-
sl2, err := sync.NewShutterL2Client(
15+
sl2, err := chainsync.NewClient(
1616
ctx,
17-
sync.WithClientURL(config.JSONRPCURL),
17+
chainsync.WithClientURL(config.JSONRPCURL),
1818
)
1919
if err != nil {
2020
return err

rolling-shutter/keyperimpl/optimism/keyper.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyper/kprconfig"
1616
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/config"
1717
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/database"
18-
shopclient "github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync"
19-
shopevent "github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/event"
2018
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley"
2119
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/broker"
20+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync"
21+
syncevent "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/event"
2222
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/configuration"
2323
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/db"
2424
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/identitypreimage"
@@ -30,7 +30,7 @@ var ErrParseKeyperSet = errors.New("can't parse KeyperSet")
3030

3131
type Keyper struct {
3232
core *keyper.KeyperCore
33-
l2Client *shopclient.ShutterL2Client
33+
l2Client *chainsync.Client
3434
dbpool *pgxpool.Pool
3535
config *config.Config
3636

@@ -78,20 +78,20 @@ func (kpr *Keyper) Start(ctx context.Context, runner service.Runner) error {
7878
return errors.Wrap(err, "can't instantiate keyper core")
7979
}
8080
// TODO: wrap the logger and pass in
81-
kpr.l2Client, err = shopclient.NewShutterL2Client(
81+
kpr.l2Client, err = chainsync.NewClient(
8282
ctx,
83-
shopclient.WithClientURL(kpr.config.Optimism.JSONRPCURL),
84-
shopclient.WithSyncNewBlock(kpr.newBlock),
85-
shopclient.WithSyncNewKeyperSet(kpr.newKeyperSet),
86-
shopclient.WithPrivateKey(kpr.config.Optimism.PrivateKey.Key),
83+
chainsync.WithClientURL(kpr.config.Optimism.JSONRPCURL),
84+
chainsync.WithSyncNewBlock(kpr.newBlock),
85+
chainsync.WithSyncNewKeyperSet(kpr.newKeyperSet),
86+
chainsync.WithPrivateKey(kpr.config.Optimism.PrivateKey.Key),
8787
)
8888
if err != nil {
8989
return err
9090
}
9191
return runner.StartService(kpr.core, kpr.l2Client)
9292
}
9393

94-
func (kpr *Keyper) newBlock(_ context.Context, ev *shopevent.LatestBlock) error {
94+
func (kpr *Keyper) newBlock(_ context.Context, ev *syncevent.LatestBlock) error {
9595
log.Info().
9696
Int64("number", ev.Number.Int64()).
9797
Str("hash", ev.BlockHash.Hex()).
@@ -110,7 +110,7 @@ func (kpr *Keyper) newBlock(_ context.Context, ev *shopevent.LatestBlock) error
110110
return nil
111111
}
112112

113-
func (kpr *Keyper) newKeyperSet(ctx context.Context, ev *shopevent.KeyperSet) error {
113+
func (kpr *Keyper) newKeyperSet(ctx context.Context, ev *syncevent.KeyperSet) error {
114114
log.Info().
115115
Uint64("activation-block", ev.ActivationBlock).
116116
Uint64("eon", ev.Eon).

rolling-shutter/keyperimpl/optimism/sync/client.go renamed to rolling-shutter/medley/chainsync/client.go

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
package sync
1+
package chainsync
22

33
import (
44
"context"
55
"crypto/ecdsa"
6-
"io"
76
"math/big"
87

98
"github.com/ethereum/go-ethereum/accounts/abi/bind"
@@ -12,25 +11,19 @@ import (
1211
"github.com/pkg/errors"
1312
"github.com/shutter-network/shop-contracts/bindings"
1413

15-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/client"
16-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/event"
17-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/syncer"
14+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/client"
15+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/event"
16+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/syncer"
1817
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/encodeable/number"
1918
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/logger"
2019
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/service"
2120
)
2221

2322
var noopLogger = &logger.NoopLogger{}
2423

25-
var ErrServiceNotInstantiated = errors.New("service is not instantiated, pass a handler function option.")
24+
var ErrServiceNotInstantiated = errors.New("service is not instantiated, pass a handler function option")
2625

27-
type ShutterSync interface {
28-
io.Closer
29-
// Start starts an additional worker syncing job
30-
Start() error
31-
}
32-
33-
type ShutterL2Client struct {
26+
type Client struct {
3427
client.Client
3528
log log.Logger
3629

@@ -49,7 +42,7 @@ type ShutterL2Client struct {
4942
services []service.Service
5043
}
5144

52-
func NewShutterL2Client(ctx context.Context, options ...Option) (*ShutterL2Client, error) {
45+
func NewClient(ctx context.Context, options ...Option) (*Client, error) {
5346
opts := defaultOptions()
5447
for _, option := range options {
5548
err := option(opts)
@@ -63,7 +56,7 @@ func NewShutterL2Client(ctx context.Context, options ...Option) (*ShutterL2Clien
6356
return nil, err
6457
}
6558

66-
c := &ShutterL2Client{
59+
c := &Client{
6760
log: noopLogger,
6861
services: []service.Service{},
6962
}
@@ -75,11 +68,11 @@ func NewShutterL2Client(ctx context.Context, options ...Option) (*ShutterL2Clien
7568
return c, nil
7669
}
7770

78-
func (s *ShutterL2Client) getServices() []service.Service {
71+
func (s *Client) getServices() []service.Service {
7972
return s.services
8073
}
8174

82-
func (s *ShutterL2Client) GetShutterState(ctx context.Context) (*event.ShutterState, error) {
75+
func (s *Client) GetShutterState(ctx context.Context) (*event.ShutterState, error) {
8376
if s.sssync == nil {
8477
return nil, errors.Wrap(ErrServiceNotInstantiated, "ShutterStateSyncer service not instantiated")
8578
}
@@ -89,7 +82,7 @@ func (s *ShutterL2Client) GetShutterState(ctx context.Context) (*event.ShutterSt
8982
return s.sssync.GetShutterState(ctx, opts)
9083
}
9184

92-
func (s *ShutterL2Client) GetKeyperSetByIndex(ctx context.Context, index uint64) (*event.KeyperSet, error) {
85+
func (s *Client) GetKeyperSetByIndex(ctx context.Context, index uint64) (*event.KeyperSet, error) {
9386
if s.kssync == nil {
9487
return nil, errors.Wrap(ErrServiceNotInstantiated, "KeyperSetSyncer service not instantiated")
9588
}
@@ -99,7 +92,7 @@ func (s *ShutterL2Client) GetKeyperSetByIndex(ctx context.Context, index uint64)
9992
return s.kssync.GetKeyperSetByIndex(ctx, opts, index)
10093
}
10194

102-
func (s *ShutterL2Client) GetKeyperSetForBlock(ctx context.Context, b *number.BlockNumber) (*event.KeyperSet, error) {
95+
func (s *Client) GetKeyperSetForBlock(ctx context.Context, b *number.BlockNumber) (*event.KeyperSet, error) {
10396
if s.kssync == nil {
10497
return nil, errors.Wrap(ErrServiceNotInstantiated, "KeyperSetSyncer service not instantiated")
10598
}
@@ -109,7 +102,7 @@ func (s *ShutterL2Client) GetKeyperSetForBlock(ctx context.Context, b *number.Bl
109102
return s.kssync.GetKeyperSetForBlock(ctx, opts, b)
110103
}
111104

112-
func (s *ShutterL2Client) GetEonPubKeyForEon(ctx context.Context, eon uint64) (*event.EonPublicKey, error) {
105+
func (s *Client) GetEonPubKeyForEon(ctx context.Context, eon uint64) (*event.EonPublicKey, error) {
113106
if s.sssync == nil {
114107
return nil, errors.Wrap(ErrServiceNotInstantiated, "ShutterStateSyncer service not instantiated")
115108
}
@@ -119,8 +112,9 @@ func (s *ShutterL2Client) GetEonPubKeyForEon(ctx context.Context, eon uint64) (*
119112
return s.epksync.GetEonPubKeyForEon(ctx, opts, eon)
120113
}
121114

122-
func (s *ShutterL2Client) BroadcastEonKey(ctx context.Context, eon uint64, eonPubKey []byte) (*types.Transaction, error) {
123-
// TODO: first do a getEonKey. If we already have something (ideally the same)
115+
func (s *Client) BroadcastEonKey(ctx context.Context, eon uint64, eonPubKey []byte) (*types.Transaction, error) {
116+
// TODO: first do a getEonKey. If we already have this key, do nothing,
117+
// if we have a different key, error
124118
// don't do a transaction
125119
// s.KeyBroadcast.GetEonKey(eon)
126120
if s.privKey == nil {
@@ -140,7 +134,7 @@ func (s *ShutterL2Client) BroadcastEonKey(ctx context.Context, eon uint64, eonPu
140134

141135
// ChainID returns the chainid of the underlying L2 chain.
142136
// This value is cached, since it is not expected to change.
143-
func (s *ShutterL2Client) ChainID(ctx context.Context) (*big.Int, error) {
137+
func (s *Client) ChainID(ctx context.Context) (*big.Int, error) {
144138
if s.chainID == nil {
145139
cid, err := s.Client.ChainID(ctx)
146140
if err != nil {
@@ -151,6 +145,6 @@ func (s *ShutterL2Client) ChainID(ctx context.Context) (*big.Int, error) {
151145
return s.chainID, nil
152146
}
153147

154-
func (s *ShutterL2Client) Start(_ context.Context, runner service.Runner) error {
148+
func (s *Client) Start(_ context.Context, runner service.Runner) error {
155149
return runner.StartService(s.getServices()...)
156150
}

rolling-shutter/keyperimpl/optimism/sync/options.go renamed to rolling-shutter/medley/chainsync/options.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package sync
1+
package chainsync
22

33
import (
44
"context"
@@ -11,9 +11,9 @@ import (
1111
"github.com/shutter-network/shop-contracts/bindings"
1212
"github.com/shutter-network/shop-contracts/predeploy"
1313

14-
syncclient "github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/client"
15-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/event"
16-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/syncer"
14+
syncclient "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/client"
15+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/event"
16+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/syncer"
1717
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/encodeable/number"
1818
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/service"
1919
)
@@ -54,7 +54,7 @@ func (o *options) verify() error {
5454
// the context is only the initialisation context,
5555
// and should not be considered to handle the lifecycle
5656
// of shutter clients background workers.
57-
func (o *options) apply(ctx context.Context, c *ShutterL2Client) error {
57+
func (o *options) apply(ctx context.Context, c *Client) error {
5858
var (
5959
client syncclient.Client
6060
err error

rolling-shutter/keyperimpl/optimism/sync/syncer/eonpubkey.go renamed to rolling-shutter/medley/chainsync/syncer/eonpubkey.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/ethereum/go-ethereum/log"
1010
"github.com/shutter-network/shop-contracts/bindings"
1111

12-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/client"
13-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/event"
12+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/client"
13+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/event"
1414
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/encodeable/number"
1515
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/service"
1616
)

rolling-shutter/keyperimpl/optimism/sync/syncer/keyperset.go renamed to rolling-shutter/medley/chainsync/syncer/keyperset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/pkg/errors"
1010
"github.com/shutter-network/shop-contracts/bindings"
1111

12-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/client"
13-
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/optimism/sync/event"
12+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/client"
13+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/event"
1414
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/encodeable/number"
1515
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/service"
1616
)
@@ -166,7 +166,7 @@ func (s *KeyperSetSyncer) GetKeyperSetForBlock(ctx context.Context, opts *bind.C
166166
}
167167

168168
func (s *KeyperSetSyncer) newEvent(
169-
ctx context.Context,
169+
_ context.Context,
170170
opts *bind.CallOpts,
171171
keyperSetContract common.Address,
172172
activationBlock uint64,

0 commit comments

Comments
 (0)