From d8095c40e55a6246c3cf34e70f6580d536defa42 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 14 Jan 2025 15:00:47 +0800 Subject: [PATCH] fix for when the code is run using the gasprice testBackend --- eth/gasprice/gasprice.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index ac91e9cab7..4fd3df7428 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -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,