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

F/gas price increment #106

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

F/gas price increment #106

wants to merge 2 commits into from

Conversation

nhannamsiu
Copy link
Contributor

@nhannamsiu nhannamsiu commented Feb 20, 2023

Add 2 new chain config options and hint to resolve tx timeout issue

  • common.OptionGasPriceIncrement(10) every time tx timed out error happend, gas prices will be increased by 10% of current gas prices to prioritize txs into block inclusion when network is busy
  • common.OptionsGasPriceResetInterval(time.NewTicker(time.Minute*3)) gas prices will be reset back to baseline every 3 minutes to avoid wasting gas when network is not busy.

Screenshot 2023-02-20 at 16 18 20

@nhannamsiu
Copy link
Contributor Author

Down the road we can add more fancy strategies like slowly reducing the gas over the period of time instead of just resetting it to baseline.

@achilleas-kal
Copy link
Contributor

We're very far from reaching tx limits per block and inclusion as of now is guaranteed.

When the network grows and gas price increase becomes relevant towards inclusion I believe market makers will aim to increase gas prices (hardcoded) instead of arbitrarily setting gas prices for them. The network will most of the times operate under the same frequency in a 3-minute interval.

Tx timeouts currently take place if the node does not respond in time based on timeout_broadcast_tx_commit (due to instability)

I don't believe there's a need for these changes.

@nhannamsiu
Copy link
Contributor Author

@achilleas-kal I created this PR to follow up this issue https://injectivelabsinc.slack.com/archives/C03AHBPV7B7/p1676168357053979

@achilleas-kal
Copy link
Contributor

The issue was not related to block inclusion and higher gas prices needed though, the client just didn't have enough INJ for gas which should be tracked individually per address on their end and not through the SDK. This specific client had actually set double gas prices from the minimum in the network which is a waste of gas since gas currently does not affect block inclusion.

Even when gas does affect block inclusion though, market makers will aim to find the optimal value based on their tolerance and hardcode it to ensure their txs get finalized first. The activity is the same over a 1-minute window, I don't believe the SDK should or even can optimally determine differences in gas prices over such low periods of time.

What would be helpful for clients when gas becomes relevant would be an API to determine average gas price in the network from all txs based on all activity etc. so they can choose their value based on preference.

@vinhphuctadang
Copy link
Contributor

The issue was not related to block inclusion and higher gas prices needed though, the client just didn't have enough INJ for gas which should be tracked individually per address on their end and not through the SDK. This specific client had actually set double gas prices from the minimum in the network which is a waste of gas since gas currently does not affect block inclusion.

Overall, I think this PR provides a convenient behavior when it can auto increase gas prices; on high level, client only needs to retry, finally the tx will be succeeded, before they were panic because tx keeps failing. So it's better than before

It's also a good point to have an API to check average tx gas, but actually out of this PR's scope

logger := c.logger.WithField("size", len(msgs))
if strings.Contains(err.Error(), "tx timed out") {
if c.gasPriceIncrement.IsPositive() {
logger = logger.WithField("hint", "please check your wallet inj balance, gas price, tx timeout configs")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should log this line even if the gasIncrement is not positive (0 e.g)

logger := c.logger.WithField("size", len(toSubmit))
if strings.Contains(err.Error(), "tx timed out") {
if c.gasPriceIncrement.IsPositive() {
logger = logger.WithField("hint", "please check your wallet inj balance, gas price, tx timeout configs")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

}

// resetGasPrices resets gas price to default value to avoid wasting gas when it's network is not busy
func (c *chainClient) resetGasPrices(defaultGasPrices string, timer *time.Ticker) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a ResetGasPrice func to explicit reset gas. It's helpful when the bot realize that all txs has passed so it don't need adjusted gas price anymore, this go routine is not controllable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants