Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit 01381df

Browse files
authored
Add a buffer to PVG estimation for non-static values (#186)
1 parent 1335362 commit 01381df

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

pkg/client/buffer.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package client
2+
3+
import "math/big"
4+
5+
func addBuffer(amt *big.Int, factor int64) *big.Int {
6+
a := big.NewInt(0).Mul(amt, big.NewInt(1000+(factor*10)))
7+
return big.NewInt(0).Div(a, big.NewInt(1000))
8+
}

pkg/client/client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,16 @@ func (i *Client) EstimateUserOperationGas(op map[string]any, ep string) (*gas.Ga
179179
return nil, err
180180
}
181181

182+
// Add a buffer to PVG for non-static values
183+
static, err := gas.NewDefaultOverhead().CalcPreVerificationGas(userOp)
184+
if err != nil {
185+
return nil, err
186+
}
187+
if pvg.Cmp(static) == 1 {
188+
// Using a custom PVG calculation. Add a small buffer to account for variability.
189+
pvg = addBuffer(pvg, 1)
190+
}
191+
182192
l.Info("eth_estimateUserOperationGas ok")
183193
return &gas.GasEstimates{
184194
PreVerificationGas: pvg,

0 commit comments

Comments
 (0)