Skip to content

Commit

Permalink
add head listener log & adjust expected block interval multiplier
Browse files Browse the repository at this point in the history
  • Loading branch information
marino39 committed Apr 12, 2024
1 parent 52ba609 commit 4998f7f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ethmonitor/ethmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
if m.provider.IsStreamingEnabled() && streamingErrorCount < m.options.ErrorNumToSwitchToPolling {
// Streaming mode if available, where we listen for new heads
// and push the new block number to the nextBlock channel.
m.log.Info("ethmonitor: starting stream head listener")

newHeads := make(chan *types.Header)
sub, err := m.provider.SubscribeNewHeads(m.ctx, newHeads)
if err != nil {
Expand All @@ -323,7 +325,7 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
goto reconnect
}

blockTimer := time.NewTimer(2 * m.options.ExpectedBlockInterval)
blockTimer := time.NewTimer(3 * m.options.ExpectedBlockInterval)
for {
select {
case <-m.ctx.Done():
Expand All @@ -350,7 +352,7 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
goto reconnect

case newHead := <-newHeads:
blockTimer.Reset(2 * m.options.ExpectedBlockInterval)
blockTimer.Reset(3 * m.options.ExpectedBlockInterval)

latestHeadBlock.Store(newHead.Number.Uint64())
select {
Expand All @@ -362,6 +364,8 @@ func (m *Monitor) listenNewHead() <-chan uint64 {
}
} else {
// We default to polling if streaming is not enabled
m.log.Info("ethmonitor: starting poll head listener")

for {
select {
case <-m.ctx.Done():
Expand Down

0 comments on commit 4998f7f

Please sign in to comment.