Skip to content

Commit e0f5bd6

Browse files
committed
Calculate TX.maxPriorityFeePerGas with eth_feeHistory
1 parent 575c2a9 commit e0f5bd6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

chain/eth2/client/execution.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,25 @@ func (c *ExecutionLayer) NewTransactOpts(k *ecdsa.PrivateKey) (*bind.TransactOpt
5454
if err != nil {
5555
return nil, err
5656
}
57-
block, err := c.client.BlockByNumber(ctx, nil)
57+
fh, err := c.client.FeeHistory(ctx, 3, nil, []float64{50})
5858
if err != nil {
5959
return nil, err
6060
}
61-
baseFee := block.BaseFee()
62-
tip, err := c.client.SuggestGasTipCap(ctx)
63-
if err != nil {
64-
return nil, err
61+
rewards := new(big.Int)
62+
for _, r := range fh.Reward {
63+
rewards.Add(rewards, r[0])
6564
}
66-
max := big.NewInt(0).Add(tip, baseFee)
67-
max.Sub(max, big.NewInt(1))
68-
txo.GasFeeCap = max
69-
txo.GasTipCap = tip
65+
txo.GasTipCap = rewards.Div(rewards, big.NewInt(int64(len(fh.Reward))))
7066

7167
return txo, nil
7268
}
7369

70+
func (c *ExecutionLayer) FeeHistory(blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error) {
71+
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
72+
defer cancel()
73+
return c.client.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles)
74+
}
75+
7476
func (c *ExecutionLayer) GetChainID() (*big.Int, error) {
7577
ctx, cancel := context.WithTimeout(context.Background(), DefaultTimeout)
7678
defer cancel()

0 commit comments

Comments
 (0)