-
Notifications
You must be signed in to change notification settings - Fork 431
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
Changes from 2 commits
915b3a1
a4038e6
36d2c38
a71af69
6c7bfea
0705db4
aadb519
4af515b
9657d31
4c8a9f2
866fb1b
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 |
---|---|---|
|
@@ -32,6 +32,8 @@ | |
encCfg encoding.Config | ||
pollTime time.Duration | ||
useFeegrant bool | ||
gasLimit uint64 | ||
gasPrice float64 | ||
|
||
// to protect from concurrent writes to the map | ||
mtx sync.Mutex | ||
|
@@ -225,11 +227,29 @@ | |
|
||
opts := make([]user.TxOption, 0) | ||
if op.GasLimit == 0 { | ||
opts = append(opts, user.SetGasLimit(DefaultGasLimit), user.SetFee(defaultFee)) | ||
if am.gasLimit > 0 { | ||
// Use the custom gas limit set on the AccountManager | ||
opts = append(opts, user.SetGasLimit(am.gasLimit)) | ||
|
||
// 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 commentThe 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 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 commentThe reason will be displayed to describe this comment to others. Learn more. thank you for the feedback! 36d2c38 |
||
} else { | ||
// Use the default gas limit | ||
opts = append(opts, user.SetGasLimit(DefaultGasLimit), user.SetFee(defaultFee)) | ||
} | ||
} else { | ||
opts = append(opts, user.SetGasLimit(op.GasLimit)) | ||
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)))) | ||
} | ||
|
@@ -409,9 +429,18 @@ | |
} | ||
|
||
func (am *AccountManager) nextAccountName() string { | ||
am.mtx.Lock() | ||
defer am.mtx.Unlock() | ||
return accountName(len(am.pending) + am.accountIndex) | ||
am.accountIndex++ | ||
return accountName(am.accountIndex) | ||
} | ||
|
||
// SetGasLimit sets a custom gas limit to be used for all transactions | ||
func (am *AccountManager) SetGasLimit(gasLimit uint64) { | ||
am.gasLimit = gasLimit | ||
} | ||
|
||
// SetGasPrice sets a custom gas price to be used for all transactions | ||
func (am *AccountManager) SetGasPrice(gasPrice float64) { | ||
am.gasPrice = gasPrice | ||
} | ||
|
||
type account struct { | ||
|
Uh oh!
There was an error while loading. Please reload this page.