Skip to content

Commit 557d5f4

Browse files
committed
Update eth_feeHistory to take into account changes to Flow fees surge factor
1 parent 5561275 commit 557d5f4

File tree

3 files changed

+78
-43
lines changed

3 files changed

+78
-43
lines changed

api/api.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,6 @@ func (b *BlockChainAPI) FeeHistory(
813813
)
814814

815815
maxCount := min(uint64(blockCount), lastBlockNumber)
816-
817-
blockRewards := make([]*hexutil.Big, len(rewardPercentiles))
818-
for i := range rewardPercentiles {
819-
blockRewards[i] = (*hexutil.Big)(b.config.GasPrice)
820-
}
821-
822816
for i := maxCount; i >= uint64(1); i-- {
823817
// If the requested block count is 5, and the last block number
824818
// is 20, then we need the blocks [16, 17, 18, 19, 20] in this
@@ -835,6 +829,16 @@ func (b *BlockChainAPI) FeeHistory(
835829

836830
baseFees = append(baseFees, (*hexutil.Big)(models.BaseFeePerGas))
837831

832+
blockRewards := make([]*hexutil.Big, len(rewardPercentiles))
833+
feeParams, err := b.feeParameters.Get()
834+
if err != nil {
835+
continue
836+
}
837+
gasPrice := feeParams.CalculateGasPrice(b.config.GasPrice)
838+
for i := range rewardPercentiles {
839+
blockRewards[i] = (*hexutil.Big)(gasPrice)
840+
}
841+
838842
rewards = append(rewards, blockRewards)
839843

840844
gasUsedRatio := float64(block.TotalGasUsed) / float64(BlockGasLimit)

tests/e2e_web3js_test.go

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tests
33
import (
44
_ "embed"
55
"encoding/hex"
6+
"fmt"
67
"math/big"
78
"testing"
89
"time"
@@ -116,35 +117,40 @@ func TestWeb3_E2E(t *testing.T) {
116117

117118
t.Run("gas price updated with surge factor multipler", func(t *testing.T) {
118119
runWeb3TestWithSetup(t, "eth_gas_price_surge_test", func(emu emulator.Emulator) {
119-
res, err := flowSendTransaction(
120-
emu,
121-
`
122-
import FlowFees from 0xe5a8b7f23e8b548f
123-
124-
// This transaction sets the FlowFees parameters
125-
transaction() {
126-
let flowFeesAccountAdmin: &FlowFees.Administrator
127-
128-
prepare(signer: auth(BorrowValue) &Account) {
129-
self.flowFeesAccountAdmin = signer.storage.borrow<&FlowFees.Administrator>(
130-
from: /storage/flowFeesAdmin
131-
)
132-
?? panic("Unable to borrow reference to administrator resource")
133-
}
134-
135-
execute {
136-
self.flowFeesAccountAdmin.setFeeParameters(
137-
surgeFactor: 2.0,
138-
inclusionEffortCost: 1.0,
139-
executionEffortCost: 1.0
140-
)
141-
}
142-
}
143-
144-
`,
145-
)
146-
require.NoError(t, err)
147-
require.NoError(t, res.Error)
120+
surgeFactorValues := []string{"1.1", "2.0", "4.0", "10.0", "100.0"}
121+
for _, surgeFactor := range surgeFactorValues {
122+
res, err := flowSendTransaction(
123+
emu,
124+
fmt.Sprintf(
125+
`
126+
import FlowFees from 0xe5a8b7f23e8b548f
127+
128+
// This transaction sets the FlowFees parameters
129+
transaction() {
130+
let flowFeesAccountAdmin: &FlowFees.Administrator
131+
132+
prepare(signer: auth(BorrowValue) &Account) {
133+
self.flowFeesAccountAdmin = signer.storage.borrow<&FlowFees.Administrator>(
134+
from: /storage/flowFeesAdmin
135+
) ?? panic("Unable to borrow reference to administrator resource")
136+
}
137+
138+
execute {
139+
self.flowFeesAccountAdmin.setFeeParameters(
140+
surgeFactor: %s,
141+
inclusionEffortCost: 1.0,
142+
executionEffortCost: 1.0
143+
)
144+
}
145+
}
146+
147+
`,
148+
surgeFactor,
149+
),
150+
)
151+
require.NoError(t, err)
152+
require.NoError(t, res.Error)
153+
}
148154
})
149155
})
150156

tests/web3js/eth_gas_price_surge_test.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const web3 = conf.web3
66

77
it('should update the value of eth_gasPrice', async () => {
88
let gasPrice = await web3.eth.getGasPrice()
9-
// The surge factor was set to 2.0
10-
assert.equal(gasPrice, 2n * conf.minGasPrice)
9+
// The surge factor was last set to 100.0
10+
assert.equal(gasPrice, 100n * conf.minGasPrice)
1111
})
1212

1313
it('should update the value of eth_MaxPriorityFeePerGas', async () => {
@@ -18,17 +18,17 @@ it('should update the value of eth_MaxPriorityFeePerGas', async () => {
1818
assert.equal(response.status, 200)
1919
assert.isDefined(response.body.result)
2020
let maxPriorityFeePerGas = utils.hexToNumber(response.body.result)
21-
// The surge factor was set to 2.0
22-
assert.equal(maxPriorityFeePerGas, 2n * conf.minGasPrice)
21+
// The surge factor was last set to 100.0
22+
assert.equal(maxPriorityFeePerGas, 100n * conf.minGasPrice)
2323
})
2424

2525
it('should reject transactions with gas price lower than the updated value', async () => {
2626
let receiver = web3.eth.accounts.create()
2727
let transferValue = utils.toWei('2.5', 'ether')
2828

2929
let gasPrice = await web3.eth.getGasPrice()
30-
// The surge factor was set to 2.0
31-
assert.equal(gasPrice, 2n * conf.minGasPrice)
30+
// The surge factor was last set to 100.0
31+
assert.equal(gasPrice, 100n * conf.minGasPrice)
3232

3333
// assert that the minimum acceptable gas price
3434
// has been multiplied by the surge factor
@@ -54,8 +54,8 @@ it('should accept transactions with the updated gas price', async () => {
5454
let transferValue = utils.toWei('2.5', 'ether')
5555

5656
let gasPrice = await web3.eth.getGasPrice()
57-
// The surge factor was set to 2.0
58-
assert.equal(gasPrice, 2n * conf.minGasPrice)
57+
// The surge factor was last set to 100.0
58+
assert.equal(gasPrice, 100n * conf.minGasPrice)
5959

6060
let transfer = await helpers.signAndSend({
6161
from: conf.eoa.address,
@@ -79,3 +79,28 @@ it('should accept transactions with the updated gas price', async () => {
7979
let coinbaseFeesTx = await web3.eth.getTransactionFromBlock(latestBlockNumber, 1)
8080
assert.equal(coinbaseFeesTx.value, transferTxReceipt.gasUsed * gasPrice)
8181
})
82+
83+
it('should update gas price for eth_feeFistory', async () => {
84+
let response = await web3.eth.getFeeHistory(10, 'latest', [20])
85+
console.log('Response: ', response)
86+
87+
assert.deepEqual(
88+
response,
89+
{
90+
oldestBlock: 1n,
91+
reward: [
92+
['0x3a98'], // 100 * gas price = 15000
93+
['0x3a98'], // 100 * gas price = 15000
94+
['0x3a98'], // 100 * gas price = 15000
95+
['0x3a98'], // 100 * gas price = 15000
96+
['0x3a98'], // 100 * gas price = 15000
97+
['0x3a98'], // 100 * gas price = 15000
98+
['0x3a98'], // 100 * gas price = 15000
99+
['0x3a98'], // 100 * gas price = 15000
100+
['0x3a98'], // 100 * gas price = 15000
101+
],
102+
baseFeePerGas: [1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n, 1n],
103+
gasUsedRatio: [0, 0.006205458333333334, 0, 0, 0, 0, 0, 0, 0.00035]
104+
}
105+
)
106+
})

0 commit comments

Comments
 (0)