From 21d24a20a0b7ff8c2a8e88591a08bfd9ebc4ce77 Mon Sep 17 00:00:00 2001 From: lupin012 <58134934+lupin012@users.noreply.github.com> Date: Fri, 18 Nov 2022 01:14:49 +0100 Subject: [PATCH] fix on number of samples for blocks (#5826) eth_gasPrice(): A maximum of 3 samples should be taken per block (see sample const) The getBlockPrices() function takes 3 samples on the first block and one on the others. In the check s.Len() >= limit s.Len() after first block will contain 3 samples and so the loop will be executed only one time for each block NOT three times --- eth/gasprice/gasprice.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/eth/gasprice/gasprice.go b/eth/gasprice/gasprice.go index c8974c7e6..f6e9e3884 100644 --- a/eth/gasprice/gasprice.go +++ b/eth/gasprice/gasprice.go @@ -254,7 +254,8 @@ func (oracle *Oracle) getBlockPrices(ctx context.Context, blockNum uint64, limit txs := newTransactionsByGasPrice(plainTxs, baseFee) heap.Init(&txs) - for txs.Len() > 0 { + count := 0 + for count < limit && txs.Len() > 0 { tx := heap.Pop(&txs).(types.Transaction) tip := tx.GetEffectiveGasTip(baseFee) if ignoreUnder != nil && tip.Lt(ignoreUnder) { @@ -263,9 +264,7 @@ func (oracle *Oracle) getBlockPrices(ctx context.Context, blockNum uint64, limit sender, _ := tx.GetSender() if err == nil && sender != block.Coinbase() { heap.Push(s, tip) - if s.Len() >= limit { - break - } + count = count + 1 } } return nil