Skip to content

Commit 79dbc5a

Browse files
feat: created generic syncmonitor package in medley and updated gnosis and api keyper services
1 parent 7db3da8 commit 79dbc5a

File tree

8 files changed

+156
-324
lines changed

8 files changed

+156
-324
lines changed

rolling-shutter/keyperimpl/gnosis/keyper.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/db"
2626
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/service"
2727
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/slotticker"
28+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/syncmonitor"
2829
"github.com/shutter-network/rolling-shutter/rolling-shutter/p2p"
2930
)
3031

@@ -49,7 +50,7 @@ type Keyper struct {
4950
validatorSyncer *ValidatorSyncer
5051
eonKeyPublisher *eonkeypublisher.EonKeyPublisher
5152
latestTriggeredSlot *uint64
52-
syncMonitor *SyncMonitor
53+
syncMonitor *syncmonitor.SyncMonitor
5354

5455
// input events
5556
newBlocks chan *syncevent.LatestBlock
@@ -63,8 +64,7 @@ type Keyper struct {
6364

6465
func New(c *Config) *Keyper {
6566
return &Keyper{
66-
config: c,
67-
syncMonitor: &SyncMonitor{},
67+
config: c,
6868
}
6969
}
7070

@@ -156,9 +156,12 @@ func (kpr *Keyper) Start(ctx context.Context, runner service.Runner) error {
156156
return errors.Wrap(err, "failed to reset transaction pointer age")
157157
}
158158

159-
kpr.syncMonitor = &SyncMonitor{
159+
kpr.syncMonitor = &syncmonitor.SyncMonitor{
160160
DBPool: kpr.dbpool,
161161
CheckInterval: time.Duration(kpr.config.Gnosis.SyncMonitorCheckInterval) * time.Second,
162+
SyncState: &GnosisSyncState{
163+
kpr.dbpool,
164+
},
162165
}
163166

164167
runner.Go(func() error { return kpr.processInputs(ctx) })

rolling-shutter/keyperimpl/gnosis/syncmonitor.go

Lines changed: 0 additions & 64 deletions
This file was deleted.

rolling-shutter/keyperimpl/gnosis/syncmonitor_test.go

Lines changed: 0 additions & 146 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package gnosis
2+
3+
import (
4+
"context"
5+
6+
"github.com/jackc/pgx/v4/pgxpool"
7+
8+
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/gnosis/database"
9+
)
10+
11+
// GnosisSyncState implements the BlockSyncState interface for the gnosis keyper
12+
type GnosisSyncState struct {
13+
DBPool *pgxpool.Pool
14+
}
15+
16+
// GetSyncedBlockNumber retrieves the current synced block number from transaction submitted events
17+
func (s *GnosisSyncState) GetSyncedBlockNumber(ctx context.Context) (int64, error) {
18+
db := database.New(s.DBPool)
19+
record, err := db.GetTransactionSubmittedEventsSyncedUntil(ctx)
20+
if err != nil {
21+
return 0, err
22+
}
23+
return record.BlockNumber, nil
24+
}

rolling-shutter/keyperimpl/shutterservice/keyper.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
syncevent "github.com/shutter-network/rolling-shutter/rolling-shutter/medley/chainsync/event"
2323
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/db"
2424
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/service"
25+
"github.com/shutter-network/rolling-shutter/rolling-shutter/medley/syncmonitor"
2526
"github.com/shutter-network/rolling-shutter/rolling-shutter/p2p"
2627
)
2728

@@ -36,7 +37,7 @@ type Keyper struct {
3637
registrySyncer *RegistrySyncer
3738
eonKeyPublisher *eonkeypublisher.EonKeyPublisher
3839
latestTriggeredTime *uint64
39-
syncMonitor *SyncMonitor
40+
syncMonitor *syncmonitor.SyncMonitor
4041

4142
// input events
4243
newBlocks chan *syncevent.LatestBlock
@@ -113,10 +114,14 @@ func (kpr *Keyper) Start(ctx context.Context, runner service.Runner) error {
113114
return err
114115
}
115116

116-
kpr.syncMonitor = &SyncMonitor{
117+
kpr.syncMonitor = &syncmonitor.SyncMonitor{
117118
DBPool: kpr.dbpool,
118119
CheckInterval: time.Duration(kpr.config.Chain.SyncMonitorCheckInterval) * time.Second,
120+
SyncState: &ShutterServiceSyncState{
121+
kpr.dbpool,
122+
},
119123
}
124+
120125
runner.Go(func() error { return kpr.processInputs(ctx) })
121126
return runner.StartService(kpr.core, kpr.chainSyncClient, kpr.eonKeyPublisher, kpr.syncMonitor)
122127
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package shutterservice
2+
3+
import (
4+
"context"
5+
6+
"github.com/jackc/pgx/v4/pgxpool"
7+
8+
"github.com/shutter-network/rolling-shutter/rolling-shutter/keyperimpl/shutterservice/database"
9+
)
10+
11+
// ShutterServiceSyncState implements the BlockSyncState interface for the shutter service
12+
type ShutterServiceSyncState struct {
13+
DBPool *pgxpool.Pool
14+
}
15+
16+
// GetSyncedBlockNumber retrieves the current synced block number from identity events
17+
func (s *ShutterServiceSyncState) GetSyncedBlockNumber(ctx context.Context) (int64, error) {
18+
db := database.New(s.DBPool)
19+
record, err := db.GetIdentityRegisteredEventsSyncedUntil(ctx)
20+
if err != nil {
21+
return 0, err
22+
}
23+
return record.BlockNumber, nil
24+
}

0 commit comments

Comments
 (0)