mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les, core: use event.Feed for block processing start/stop events
This commit is contained in:
parent
6f2b0b3183
commit
a9159a70a8
2 changed files with 16 additions and 33 deletions
|
|
@ -111,6 +111,7 @@ type BlockChain struct {
|
||||||
chainSideFeed event.Feed
|
chainSideFeed event.Feed
|
||||||
chainHeadFeed event.Feed
|
chainHeadFeed event.Feed
|
||||||
logsFeed event.Feed
|
logsFeed event.Feed
|
||||||
|
blockProcFeed event.Feed
|
||||||
scope event.SubscriptionScope
|
scope event.SubscriptionScope
|
||||||
genesisBlock *types.Block
|
genesisBlock *types.Block
|
||||||
|
|
||||||
|
|
@ -138,7 +139,6 @@ type BlockChain struct {
|
||||||
processor Processor // block processor interface
|
processor Processor // block processor interface
|
||||||
validator Validator // block and state validator interface
|
validator Validator // block and state validator interface
|
||||||
vmConfig vm.Config
|
vmConfig vm.Config
|
||||||
procFeedback chan bool
|
|
||||||
|
|
||||||
badBlocks *lru.Cache // Bad block cache
|
badBlocks *lru.Cache // Bad block cache
|
||||||
shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block.
|
shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block.
|
||||||
|
|
@ -371,14 +371,6 @@ func (bc *BlockChain) CurrentFastBlock() *types.Block {
|
||||||
return bc.currentFastBlock.Load().(*types.Block)
|
return bc.currentFastBlock.Load().(*types.Block)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetProcFeedback adds a feedback channel where true is sent each time block
|
|
||||||
// processing begins and false is sent when it is finished.
|
|
||||||
func (bc *BlockChain) SetProcFeedback(procFeedback chan bool) {
|
|
||||||
bc.procmu.Lock()
|
|
||||||
defer bc.procmu.Unlock()
|
|
||||||
bc.procFeedback = procFeedback
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetProcessor sets the processor required for making state modifications.
|
// SetProcessor sets the processor required for making state modifications.
|
||||||
func (bc *BlockChain) SetProcessor(processor Processor) {
|
func (bc *BlockChain) SetProcessor(processor Processor) {
|
||||||
bc.procmu.Lock()
|
bc.procmu.Lock()
|
||||||
|
|
@ -1100,23 +1092,8 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// send block processing feedback if needed
|
bc.blockProcFeed.Send(true)
|
||||||
bc.procmu.RLock()
|
defer bc.blockProcFeed.Send(false)
|
||||||
procFeedback := bc.procFeedback
|
|
||||||
bc.procmu.RUnlock()
|
|
||||||
|
|
||||||
if procFeedback != nil {
|
|
||||||
select {
|
|
||||||
case procFeedback <- true:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
select {
|
|
||||||
case procFeedback <- false:
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove already known canon-blocks
|
// Remove already known canon-blocks
|
||||||
var (
|
var (
|
||||||
|
|
@ -1753,3 +1730,9 @@ func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- ChainSideEvent) event.Su
|
||||||
func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription {
|
func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription {
|
||||||
return bc.scope.Track(bc.logsFeed.Subscribe(ch))
|
return bc.scope.Track(bc.logsFeed.Subscribe(ch))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SubscribeBlockProcessingEvent registers a subscription of bool where true means
|
||||||
|
// block processing has started while false means it has stopped.
|
||||||
|
func (bc *BlockChain) SubscribeBlockProcessingEvent(ch chan<- bool) event.Subscription {
|
||||||
|
return bc.scope.Track(bc.blockProcFeed.Subscribe(ch))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -146,8 +146,8 @@ func (s *LesServer) startEventLoop() {
|
||||||
s.protocolManager.wg.Add(1)
|
s.protocolManager.wg.Add(1)
|
||||||
|
|
||||||
var processing bool
|
var processing bool
|
||||||
procFeedback := make(chan bool, 100)
|
blockProcFeed := make(chan bool, 100)
|
||||||
s.protocolManager.blockchain.(*core.BlockChain).SetProcFeedback(procFeedback)
|
s.protocolManager.blockchain.(*core.BlockChain).SubscribeBlockProcessingEvent(blockProcFeed)
|
||||||
totalRechargeCh := make(chan uint64, 100)
|
totalRechargeCh := make(chan uint64, 100)
|
||||||
totalRecharge := s.costTracker.subscribeTotalRecharge(totalRechargeCh)
|
totalRecharge := s.costTracker.subscribeTotalRecharge(totalRechargeCh)
|
||||||
totalCapacityCh := make(chan uint64, 100)
|
totalCapacityCh := make(chan uint64, 100)
|
||||||
|
|
@ -163,7 +163,7 @@ func (s *LesServer) startEventLoop() {
|
||||||
s.fcManager.SetRechargeCurve(flowcontrol.PieceWiseLinear{{0, 0}, {totalRecharge / 10, totalRecharge}, {totalRecharge, totalRecharge}})
|
s.fcManager.SetRechargeCurve(flowcontrol.PieceWiseLinear{{0, 0}, {totalRecharge / 10, totalRecharge}, {totalRecharge, totalRecharge}})
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
case processing = <-procFeedback:
|
case processing = <-blockProcFeed:
|
||||||
case totalRecharge = <-totalRechargeCh:
|
case totalRecharge = <-totalRechargeCh:
|
||||||
case totalCapacity = <-totalCapacityCh:
|
case totalCapacity = <-totalCapacityCh:
|
||||||
s.priorityClientPool.setLimits(s.maxPeers, totalCapacity)
|
s.priorityClientPool.setLimits(s.maxPeers, totalCapacity)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue