mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
eth/gasprice: ensure goroutine that that purges cache upon reorg doesn't hang after dependent subscription is closed
This commit is contained in:
parent
864e717b56
commit
0510fc8662
1 changed files with 10 additions and 5 deletions
|
|
@ -120,14 +120,19 @@ func NewOracle(backend OracleBackend, params Config, startPrice *big.Int) *Oracl
|
|||
|
||||
cache := lru.NewCache[cacheKey, processedFees](2048)
|
||||
headEvent := make(chan core.ChainHeadEvent, 1)
|
||||
backend.SubscribeChainHeadEvent(headEvent)
|
||||
sub := backend.SubscribeChainHeadEvent(headEvent)
|
||||
go func() {
|
||||
var lastHead common.Hash
|
||||
for ev := range headEvent {
|
||||
if ev.Header.ParentHash != lastHead {
|
||||
cache.Purge()
|
||||
for {
|
||||
select {
|
||||
case ev := <-headEvent:
|
||||
if ev.Header.ParentHash != lastHead {
|
||||
cache.Purge()
|
||||
}
|
||||
lastHead = ev.Header.Hash()
|
||||
case <-sub.Err():
|
||||
return
|
||||
}
|
||||
lastHead = ev.Header.Hash()
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue