Skip to content

Commit 01e94db

Browse files
committed
wip: minor changes and debug logging
1 parent 2643a0c commit 01e94db

File tree

8 files changed

+50
-20
lines changed

8 files changed

+50
-20
lines changed

rolling-shutter/medley/chainsync/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var noopLogger = &logger.NoopLogger{}
2424
var ErrServiceNotInstantiated = errors.New("service is not instantiated, pass a handler function option")
2525

2626
type Client struct {
27-
client.Client
27+
client.EthereumClient
2828
log log.Logger
2929

3030
options *options
@@ -136,7 +136,7 @@ func (s *Client) BroadcastEonKey(ctx context.Context, eon uint64, eonPubKey []by
136136
// This value is cached, since it is not expected to change.
137137
func (s *Client) ChainID(ctx context.Context) (*big.Int, error) {
138138
if s.chainID == nil {
139-
cid, err := s.Client.ChainID(ctx)
139+
cid, err := s.EthereumClient.ChainID(ctx)
140140
if err != nil {
141141
return nil, err
142142
}

rolling-shutter/medley/chainsync/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/ethereum/go-ethereum/core/types"
1010
)
1111

12-
type Client interface {
12+
type EthereumClient interface {
1313
Close()
1414
ChainID(ctx context.Context) (*big.Int, error)
1515
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)

rolling-shutter/medley/chainsync/options.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type options struct {
2424
keyperSetManagerAddress *common.Address
2525
keyBroadcastContractAddress *common.Address
2626
clientURL string
27-
client syncclient.Client
27+
ethClient syncclient.EthereumClient
2828
logger log.Logger
2929
runner service.Runner
3030
syncStart *number.BlockNumber
@@ -37,11 +37,11 @@ type options struct {
3737
}
3838

3939
func (o *options) verify() error {
40-
if o.clientURL != "" && o.client != nil {
40+
if o.clientURL != "" && o.ethClient != nil {
4141
// TODO: error message
4242
return errors.New("can't use client and client url")
4343
}
44-
if o.clientURL == "" && o.client == nil {
44+
if o.clientURL == "" && o.ethClient == nil {
4545
// TODO: error message
4646
return errors.New("have to provide either url or client")
4747
}
@@ -56,25 +56,30 @@ func (o *options) verify() error {
5656
// of shutter clients background workers.
5757
func (o *options) apply(ctx context.Context, c *Client) error {
5858
var (
59-
client syncclient.Client
59+
client syncclient.EthereumClient
6060
err error
6161
)
6262
if o.clientURL != "" {
63-
o.client, err = ethclient.DialContext(ctx, o.clientURL)
63+
o.ethClient, err = ethclient.DialContext(ctx, o.clientURL)
6464
if err != nil {
6565
return err
6666
}
6767
}
68-
client = o.client
69-
c.log = o.logger
68+
client = o.ethClient
7069

71-
c.Client = client
70+
c.EthereumClient = client
71+
72+
if o.logger != nil {
73+
c.log = o.logger
74+
// NOCHECKIN:
75+
c.log.Info("got logger in options")
76+
}
7277

7378
syncedServices := []syncer.ManualFilterHandler{}
7479
// the nil passthrough will use "latest" for each call,
7580
// but we want to harmonize and fix the sync start to a specific block.
7681
if o.syncStart.IsLatest() {
77-
latestBlock, err := c.Client.BlockNumber(ctx)
82+
latestBlock, err := c.EthereumClient.BlockNumber(ctx)
7883
if err != nil {
7984
return errors.Wrap(err, "polling latest block")
8085
}
@@ -161,7 +166,7 @@ func defaultOptions() *options {
161166
keyperSetManagerAddress: &predeploy.KeyperSetManagerAddr,
162167
keyBroadcastContractAddress: &predeploy.KeyBroadcastContractAddr,
163168
clientURL: "",
164-
client: nil,
169+
ethClient: nil,
165170
logger: noopLogger,
166171
runner: nil,
167172
syncStart: number.NewBlockNumber(nil),
@@ -213,9 +218,9 @@ func WithLogger(l log.Logger) Option {
213218
}
214219
}
215220

216-
func WithClient(client syncclient.Client) Option {
221+
func WithClient(client syncclient.EthereumClient) Option {
217222
return func(o *options) error {
218-
o.client = client
223+
o.ethClient = client
219224
return nil
220225
}
221226
}

rolling-shutter/medley/chainsync/syncer/eonpubkey.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
var _ ManualFilterHandler = &EonPubKeySyncer{}
2020

2121
type EonPubKeySyncer struct {
22-
Client client.Client
22+
Client client.EthereumClient
2323
Log log.Logger
2424
KeyBroadcast *bindings.KeyBroadcastContract
2525
KeyperSetManager *bindings.KeyperSetManager
@@ -31,6 +31,11 @@ type EonPubKeySyncer struct {
3131
}
3232

3333
func (s *EonPubKeySyncer) QueryAndHandle(ctx context.Context, block uint64) error {
34+
s.Log.Info(
35+
"pubsyncer query and handle called",
36+
"block",
37+
block,
38+
)
3439
opts := &bind.FilterOpts{
3540
Start: block,
3641
End: &block,
@@ -56,6 +61,10 @@ func (s *EonPubKeySyncer) QueryAndHandle(ctx context.Context, block uint64) erro
5661
}
5762

5863
func (s *EonPubKeySyncer) Start(ctx context.Context, runner service.Runner) error {
64+
fmt.Println("pubsync looper started (println)")
65+
s.Log.Info(
66+
"pubsyncer loop started",
67+
)
5968
if s.Handler == nil {
6069
return errors.New("no handler registered")
6170
}
@@ -165,9 +174,15 @@ func (s *EonPubKeySyncer) watchNewEonPubkey(ctx context.Context) error {
165174
for {
166175
select {
167176
case newEonKey, ok := <-s.keyBroadcastCh:
177+
s.Log.Info(
178+
"pubsyncer received value",
179+
)
168180
if !ok {
169181
return nil
170182
}
183+
s.Log.Info(
184+
"pubsyncer channel ok",
185+
)
171186
// FIXME: this happens, why?
172187
if len(newEonKey.Key) == 0 {
173188
opts := &bind.CallOpts{
@@ -185,6 +200,10 @@ func (s *EonPubKeySyncer) watchNewEonPubkey(ctx context.Context) error {
185200
"eon",
186201
k,
187202
)
203+
} else {
204+
s.Log.Info(
205+
"pubsyncer key lenght ok",
206+
)
188207
}
189208
pubk := newEonKey.Key
190209
bn := newEonKey.Raw.BlockNumber
@@ -193,6 +212,11 @@ func (s *EonPubKeySyncer) watchNewEonPubkey(ctx context.Context) error {
193212
Key: pubk,
194213
AtBlockNumber: number.NewBlockNumber(&bn),
195214
}
215+
s.Log.Info(
216+
"pubsyncer constructed event",
217+
"event",
218+
ev,
219+
)
196220
err := s.Handler(ctx, ev)
197221
if err != nil {
198222
s.Log.Error(

rolling-shutter/medley/chainsync/syncer/keyperset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const channelSize = 10
2424
var _ ManualFilterHandler = &KeyperSetSyncer{}
2525

2626
type KeyperSetSyncer struct {
27-
Client client.Client
27+
Client client.EthereumClient
2828
Contract *bindings.KeyperSetManager
2929
Log log.Logger
3030
StartBlock *number.BlockNumber

rolling-shutter/medley/chainsync/syncer/shutterstate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
var _ ManualFilterHandler = &ShutterStateSyncer{}
1818

1919
type ShutterStateSyncer struct {
20-
Client client.Client
20+
Client client.EthereumClient
2121
Contract *bindings.KeyperSetManager
2222
StartBlock *number.BlockNumber
2323
Log log.Logger

rolling-shutter/medley/chainsync/syncer/unsafehead.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
type UnsafeHeadSyncer struct {
17-
Client client.Client
17+
Client client.EthereumClient
1818
Log log.Logger
1919
Handler event.BlockHandler
2020
// Handler to be manually triggered
@@ -26,6 +26,7 @@ type UnsafeHeadSyncer struct {
2626
}
2727

2828
func (s *UnsafeHeadSyncer) Start(ctx context.Context, runner service.Runner) error {
29+
s.Log.Info("unsafe head syncer started")
2930
if s.Handler == nil {
3031
return errors.New("no handler registered")
3132
}

rolling-shutter/medley/chainsync/syncer/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func guardCallOpts(opts *bind.CallOpts, allowLatest bool) error {
4444
return nil
4545
}
4646

47-
func fixCallOpts(ctx context.Context, c client.Client, opts *bind.CallOpts) (*bind.CallOpts, *uint64, error) {
47+
func fixCallOpts(ctx context.Context, c client.EthereumClient, opts *bind.CallOpts) (*bind.CallOpts, *uint64, error) {
4848
err := guardCallOpts(opts, false)
4949
if err == nil {
5050
return opts, nil, nil

0 commit comments

Comments
 (0)