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
This commit is contained in:
lupin012 2022-11-18 01:14:49 +01:00 committed by GitHub
parent 4509f496c6
commit 21d24a20a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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