mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
eth/backend: updated updateFilterMapsHeads
This commit is contained in:
parent
f30ec81ef8
commit
9c42b48bad
1 changed files with 19 additions and 59 deletions
|
|
@ -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,64 +446,27 @@ 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 ev := <-headEventCh:
|
||||||
case s.filterMaps.BlockProcessingCh <- blockProc:
|
setHead(ev.Header)
|
||||||
lastBlockProc = blockProc
|
case blockProc := <-blockProcCh:
|
||||||
case ev := <-headEventCh:
|
s.filterMaps.SetBlockProcessing(blockProc)
|
||||||
setHead(ev.Header)
|
case <-time.After(time.Second * 10):
|
||||||
case blockProc = <-blockProcCh:
|
setHead(s.blockchain.CurrentBlock())
|
||||||
case <-time.After(time.Second * 10):
|
case ch := <-s.closeFilterMaps:
|
||||||
setHead(s.blockchain.CurrentBlock())
|
close(ch)
|
||||||
case ch := <-s.closeFilterMaps:
|
return
|
||||||
close(ch)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue