@@ -59,14 +59,14 @@ type WatcherClient struct {
59
59
}
60
60
61
61
// NewL2WatcherClient take a l2geth instance to generate a l2watcherclient instance
62
- func NewL2WatcherClient (ctx context.Context , client * ethclient.Client , confirmations uint64 , bpCfg * config.BatchProposerConfig , messengerAddress common.Address , orm database.OrmFactory ) ( * WatcherClient , error ) {
62
+ func NewL2WatcherClient (ctx context.Context , client * ethclient.Client , confirmations uint64 , bpCfg * config.BatchProposerConfig , messengerAddress common.Address , orm database.OrmFactory ) * WatcherClient {
63
63
savedHeight , err := orm .GetLayer2LatestWatchedHeight ()
64
64
if err != nil {
65
65
log .Warn ("fetch height from db failed" , "err" , err )
66
66
savedHeight = 0
67
67
}
68
68
69
- watcher := & WatcherClient {
69
+ return & WatcherClient {
70
70
ctx : ctx ,
71
71
Client : client ,
72
72
orm : orm ,
@@ -78,20 +78,13 @@ func NewL2WatcherClient(ctx context.Context, client *ethclient.Client, confirmat
78
78
stopped : 0 ,
79
79
batchProposer : newBatchProposer (bpCfg , orm ),
80
80
}
81
- // Init cache, if traces in cache expired reset it.
82
- if err = watcher .initCache (ctx ); err != nil {
83
- log .Error ("failed to init cache in l2 watcher" )
84
- return nil , err
85
- }
86
-
87
- return watcher , nil
88
81
}
89
82
90
83
// Start the Listening process
91
84
func (w * WatcherClient ) Start () {
92
85
go func () {
93
86
if reflect .ValueOf (w .orm ).IsNil () {
94
- panic ("must run L2 watcher with Persistence " )
87
+ panic ("must run L2 watcher with DB " )
95
88
}
96
89
97
90
ctx , cancel := context .WithCancel (w .ctx )
@@ -184,7 +177,7 @@ const blockTracesFetchLimit = uint64(10)
184
177
185
178
// try fetch missing blocks if inconsistent
186
179
func (w * WatcherClient ) tryFetchRunningMissingBlocks (ctx context.Context , blockHeight uint64 ) {
187
- // Get newest block in Persistence . must have blocks at that time.
180
+ // Get newest block in DB . must have blocks at that time.
188
181
// Don't use "block_trace" table "trace" column's BlockTrace.Number,
189
182
// because it might be empty if the corresponding rollup_result is finalized/finalization_skipped
190
183
heightInDB , err := w .orm .GetBlockTracesLatestHeight ()
@@ -226,6 +219,7 @@ func (w *WatcherClient) getAndStoreBlockTraces(ctx context.Context, from, to uin
226
219
log .Info ("retrieved block trace" , "height" , trace .Header .Number , "hash" , trace .Header .Hash ().String ())
227
220
228
221
traces = append (traces , trace )
222
+
229
223
}
230
224
if len (traces ) > 0 {
231
225
if err := w .orm .InsertBlockTraces (traces ); err != nil {
@@ -238,7 +232,7 @@ func (w *WatcherClient) getAndStoreBlockTraces(ctx context.Context, from, to uin
238
232
239
233
const contractEventsBlocksFetchLimit = int64 (10 )
240
234
241
- // FetchContractEvent pull latest event logs from given contract address and save in Persistence
235
+ // FetchContractEvent pull latest event logs from given contract address and save in DB
242
236
func (w * WatcherClient ) FetchContractEvent (blockHeight uint64 ) {
243
237
defer func () {
244
238
log .Info ("l2 watcher fetchContractEvent" , "w.processedMsgHeight" , w .processedMsgHeight )
0 commit comments