Skip to content

Commit d903889

Browse files
authored
ethmonitor: ensure trail is always distance apart from head, or do no… (#23)
1 parent 2e17514 commit d903889

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

ethmonitor/chain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (c *Chain) Head() *Block {
8080
}
8181

8282
func (c *Chain) Blocks() []*Block {
83+
// TODO: this lock is pointless
8384
c.mu.Lock()
8485
defer c.mu.Unlock()
8586
return c.blocks

ethmonitor/ethmonitor.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,14 @@ func (m *Monitor) broadcast(events Blocks) {
378378
return
379379
}
380380

381+
head := m.chain.Head()
382+
381383
if m.sentBlockNumber == nil {
382-
m.sentBlockNumber = big.NewInt(0).SetUint64(m.chain.Head().NumberU64() - uint64(numBlocksBehindHead))
384+
m.sentBlockNumber = big.NewInt(0).Sub(head.Number(), big.NewInt(int64(numBlocksBehindHead+1)))
385+
}
386+
387+
if big.NewInt(0).Sub(head.Number(), m.sentBlockNumber).Cmp(big.NewInt(int64(numBlocksBehindHead))) < 0 {
388+
return
383389
} else {
384390
m.sentBlockNumber = big.NewInt(0).Add(m.sentBlockNumber, big.NewInt(1))
385391
}

0 commit comments

Comments
 (0)