-
Notifications
You must be signed in to change notification settings - Fork 6
feat(cmd/mito): implement dynamic gas estimation for transactions #85
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |||||
| "fmt" | ||||||
| "math/big" | ||||||
|
|
||||||
| "github.com/ethereum/go-ethereum" | ||||||
| "github.com/ethereum/go-ethereum/common" | ||||||
| "github.com/ethereum/go-ethereum/core/types" | ||||||
| "github.com/mitosis-org/chain/cmd/mito/internal/client" | ||||||
|
|
@@ -86,7 +87,31 @@ func (b *Builder) CreateTransactionFromDataWithOptions(txData *TransactionData, | |||||
| gasLimit = b.config.GasLimit | ||||||
| } | ||||||
| if gasLimit == 0 { | ||||||
| gasLimit = 500000 // Default | ||||||
| if b.ethClient != nil && !unsigned { | ||||||
| // Only estimate gas for signed transactions since we need a valid from address | ||||||
| fromAddr, err := b.GetSignerAddress() | ||||||
| if err != nil { | ||||||
| // Fallback to default if we can't get signer address | ||||||
| gasLimit = 200000 | ||||||
| } else { | ||||||
| msg := ethereum.CallMsg{ | ||||||
| From: fromAddr, | ||||||
| To: &txData.To, | ||||||
| Value: txData.Value, | ||||||
| Data: txData.Data, | ||||||
| } | ||||||
|
|
||||||
| estimatedGas, err := b.ethClient.EstimateGas(context.Background(), msg) | ||||||
| if err != nil { | ||||||
| return nil, fmt.Errorf("gas estimation failed: %w", err) | ||||||
| } else { | ||||||
| // Add 20% buffer to estimated gas | ||||||
| gasLimit = estimatedGas + (estimatedGas / 5) | ||||||
|
||||||
| gasLimit = estimatedGas + (estimatedGas / 5) | |
| gasLimit = (estimatedGas * 6) / 5 |
Copilot
AI
Aug 16, 2025
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.
The comment describes this as 'Conservative default' but 200000 is actually less conservative than the previous 500000 default. This inconsistency between the comment and the actual behavior could be misleading.
| gasLimit = 200000 // Conservative default when no RPC available or unsigned transaction | |
| gasLimit = 500000 // Conservative default when no RPC available or unsigned transaction |
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.
The fallback gas limit of 200000 is significantly lower than the previous default of 500000. This could cause transaction failures for operations that require more gas. Consider using a more conservative fallback value or documenting why this reduction is safe.