eth/backend: updated updateFilterMapsHeads

This commit is contained in:
Zsolt Felfoldi 2025-03-12 18:04:33 +01:00
parent f30ec81ef8
commit 9c42b48bad

View file

@ -411,11 +411,11 @@ func (s *Ethereum) Start() error {
return nil return nil
} }
func (s *Ethereum) newChainView(head *types.Header) *filtermaps.StoredChainView { func (s *Ethereum) newChainView(head *types.Header) *filtermaps.ChainView {
if head == nil { if head == nil {
return nil return nil
} }
return filtermaps.NewStoredChainView(s.blockchain, head.Number.Uint64(), head.Hash()) return filtermaps.NewChainView(s.blockchain, head.Number.Uint64(), head.Hash())
} }
func (s *Ethereum) updateFilterMapsHeads() { func (s *Ethereum) updateFilterMapsHeads() {
@ -437,11 +437,8 @@ func (s *Ethereum) updateFilterMapsHeads() {
}() }()
head := s.blockchain.CurrentBlock() head := s.blockchain.CurrentBlock()
targetView := s.newChainView(head) // nil if already sent to channel s.filterMaps.SetTargetView(s.newChainView(head))
var ( var lastFinalBlock uint64
blockProc, lastBlockProc bool
finalBlock, lastFinal uint64
)
setHead := func(newHead *types.Header) { setHead := func(newHead *types.Header) {
if newHead == nil { if newHead == nil {
@ -449,65 +446,28 @@ func (s *Ethereum) updateFilterMapsHeads() {
} }
if head == nil || newHead.Hash() != head.Hash() { if head == nil || newHead.Hash() != head.Hash() {
head = newHead head = newHead
targetView = s.newChainView(head) s.filterMaps.SetTargetView(s.newChainView(head))
} }
if fb := s.blockchain.CurrentFinalBlock(); fb != nil { if fb := s.blockchain.CurrentFinalBlock(); fb != nil {
finalBlock = fb.Number.Uint64() if finalBlock := fb.Number.Uint64(); finalBlock != lastFinalBlock {
s.filterMaps.SetFinalBlock(finalBlock)
lastFinalBlock = finalBlock
}
} }
} }
for { for {
if blockProc != lastBlockProc {
select { select {
case s.filterMaps.BlockProcessingCh <- blockProc:
lastBlockProc = blockProc
case ev := <-headEventCh: case ev := <-headEventCh:
setHead(ev.Header) setHead(ev.Header)
case blockProc = <-blockProcCh: case blockProc := <-blockProcCh:
s.filterMaps.SetBlockProcessing(blockProc)
case <-time.After(time.Second * 10): case <-time.After(time.Second * 10):
setHead(s.blockchain.CurrentBlock()) setHead(s.blockchain.CurrentBlock())
case ch := <-s.closeFilterMaps: case ch := <-s.closeFilterMaps:
close(ch) close(ch)
return return
} }
} else if targetView != nil {
select {
case s.filterMaps.TargetViewCh <- targetView:
targetView = nil
case ev := <-headEventCh:
setHead(ev.Header)
case blockProc = <-blockProcCh:
case <-time.After(time.Second * 10):
setHead(s.blockchain.CurrentBlock())
case ch := <-s.closeFilterMaps:
close(ch)
return
}
} else if finalBlock != lastFinal {
select {
case s.filterMaps.FinalBlockCh <- finalBlock:
lastFinal = finalBlock
case ev := <-headEventCh:
setHead(ev.Header)
case blockProc = <-blockProcCh:
case <-time.After(time.Second * 10):
setHead(s.blockchain.CurrentBlock())
case ch := <-s.closeFilterMaps:
close(ch)
return
}
} else {
select {
case ev := <-headEventCh:
setHead(ev.Header)
case <-time.After(time.Second * 10):
setHead(s.blockchain.CurrentBlock())
case blockProc = <-blockProcCh:
case ch := <-s.closeFilterMaps:
close(ch)
return
}
}
} }
} }