mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core/filtermaps: do not use exported channels
This commit is contained in:
parent
4ece8f50f8
commit
61b17c3bce
3 changed files with 56 additions and 13 deletions
|
|
@ -91,9 +91,9 @@ type FilterMaps struct {
|
||||||
finalBlock, lastFinal uint64
|
finalBlock, lastFinal uint64
|
||||||
lastFinalEpoch uint32
|
lastFinalEpoch uint32
|
||||||
stop bool
|
stop bool
|
||||||
TargetViewCh chan *ChainView
|
targetViewCh chan *ChainView
|
||||||
FinalBlockCh chan uint64
|
finalBlockCh chan uint64
|
||||||
BlockProcessingCh chan bool
|
blockProcessingCh chan bool
|
||||||
blockProcessing bool
|
blockProcessing bool
|
||||||
matcherSyncCh chan *FilterMapsMatcherBackend
|
matcherSyncCh chan *FilterMapsMatcherBackend
|
||||||
waitIdleCh chan chan bool
|
waitIdleCh chan chan bool
|
||||||
|
|
@ -184,9 +184,9 @@ func NewFilterMaps(db ethdb.KeyValueStore, initView *ChainView, params Params, h
|
||||||
db: db,
|
db: db,
|
||||||
closeCh: make(chan struct{}),
|
closeCh: make(chan struct{}),
|
||||||
waitIdleCh: make(chan chan bool),
|
waitIdleCh: make(chan chan bool),
|
||||||
TargetViewCh: make(chan *ChainView),
|
targetViewCh: make(chan *ChainView, 1),
|
||||||
FinalBlockCh: make(chan uint64),
|
finalBlockCh: make(chan uint64, 1),
|
||||||
BlockProcessingCh: make(chan bool),
|
blockProcessingCh: make(chan bool, 1),
|
||||||
history: history,
|
history: history,
|
||||||
noHistory: noHistory,
|
noHistory: noHistory,
|
||||||
unindexLimit: unindexLimit,
|
unindexLimit: unindexLimit,
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,43 @@ func (f *FilterMaps) indexerLoop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetTargetView sets a new target chain view for the indexer to render.
|
||||||
|
// Note that SetTargetView never blocks.
|
||||||
|
func (f *FilterMaps) SetTargetView(targetView *ChainView) {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-f.targetViewCh:
|
||||||
|
case f.targetViewCh <- targetView:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFinalBlock sets the finalized block number used for exporting checkpoints.
|
||||||
|
// Note that SetFinalBlock never blocks.
|
||||||
|
func (f *FilterMaps) SetFinalBlock(finalBlock uint64) {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-f.finalBlockCh:
|
||||||
|
case f.finalBlockCh <- finalBlock:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBlockProcessing sets the block processing flag that temporarily suspends
|
||||||
|
// log index rendering.
|
||||||
|
// Note that SetBlockProcessing never blocks.
|
||||||
|
func (f *FilterMaps) SetBlockProcessing(blockProcessing bool) {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-f.blockProcessingCh:
|
||||||
|
case f.blockProcessingCh <- blockProcessing:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WaitIdle blocks until the indexer is in an idle state while synced up to the
|
// WaitIdle blocks until the indexer is in an idle state while synced up to the
|
||||||
// latest targetView.
|
// latest targetView.
|
||||||
func (f *FilterMaps) WaitIdle() {
|
func (f *FilterMaps) WaitIdle() {
|
||||||
|
|
@ -105,23 +142,28 @@ func (f *FilterMaps) processSingleEvent(blocking bool) bool {
|
||||||
}
|
}
|
||||||
if blocking {
|
if blocking {
|
||||||
select {
|
select {
|
||||||
case targetView := <-f.TargetViewCh:
|
case targetView := <-f.targetViewCh:
|
||||||
f.setTargetView(targetView)
|
f.setTargetView(targetView)
|
||||||
case f.finalBlock = <-f.FinalBlockCh:
|
case f.finalBlock = <-f.finalBlockCh:
|
||||||
case f.matcherSyncRequest = <-f.matcherSyncCh:
|
case f.matcherSyncRequest = <-f.matcherSyncCh:
|
||||||
case f.blockProcessing = <-f.BlockProcessingCh:
|
case f.blockProcessing = <-f.blockProcessingCh:
|
||||||
case <-f.closeCh:
|
case <-f.closeCh:
|
||||||
f.stop = true
|
f.stop = true
|
||||||
case ch := <-f.waitIdleCh:
|
case ch := <-f.waitIdleCh:
|
||||||
|
select {
|
||||||
|
case targetView := <-f.targetViewCh:
|
||||||
|
f.setTargetView(targetView)
|
||||||
|
default:
|
||||||
|
}
|
||||||
ch <- !f.blockProcessing && f.targetHeadIndexed()
|
ch <- !f.blockProcessing && f.targetHeadIndexed()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
select {
|
select {
|
||||||
case targetView := <-f.TargetViewCh:
|
case targetView := <-f.targetViewCh:
|
||||||
f.setTargetView(targetView)
|
f.setTargetView(targetView)
|
||||||
case f.finalBlock = <-f.FinalBlockCh:
|
case f.finalBlock = <-f.finalBlockCh:
|
||||||
case f.matcherSyncRequest = <-f.matcherSyncCh:
|
case f.matcherSyncRequest = <-f.matcherSyncCh:
|
||||||
case f.blockProcessing = <-f.BlockProcessingCh:
|
case f.blockProcessing = <-f.blockProcessingCh:
|
||||||
case <-f.closeCh:
|
case <-f.closeCh:
|
||||||
f.stop = true
|
f.stop = true
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -414,7 +414,8 @@ func (tc *testChain) setTargetHead() {
|
||||||
head := tc.CurrentBlock()
|
head := tc.CurrentBlock()
|
||||||
if tc.ts.fm != nil {
|
if tc.ts.fm != nil {
|
||||||
if !tc.ts.fm.noHistory {
|
if !tc.ts.fm.noHistory {
|
||||||
tc.ts.fm.TargetViewCh <- NewChainView(tc, head.Number.Uint64(), head.Hash())
|
//tc.ts.fm.targetViewCh <- NewChainView(tc, head.Number.Uint64(), head.Hash())
|
||||||
|
tc.ts.fm.SetTargetView(NewChainView(tc, head.Number.Uint64(), head.Hash()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue