-
Notifications
You must be signed in to change notification settings - Fork 398
feat: implement gas price and gas limit customization for txsim #4447
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
Conversation
📝 Walkthrough""" WalkthroughThe changes introduce configurable gas parameters in the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant CLI as Command-Line Interface
participant O as Options
participant AM as AccountManager
U->>CLI: Execute txsim with --gas-limit and --gas-price flags
CLI->>O: Parse flags and set gasLimit and gasPrice
O->>AM: Invoke WithGasLimit and WithGasPrice to pass custom values
AM->>AM: Use custom gas settings during transaction submission (Submit)
Assessment against linked issues
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 Tip ⚡💬 Agentic Chat (Pro Plan, General Availability)
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (8)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
test/txsim/account.go (2)
230-245
: Gas limit handling logic looks good but could be formatted better.The implementation correctly handles the custom gas limit and properly calculates fees based on gas price. However, there's a formatting issue on line 233 that should be fixed.
- opts = append(opts, user.SetGasLimit(am.gasLimit)) - + opts = append(opts, user.SetGasLimit(am.gasLimit))🧰 Tools
🪛 golangci-lint (1.64.8)
233-233: File is not properly formatted
(gofumpt)
248-255
: Consider refactoring the if-else chain to a switch statement.The current nested if-else structure works, but a switch statement would improve readability for this gas price determination logic.
- if op.GasPrice > 0 { - opts = append(opts, user.SetFee(uint64(math.Ceil(float64(op.GasLimit)*op.GasPrice)))) - } else if am.gasPrice > 0 { - // Use custom gas price set on AccountManager if available - opts = append(opts, user.SetFee(uint64(math.Ceil(float64(op.GasLimit)*am.gasPrice)))) - } else { - opts = append(opts, user.SetFee(uint64(math.Ceil(float64(op.GasLimit)*appconsts.DefaultMinGasPrice)))) - } + switch { + case op.GasPrice > 0: + opts = append(opts, user.SetFee(uint64(math.Ceil(float64(op.GasLimit)*op.GasPrice)))) + case am.gasPrice > 0: + // Use custom gas price set on AccountManager if available + opts = append(opts, user.SetFee(uint64(math.Ceil(float64(op.GasLimit)*am.gasPrice)))) + default: + opts = append(opts, user.SetFee(uint64(math.Ceil(float64(op.GasLimit)*appconsts.DefaultMinGasPrice)))) + }🧰 Tools
🪛 golangci-lint (1.64.8)
248-248: ifElseChain: rewrite if-else to switch statement
(gocritic)
🪛 GitHub Check: lint / golangci-lint
[failure] 248-248:
ifElseChain: rewrite if-else to switch statement (gocritic)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
test/cmd/txsim/cli.go
(3 hunks)test/txsim/account.go
(3 hunks)test/txsim/run.go
(3 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
test/txsim/account.go (3)
test/cmd/txsim/cli.go (2)
gasLimit
(45-45)gasPrice
(46-46)app/errors/insufficient_gas_price_test.go (2)
gasLimit
(28-28)gasPrice
(30-30)test/txsim/sequence.go (1)
DefaultGasLimit
(47-47)
test/cmd/txsim/cli.go (1)
test/txsim/account.go (1)
gasPrice
(235-235)
🪛 golangci-lint (1.64.8)
test/txsim/account.go
248-248: ifElseChain: rewrite if-else to switch statement
(gocritic)
233-233: File is not properly formatted
(gofumpt)
🪛 GitHub Check: lint / golangci-lint
test/txsim/account.go
[failure] 248-248:
ifElseChain: rewrite if-else to switch statement (gocritic)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: test / test
- GitHub Check: Summary
🔇 Additional comments (9)
test/txsim/run.go (3)
69-77
: Feature implementation looks good!These checks appropriately apply custom gas limit and gas price from the options to the account manager if provided. The conditional structure ensures these configurations are only set when explicitly specified by the user (values > 0).
145-146
: Good addition of fields to Options struct.The additions of
gasLimit
andgasPrice
fields to the Options struct are well-aligned with the PR objective of allowing customization of gas parameters.
189-197
: Well-designed method chaining for gas configuration.These new methods follow the existing pattern of method chaining in the Options struct, providing a clean API for configuring gas parameters. This implementation approach maintains consistency with the rest of the codebase.
test/txsim/account.go (3)
35-36
: Appropriate addition of gas configuration fields.Adding
gasLimit
andgasPrice
fields to the AccountManager struct aligns with the PR objective of supporting customizable gas parameters.
431-434
: Simplified function - good improvement.Simplifying the
nextAccountName
method by removing the mutex lock is a good improvement. Since this method is only incrementing a counter and returning a string, the lock wasn't necessary in this context.
437-444
: Well-designed setter methods for gas parameters.These setter methods follow good Go practices and provide a clean API for setting gas parameters on the account manager.
test/cmd/txsim/cli.go (3)
45-46
: Good addition of gas parameter variables.Adding
gasLimit
andgasPrice
as global variables is consistent with the pattern used for other configuration parameters in this file.
182-188
: Clear and consistent handling of gas parameters.The implementation properly checks if custom values were provided before applying them to the options, following the same pattern used for other optional parameters.
230-231
: Well-documented CLI flags for gas parameters.The flag descriptions clearly explain the purpose and default behavior of the gas limit and gas price parameters. The "(0 = auto-estimate)" and "(0 = use default)" notes are particularly helpful for users.
nit: golangci-lint is complaining: https://github.com/celestiaorg/celestia-app/actions/runs/14042058383/job/39314321206#step:5:38 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One idea for an optional refactor to make it easier to reason about the fee calculation
test/txsim/account.go
Outdated
// Calculate fee based on gas price | ||
var gasPrice float64 | ||
if am.gasPrice > 0 { | ||
gasPrice = am.gasPrice | ||
} else { | ||
gasPrice = appconsts.DefaultMinGasPrice | ||
} | ||
opts = append(opts, user.SetFee(uint64(math.Ceil(float64(am.gasLimit)*gasPrice)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[question] this seems a bit difficult to reason about. Is it possible to extract the fee
calculation to after the custom gas limit and gas price have been set. That way this code can remain less indented:
if am.gasLimit > 0 {
// set custom gas limit
}
if am.gasPrice > 0 {
// set custom gas price
}
fee := calculateFee(gasLimit, gasPrice)
opts = append(opts, user.SetFee(fee))
That way there's only one line where we set the fee instead of two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for the feedback! 36d2c38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utack
tested with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
test/txsim/account.go (2)
229-266
: Consider simplifying the fee calculation logic.The implementation correctly prioritizes gas parameters (op-specific → account manager → defaults) and includes appropriate warnings for low gas prices. However, the nested conditionals for fee calculation could be simplified.
Per rootulp's previous suggestion, consider extracting the fee calculation after both gas parameters are determined:
- var gasLimit, fee uint64 + var gasLimit uint64 var gasPrice float64 // Determine gas limit switch { case op.GasLimit > 0: gasLimit = op.GasLimit case am.gasLimit > 0: gasLimit = am.gasLimit default: gasLimit = DefaultGasLimit - fee = defaultFee } // Set gas limit if gasLimit > 0 { opts = append(opts, user.SetGasLimit(gasLimit)) } // Determine gas price and calculate fee if not already set - if fee == 0 { - switch { - case op.GasPrice > 0: - gasPrice = op.GasPrice - case am.gasPrice > 0: - gasPrice = am.gasPrice - if gasPrice < appconsts.DefaultMinGasPrice { - log.Warn(). - Float64("gas_price", gasPrice). - Float64("default_min_gas_price", appconsts.DefaultMinGasPrice). - Msg("custom gas price is lower than default minimum") - } - default: - gasPrice = appconsts.DefaultMinGasPrice - } - fee = uint64(math.Ceil(float64(gasLimit) * gasPrice)) - opts = append(opts, user.SetFee(fee)) + // Determine gas price + switch { + case op.GasPrice > 0: + gasPrice = op.GasPrice + case am.gasPrice > 0: + gasPrice = am.gasPrice + if gasPrice < appconsts.DefaultMinGasPrice { + log.Warn(). + Float64("gas_price", gasPrice). + Float64("default_min_gas_price", appconsts.DefaultMinGasPrice). + Msg("custom gas price is lower than default minimum") + } + default: + gasPrice = appconsts.DefaultMinGasPrice } + + // Calculate and set fee + fee := uint64(math.Ceil(float64(gasLimit) * gasPrice)) + opts = append(opts, user.SetFee(fee))This approach is cleaner, has less indentation, and avoids conditional fee calculation.
446-454
: Consider adding validation to the setter methods.The methods correctly implement the functionality to set custom gas parameters, but they don't validate inputs.
Consider adding validation to prevent negative or unreasonable values:
// SetGasLimit sets a custom gas limit to be used for all transactions func (am *AccountManager) SetGasLimit(gasLimit uint64) { + if gasLimit == 0 { + log.Warn().Msg("setting gas limit to zero may cause transactions to fail") + } am.gasLimit = gasLimit } // SetGasPrice sets a custom gas price to be used for all transactions func (am *AccountManager) SetGasPrice(gasPrice float64) { + if gasPrice <= 0 { + log.Warn().Msg("setting non-positive gas price will cause transactions to fail") + } else if gasPrice < appconsts.DefaultMinGasPrice { + log.Warn(). + Float64("gas_price", gasPrice). + Float64("default_min_gas_price", appconsts.DefaultMinGasPrice). + Msg("custom gas price is lower than default minimum") + } am.gasPrice = gasPrice }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
test/txsim/account.go
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: test / test
- GitHub Check: test / test-race
- GitHub Check: Summary
🔇 Additional comments (2)
test/txsim/account.go (2)
35-36
: LGTM: New fields support gas customization.These new fields appropriately extend the
AccountManager
to store custom gas parameters, supporting the core feature of this PR.
441-444
:✅ Verification successful
Verify thread safety of accountIndex modifications.
The mutex lock was removed from this method, which simplifies the code but could introduce thread safety issues if the method is called concurrently.
🏁 Script executed:
#!/bin/bash # Check if nextAccountName is called from any methods other than AllocateAccounts echo "Searching for calls to nextAccountName outside of AllocateAccounts..." rg "nextAccountName\(\)" --type go -A 3 -B 3 | grep -v "AllocateAccounts"Length of output: 1010
Thread Safety Verification and Documentation
The search confirmed that the only usage of
nextAccountName
is within a non-concurrent context (specifically, within the loop in AllocateAccounts, which is already documented as not concurrently safe). Thus, removing the mutex lock is acceptable given the current usage. However, please consider updating the documentation or adding a comment to clearly state that this method is not safe for concurrent calls, so future modifications or usages are aware of this constraint.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still a little confused on why this calculates fee in the middle of setting gas limit and gas price. IMO the code could be clearer if it:
- Determine gas limit (either user specified or default)
- Determine gas price (either user specified or default)
- Calculate fee based on gas limit and gas price from step 1 and 2
I haven't tried any of this code and it's mostly for testing purposes so if this works then I'm okay with merging it
- Separate gas limit, price and fee calculation into clear steps\n- Remove redundant default fee calculation\n- Improve code readability and maintainability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks for addressing the feedback
FYI golangci-lint is failing but it wasn't caused by this PR: #4454 will fix separately. |
I will trust core/app team and your judgement here @cmwaters! In #4445 I hit issues with |
Proposition: Why not use the gas estimation endpoint in txsim? would be a good stress test for it every time someone runs it, and it should return accurate results. |
I'm not sure what's best here. I'd defer to core/app team to take this over if possible, I just was trying to use txsim and it didn't work without changing the minimum gas price to be enough compared to what the endpoint is asking for |
I'm still a bit concerned this implementation is wrong, even though it "works" |
Eventually we should. But I think allowing to manually set it is also good. We should open an issue for it |
Yeah this is from the gas price being insufficient |
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview Resolves #4445 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Testing results `txsim --key-path ~/.celestia-app --grpc-endpoint validator-1.celestia-arabica-11.com:9090 --feegrant --blob 4 --blob-amounts 1 --blob-sizes 475000 --gas-limit 360000 --gas-price 1.0` The fees were outrageous here - 16+ TIA. - [example block](https://arabica.celenium.io/block/4973806?tab=transactions) `txsim --key-path ~/.celestia-app --grpc-endpoint validator-1.celestia-arabica-11.com:9090 --feegrant --blob 4 --blob-amounts 1 --blob-sizes 475000 --gas-limit 720000 --gas-price 0.5` This fills 2MB with 8.25 TIA - [example block](https://arabica.celenium.io/block/4973865?tab=transactions) then using `txsim --key-path ~/.celestia-app --grpc-endpoint validator-1.celestia-arabica-11.com:9090 --feegrant --blob 4 --blob-amounts 1 --blob-sizes 475000 --gas-limit 3600000 --gas-price 0.1` works and 2MB costs 1.65 TIA, much more reasonable - [example block](https://arabica.celenium.io/block/4973906?tab=transactions) ### Failed testing this also failed but idk why ``` txsim --key-path ~/.celestia-app --grpc-endpoint validator-1.celestia-arabica-11.com:9090 --feegrant --blob 4 --blob-amounts 1 --blob-sizes 475000 --gas-limit 18000000 --gas-price 0.02 Error: error funding accounts: broadcast tx error: insufficient minimum gas price for this node; got: 72000 required at least: 360000.000000000000000000: insufficient fee ``` going lower ``` txsim --key-path ~/.celestia-app --grpc-endpoint validator-1.celestia-arabica-11.com:9090 --feegrant --blob 4 --blob-amounts 1 --blob-sizes 475000 --gas-limit 12000000 --gas-price 0.03 Error: error funding accounts: broadcast tx error: insufficient minimum gas price for this node; got: 108000 required at least: 360000.000000000000000000: insufficient fee ``` and up a bit: ``` txsim --key-path ~/.celestia-app --grpc-endpoint validator-1.celestia-arabica-11.com:9090 --feegrant --blob 4 --blob-amounts 1 --blob-sizes 475000 --gas-limit 15000000 --gas-price 0.03 Error: error funding accounts: broadcast tx error: insufficient minimum gas price for this node; got: 108000 required at least: 360000.000000000000000000: insufficient fee ``` --------- Co-authored-by: Rootul P <[email protected]> (cherry picked from commit ba3a448) # Conflicts: # test/cmd/txsim/cli.go # test/txsim/run.go
Overview
Resolves #4445
Testing results
txsim --key-path ~/.celestia-app --grpc-endpoint validator-1.celestia-arabica-11.com:9090 --feegrant --blob 4 --blob-amounts 1 --blob-sizes 475000 --gas-limit 360000 --gas-price 1.0
The fees were outrageous here - 16+ TIA. - example block
txsim --key-path ~/.celestia-app --grpc-endpoint validator-1.celestia-arabica-11.com:9090 --feegrant --blob 4 --blob-amounts 1 --blob-sizes 475000 --gas-limit 720000 --gas-price 0.5
This fills 2MB with 8.25 TIA - example block
then using
txsim --key-path ~/.celestia-app --grpc-endpoint validator-1.celestia-arabica-11.com:9090 --feegrant --blob 4 --blob-amounts 1 --blob-sizes 475000 --gas-limit 3600000 --gas-price 0.1
works and 2MB costs 1.65 TIA, much more reasonable - example block
Failed testing
this also failed but idk why
going lower
and up a bit: