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

pm: lower avgGasPrice #2481

Merged
merged 3 commits into from
Jul 11, 2022
Merged

pm: lower avgGasPrice #2481

merged 3 commits into from
Jul 11, 2022

Conversation

leszko
Copy link
Contributor

@leszko leszko commented Jun 29, 2022

What does this pull request do? Explain your changes. (required)

Lower the hardcoded avg gas price to prevent Os from dropping streams in case of the gas price spikes.

The value is changed from 200 => 140. Here's the rationale why this value was chosen. In our problematic scenario, in the case when maxFaceValue is not set, then:

  1. In order to not drop the stream during gas spike this condition faceValue.Cmp(r.txCostWithGasPrice(avgGasPrice)) < 0 must be false
  2. In the worse case scenario, face value equals to max float (which corresponds to the B's reserve, currently 180000000000000000)
  3. txCostWithGasPrice() is calculated as redeemGas * avgGasPrice, where Arbitrum redeemGas is hardcoded as 1200000
  4. That means that 180000000000000000 < 1200000 * avgGasPrice must be false
  5. That means that 180000000000000000 >= 1200000 * avgGasPrice must be true
  6. That means that avgGasPrice <= 180000000000000000 / 1200000 => avgGasPrice <= 150000000000

So, with the current B's reserve and the current hardcoded redeemGas, the avgGasPrice must be smaller than 150 Gwei. To make a buffer, I changed it to 140.

Specific updates (required)

  • Change avgGasPrice
  • Simplify the condition check

How did you test each of these updates (required)

Debugged with Orchestrator.

Does this pull request close any open issues?

fix #2473

Checklist:

@codecov
Copy link

codecov bot commented Jun 29, 2022

Codecov Report

Merging #2481 (c14d9ce) into master (159deaa) will decrease coverage by 0.02337%.
The diff coverage is 33.33333%.

Impacted file tree graph

@@                 Coverage Diff                 @@
##              master       #2481         +/-   ##
===================================================
- Coverage   54.70159%   54.67822%   -0.02337%     
===================================================
  Files             95          95                 
  Lines          19855       19858          +3     
===================================================
- Hits           10861       10858          -3     
- Misses          8390        8396          +6     
  Partials         604         604                 
Impacted Files Coverage Δ
cmd/livepeer/starter/starter.go 2.29008% <0.00000%> (-0.00657%) ⬇️
pm/recipient.go 89.63964% <100.00000%> (ø)
discovery/db_discovery.go 67.01389% <0.00000%> (-1.04167%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2757289...c14d9ce. Read the comment docs.

@leszko leszko requested a review from yondonfu June 30, 2022 07:57
@leszko leszko force-pushed the rafal/fix-avggasprice branch 2 times, most recently from 1ade1c6 to 5cd3251 Compare June 30, 2022 08:01
@leszko leszko marked this pull request as ready for review June 30, 2022 08:02
@yondonfu
Copy link
Member

yondonfu commented Jul 6, 2022

Just to clarify my own understanding (I wrote this avgGasPrice check awhile ago, but I need to jog my memory around how it works...):

avgGasPrice is supposed to represent the average gas price during a period of time. For simplicity, it was originally hardcoded to 200 gwei which indicates that the average gas price is 200 gwei (which was probably accurate at some point on L1).

The check faceValue.Cmp(r.txCostWithGasPrice(avgGasPrice)) < 0 is used as a secondary check when faceValue < txCost where txCost is calculated based on the current estimated gas price. The reason for having this secondary check is that when faceValue < txCost it might be the case that we are in the middle of a gas price spike which is why faceValue < txCost. If we are in the middle of a gas price spike it would be reasonable to expect the gas price to fall after a period of time. As long as the faceValue can cover the expected tx cost based on avgGasPrice (recall that this is meant to represent the average gas price) then O advertises ticket params assuming that the gas price will fall to avgGasPrice or lower.

With this in mind, it makes sense that a lower avgGasPrice makes sense here because the average gas price on Arbitrum is substantially lower than 200 gwei. In reality, the average gas price is even lower than 140 gwei (I know that the OP describes deriving this value based on an assumption of the value of B's reserve, but I generally don't think we should hardcoded values based on an assumption of the value of B's reserve).

I think this PR is fine as-is though as the more ideal solution is to not hardcode a value for avgGasPrice at all which can be followed up on.

Copy link
Member

@yondonfu yondonfu left a comment

Choose a reason for hiding this comment

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

Minor comment about fixing an outdated comment.

Other than that LGTM.

pm/recipient.go Outdated
@@ -28,7 +28,7 @@ var evMultiplier = big.NewInt(100)

// Hardcode to 200 gwei
Copy link
Member

Choose a reason for hiding this comment

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

Let's update this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 98cad6d

@leszko
Copy link
Contributor Author

leszko commented Jul 11, 2022

Just to clarify my own understanding (I wrote this avgGasPrice check awhile ago, but I need to jog my memory around how it works...):

avgGasPrice is supposed to represent the average gas price during a period of time. For simplicity, it was originally hardcoded to 200 gwei which indicates that the average gas price is 200 gwei (which was probably accurate at some point on L1).

The check faceValue.Cmp(r.txCostWithGasPrice(avgGasPrice)) < 0 is used as a secondary check when faceValue < txCost where txCost is calculated based on the current estimated gas price. The reason for having this secondary check is that when faceValue < txCost it might be the case that we are in the middle of a gas price spike which is why faceValue < txCost. If we are in the middle of a gas price spike it would be reasonable to expect the gas price to fall after a period of time. As long as the faceValue can cover the expected tx cost based on avgGasPrice (recall that this is meant to represent the average gas price) then O advertises ticket params assuming that the gas price will fall to avgGasPrice or lower.

With this in mind, it makes sense that a lower avgGasPrice makes sense here because the average gas price on Arbitrum is substantially lower than 200 gwei. In reality, the average gas price is even lower than 140 gwei (I know that the OP describes deriving this value based on an assumption of the value of B's reserve, but I generally don't think we should hardcoded values based on an assumption of the value of B's reserve).

I think this PR is fine as-is though as the more ideal solution is to not hardcode a value for avgGasPrice at all which can be followed up on.

Yes, everything you described is correct. You may be right that we should maybe not make any assumptions about our B reserve. So how, about setting average gas price to some more realistic number in Arbitrum, like 2 or 3. Wdyt?

@yondonfu
Copy link
Member

So how, about setting average gas price to some more realistic number in Arbitrum, like 2 or 3. Wdyt?

👍

@leszko
Copy link
Contributor Author

leszko commented Jul 11, 2022

So how, about setting average gas price to some more realistic number in Arbitrum, like 2 or 3. Wdyt?

👍

Updated in 98cad6d

@leszko leszko merged commit 994ef57 into livepeer:master Jul 11, 2022
@leszko leszko deleted the rafal/fix-avggasprice branch July 11, 2022 14:57
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.

Streams drop using low face value
2 participants