Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth: Set tx GasFeeCap to min(gasPriceEstimate, current GasFeeCap) #2583

Merged
merged 2 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#### CLI

#### General
- [#2583](https://github.com/livepeer/go-livepeer/pull/2583) eth: Set tx GasFeeCap to min(gasPriceEstimate, current GasFeeCap) (@yondonfu)

#### Broadcaster
- [#2573](https://github.com/livepeer/go-livepeer/pull/2573) server: Fix timeout for stream recording background jobs (@victorges)
- [#2573](https://github.com/livepeer/go-livepeer/pull/2573) server: Fix timeout for stream recording background jobs (@victorges)

#### Orchestrator

Expand Down
24 changes: 24 additions & 0 deletions eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,30 @@ func (c *client) transactOpts() *bind.TransactOpts {

opts.Context = newEthRpcContext()

// If GasFeeCap is nil then one of the following will be true:
// - A dynamic tx will be created by BoundContract and GasFeeCap will automatically be set.
// - A legacy tx will be created by BoundContract in which case the GasFeeCap field is not used.
if opts.GasFeeCap == nil {
return &opts
}

// If GasFeeCap is non-nil ensure that we adjust it to be min(gasPriceEstimate, current GasFeeCap).
gasPriceEstimate := opts.GasFeeCap
head, err := c.backend.HeaderByNumber(context.Background(), nil)
if err != nil {
glog.Errorf("failed to calculate gas price estimate - defaulting to using GasFeeCap = maxGasPrice")
} else {
gasPriceEstimate = new(big.Int).Mul(head.BaseFee, big.NewInt(2))
}
// Setting GasFeeCap > gasPriceEstimate is detrimental to the user because the user account will need at least gas * GasFeeCap in their balance
// to pay for the tx when they only need gas * gasPriceEstimate. GasFeeCap is initially going to be set to the maxGasPrice specified by the user which
// they expect to be the maximum gas price they will ever pay. So, a user might set maxGasPrice to 100 gwei as a safety precaution even if the average gas price
// is 0.1 gwei. In this case, the gasPriceEstimate would be 0.1 * 2 = 0.2 gwei (multiplied by 2 to add a buffer). So, the user account would need 500x more funds
// in its balance if its GasFeeCap is set to the maxGasPrice.
if opts.GasFeeCap.Cmp(gasPriceEstimate) > 0 {
opts.GasFeeCap = gasPriceEstimate
}

return &opts
}

Expand Down