Skip to content

Commit 60fc001

Browse files
committed
Multiply eth_maxPriorityFeePerGas with the latest surge factor
1 parent 453c678 commit 60fc001

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

api/api.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,16 @@ func (b *BlockChainAPI) GetUncleByBlockNumberAndIndex(
10651065

10661066
// MaxPriorityFeePerGas returns a suggestion for a gas tip cap for dynamic fee transactions.
10671067
func (b *BlockChainAPI) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error) {
1068-
return (*hexutil.Big)(b.config.GasPrice), nil
1068+
feeParams, err := b.feeParameters.Get()
1069+
if err != nil {
1070+
return nil, err
1071+
}
1072+
1073+
surgeFactor := uint64(feeParams.SurgeFactor)
1074+
multiplier := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(8)), nil)
1075+
gp := b.config.GasPrice.Uint64()
1076+
gasPrice := new(big.Int).SetUint64(uint64(gp * surgeFactor))
1077+
return (*hexutil.Big)(new(big.Int).Div(gasPrice, multiplier)), nil
10691078
}
10701079

10711080
// Mining returns true if client is actively mining new blocks.

tests/e2e_web3js_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestWeb3_E2E(t *testing.T) {
114114
})
115115
})
116116

117-
t.Run("gas price with surge factor multipler", func(t *testing.T) {
117+
t.Run("gas price updated with surge factor multipler", func(t *testing.T) {
118118
runWeb3TestWithSetup(t, "eth_gas_price_surge_test", func(emu emulator.Emulator) {
119119
res, err := flowSendTransaction(
120120
emu,

tests/web3js/eth_gas_price_surge_test.js

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,40 @@ const conf = require('./config')
44
const helpers = require('./helpers')
55
const web3 = conf.web3
66

7-
it('updates the gas price', async () => {
7+
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
910
assert.equal(gasPrice, 2n * conf.minGasPrice)
11+
})
1012

11-
let receiver = web3.eth.accounts.create()
12-
13-
// make sure receiver balance is initially 0
14-
let receiverWei = await web3.eth.getBalance(receiver.address)
15-
assert.equal(receiverWei, 0n)
13+
it('should update the value of eth_MaxPriorityFeePerGas', async () => {
14+
let response = await helpers.callRPCMethod(
15+
'eth_maxPriorityFeePerGas',
16+
[]
17+
)
18+
assert.equal(response.status, 200)
19+
assert.isDefined(response.body.result)
20+
let maxPriorityFeePerGas = utils.hexToNumber(response.body.result)
21+
// The surge factor was set to 2.0
22+
assert.equal(maxPriorityFeePerGas, 2n * conf.minGasPrice)
23+
})
1624

17-
// get sender balance
18-
let senderBalance = await web3.eth.getBalance(conf.eoa.address)
19-
assert.equal(senderBalance, utils.toWei(conf.fundedAmount, 'ether'))
25+
it('should reject transactions with gas price lower than the updated value', async () => {
26+
let receiver = web3.eth.accounts.create()
27+
let transferValue = utils.toWei('2.5', 'ether')
2028

21-
let txCount = await web3.eth.getTransactionCount(conf.eoa.address)
22-
assert.equal(0n, txCount)
29+
let gasPrice = await web3.eth.getGasPrice()
30+
// The surge factor was set to 2.0
31+
assert.equal(gasPrice, 2n * conf.minGasPrice)
2332

24-
let transferValue = utils.toWei('2.5', 'ether')
25-
// assert that the minimum acceptable gas price has been multiplied by the surge factor
33+
// assert that the minimum acceptable gas price
34+
// has been multiplied by the surge factor
2635
try {
27-
let transfer = await helpers.signAndSend({
36+
await helpers.signAndSend({
2837
from: conf.eoa.address,
2938
to: receiver.address,
3039
value: transferValue,
31-
gasPrice: gasPrice - 10n,
40+
gasPrice: gasPrice - 10n, // provide a lower gas price
3241
gasLimit: 55_000,
3342
})
3443
assert.fail('should not have gotten here')
@@ -38,12 +47,21 @@ it('updates the gas price', async () => {
3847
`the minimum accepted gas price for transactions is: ${gasPrice}`
3948
)
4049
}
50+
})
51+
52+
it('should accept transactions with the updated gas price', async () => {
53+
let receiver = web3.eth.accounts.create()
54+
let transferValue = utils.toWei('2.5', 'ether')
55+
56+
let gasPrice = await web3.eth.getGasPrice()
57+
// The surge factor was set to 2.0
58+
assert.equal(gasPrice, 2n * conf.minGasPrice)
4159

4260
let transfer = await helpers.signAndSend({
4361
from: conf.eoa.address,
4462
to: receiver.address,
4563
value: transferValue,
46-
gasPrice: gasPrice,
64+
gasPrice: gasPrice, // provide the updated gas price
4765
gasLimit: 55_000,
4866
})
4967
assert.equal(transfer.receipt.status, conf.successStatus)

0 commit comments

Comments
 (0)