fix: gas oracle cache purge

This commit is contained in:
Jaynti Kanani 2021-08-24 12:09:21 +04:00
parent 7e76e9f27c
commit a91b24d4d0
No known key found for this signature in database
GPG key ID: 4396982C976BAE5E
2 changed files with 18 additions and 11 deletions

View file

@ -211,6 +211,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}
eth.engine.VerifyHeader(eth.blockchain, eth.blockchain.CurrentHeader(), true) // TODO think on it
// BOR changes
eth.APIBackend.gpo.ProcessCache()
// BOR changes
// Rewind the chain in case of an incompatible config upgrade.
if compat, ok := genesisErr.(*params.ConfigCompatError); ok {
log.Warn("Rewinding chain to upgrade configuration", "err", compat)

View file

@ -106,17 +106,6 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
}
cache, _ := lru.New(2048)
headEvent := make(chan core.ChainHeadEvent, 1)
backend.SubscribeChainHeadEvent(headEvent)
go func() {
var lastHead common.Hash
for ev := range headEvent {
if ev.Block.ParentHash() != lastHead {
cache.Purge()
}
lastHead = ev.Block.Hash()
}
}()
return &Oracle{
backend: backend,
@ -131,6 +120,20 @@ func NewOracle(backend OracleBackend, params Config) *Oracle {
}
}
func (oracle *Oracle) ProcessCache() {
headEvent := make(chan core.ChainHeadEvent, 1)
oracle.backend.SubscribeChainHeadEvent(headEvent)
go func() {
var lastHead common.Hash
for ev := range headEvent {
if ev.Block.ParentHash() != lastHead {
oracle.historyCache.Purge()
}
lastHead = ev.Block.Hash()
}
}()
}
// SuggestTipCap returns a tip cap so that newly created transaction can have a
// very high chance to be included in the following blocks.
//