Skip to content

Commit 2e42409

Browse files
committed
Add chain id in logging
1 parent 33a3deb commit 2e42409

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/blockchain/ethereum.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ func (e *EthereumClient) InitializeHeaderSubscription() error {
13251325

13261326
// startPollingHeaders starts a polling loop to fetch new headers at regular intervals
13271327
func (e *EthereumClient) startHeaderPolling() error {
1328-
e.l.Info().Msg("Starting Polling Headers")
1328+
e.l.Info().Int64("Chain Id", e.GetChainID().Int64()).Msg("Starting Polling Headers")
13291329
// pollInterval := time.Second * 30
13301330
chainPollingRegistry.Lock()
13311331
pollInterval := chainPollingRegistry.m[e.GetChainID().Int64()].pollInterval
@@ -1338,17 +1338,17 @@ func (e *EthereumClient) startHeaderPolling() error {
13381338
initCtx, initCancel := context.WithTimeout(context.Background(), e.NetworkConfig.Timeout.Duration)
13391339
defer initCancel()
13401340

1341-
e.l.Info().Msg("Attempting to fetch latest header during initialization")
1341+
e.l.Info().Int64("Chain Id", e.GetChainID().Int64()).Msg("Attempting to fetch latest header during initialization")
13421342
latestHeader, err := e.HeaderByNumber(initCtx, nil) // Fetch the latest header
13431343
if err != nil {
1344-
e.l.Error().Err(err).Msg("Failed to fetch the latest header during initialization")
1344+
e.l.Error().Int64("Chain Id", e.GetChainID().Int64()).Err(err).Msg("Failed to fetch the latest header during initialization")
13451345
return fmt.Errorf("failed to fetch the latest header during initialization: %w", err)
13461346
}
1347-
e.l.Info().Str("HeaderHash", latestHeader.Hash.String()).Msg("Successfully fetched latest header during initialization")
1347+
e.l.Info().Int64("Chain Id", e.GetChainID().Int64()).Str("HeaderHash", latestHeader.Hash.String()).Msg("Successfully fetched latest header during initialization")
13481348

13491349
go func() {
13501350
defer e.subscriptionWg.Done()
1351-
e.l.Info().Msg("Polling for headers goroutine started")
1351+
e.l.Info().Int64("Chain Id", e.GetChainID().Int64()).Msg("Polling for headers goroutine started")
13521352
// Initialize lastHeaderNumber dynamically
13531353
lastHeaderNumber := latestHeader.Number.Uint64() - 1
13541354
for {
@@ -1358,28 +1358,28 @@ func (e *EthereumClient) startHeaderPolling() error {
13581358
e.sharedPoller.mu.Lock()
13591359
now := time.Now()
13601360
if now.Sub(e.sharedPoller.lastPolled) < e.sharedPoller.pollInterval || e.sharedPoller.fetching {
1361-
e.l.Debug().Msg("Not my time to poll, skipping")
1361+
e.l.Debug().Int64("Chain Id", e.GetChainID().Int64()).Msg("Not my time to poll, skipping")
13621362
e.sharedPoller.mu.Unlock()
13631363
continue
13641364
}
13651365
e.sharedPoller.lastPolled = now
13661366
e.sharedPoller.fetching = true
13671367
e.sharedPoller.mu.Unlock()
13681368

1369-
e.l.Debug().Msg("Polling Headers")
1369+
e.l.Debug().Int64("Chain Id", e.GetChainID().Int64()).Msg("Polling Headers")
13701370

13711371
// Create a new context with timeout for each HeaderByNumber call
13721372
pollCtx, pollCancel := context.WithTimeout(context.Background(), e.NetworkConfig.Timeout.Duration)
13731373
latestHeader, err := e.HeaderByNumber(pollCtx, nil) // nil gets the latest header
13741374
pollCancel()
13751375

13761376
if err != nil {
1377-
e.l.Error().Err(err).Msg("Error fetching latest header during polling")
1377+
e.l.Error().Int64("Chain Id", e.GetChainID().Int64()).Err(err).Msg("Error fetching latest header during polling")
13781378
continue
13791379
}
13801380

13811381
if latestHeader.Number.Uint64() > lastHeaderNumber {
1382-
e.l.Info().Uint64("LatestHeaderNumber", latestHeader.Number.Uint64()).Msg("New headers detected")
1382+
e.l.Info().Int64("Chain Id", e.GetChainID().Int64()).Uint64("LatestHeaderNumber", latestHeader.Number.Uint64()).Msg("New headers detected")
13831383
// Process headers from (lastHeaderNumber + 1) to latestHeader.Number
13841384
// We may need to add a rate limiter, if we run into issues.
13851385
for blockNum := lastHeaderNumber + 1; blockNum <= latestHeader.Number.Uint64(); blockNum++ {
@@ -1388,24 +1388,24 @@ func (e *EthereumClient) startHeaderPolling() error {
13881388
header, err := e.HeaderByNumber(blockCtx, big.NewInt(int64(blockNum)))
13891389
blockCancel()
13901390
if err != nil {
1391-
e.l.Error().Err(err).Uint64("BlockNumber", blockNum).Msg("Error fetching header during range processing")
1391+
e.l.Error().Int64("Chain Id", e.GetChainID().Int64()).Err(err).Uint64("BlockNumber", blockNum).Msg("Error fetching header during range processing")
13921392
continue
13931393
}
13941394

13951395
lastHeaderNumber = header.Number.Uint64()
13961396

13971397
if err := e.receiveHeader(header); err != nil {
1398-
e.l.Error().Err(err).Uint64("BlockNumber", blockNum).Msg("Error processing header")
1398+
e.l.Error().Int64("Chain Id", e.GetChainID().Int64()).Err(err).Uint64("BlockNumber", blockNum).Msg("Error processing header")
13991399
continue
14001400
}
1401-
e.l.Debug().Uint64("BlockNumber", blockNum).Msg("Processing header")
1401+
e.l.Debug().Int64("Chain Id", e.GetChainID().Int64()).Uint64("BlockNumber", blockNum).Msg("Processing header")
14021402
}
14031403
}
14041404
e.sharedPoller.mu.Lock()
14051405
e.sharedPoller.fetching = false
14061406
e.sharedPoller.mu.Unlock()
14071407
case <-e.doneChan:
1408-
e.l.Debug().Str("Network", e.NetworkConfig.Name).Msg("Polling loop cancelled")
1408+
e.l.Debug().Int64("Chain Id", e.GetChainID().Int64()).Str("Network", e.NetworkConfig.Name).Msg("Polling loop cancelled")
14091409
ticker.Stop()
14101410
e.Client.Close()
14111411
return

0 commit comments

Comments
 (0)