fix for when the code is run using the gasprice testBackend

This commit is contained in:
Jared Wasinger 2025-01-14 15:00:47 +08:00
parent 0510fc8662
commit d8095c40e5

View file

@ -121,20 +121,22 @@ func NewOracle(backend OracleBackend, params Config, startPrice *big.Int) *Oracl
cache := lru.NewCache[cacheKey, processedFees](2048)
headEvent := make(chan core.ChainHeadEvent, 1)
sub := backend.SubscribeChainHeadEvent(headEvent)
go func() {
var lastHead common.Hash
for {
select {
case ev := <-headEvent:
if ev.Header.ParentHash != lastHead {
cache.Purge()
if sub != nil { // the gasprice testBackend doesn't support subscribing to head events
go func() {
var lastHead common.Hash
for {
select {
case ev := <-headEvent:
if ev.Header.ParentHash != lastHead {
cache.Purge()
}
lastHead = ev.Header.Hash()
case <-sub.Err():
return
}
lastHead = ev.Header.Hash()
case <-sub.Err():
return
}
}
}()
}()
}
return &Oracle{
backend: backend,