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

fix: gas: estimate gas with a zero base-fee #8991

Merged
merged 2 commits into from
Jul 13, 2022

Conversation

Stebalien
Copy link
Member

@Stebalien Stebalien commented Jul 7, 2022

Related Issues

#8697

Proposed Changes

Estimate gas with a zero base-fee. Otherwise, an account will need funds to estimate the max possible gas a message could take (which is usually the block gas limit).

This does mean gas estimation no longer checks if the sending account has enough funds to cover the message cost, but MpoolPush will now do this. Furthermore, subsystems like the window post worker will carefully pick an account with funds to cover the message. Previously, the fact that gas estimation would fail up-front caused this code to be less useful.

Checklist

Before you mark the PR ready for review, please make sure that:

  • All commits have a clear commit message.
  • The PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, INTERFACE BREAKING CHANGE, CONSENSUS BREAKING, build, chore, ci, docs,perf, refactor, revert, style, test
    • area: api, chain, state, vm, data transfer, market, mempool, message, block production, multisig, networking, paychan, proving, sealing, wallet, deps
  • This PR has tests for new functionality or change in behaviour
  • If new user-facing features are introduced, clear usage guidelines and / or documentation updates should be included in https://lotus.filecoin.io or Discussion Tutorials.
  • CI is green

@Stebalien Stebalien force-pushed the fix/estimate-with-zero-base-fee branch 5 times, most recently from 492e3d9 to 8244a6f Compare July 7, 2022 22:02
@@ -178,69 +186,3 @@ func TestDealsRetryLackOfFunds_blockInPublishDeal(t *testing.T) {
case <-time.After(time.Second * 15):
}
}

func TestDealsRetryLackOfFunds_belowLimit(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I can tell, this was testing a bug? We should always allow retries, no matter how low our account balance is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that's true -- I believe we explicitly don't auto-retry (can be manually triggered, or happens on restart, per discussion here).

Is this test failing as a result of your change? It may just need to have its funds lowered to, like, 1 attoFIL.

Copy link
Member Author

Choose a reason for hiding this comment

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

Before: The deal would fail if the account didn't have enough funds to cover the gas, but would wait for a retry call if it had enough funds to cover the message, but not enough funds to process the deal.
Now: The deal will behave the same way in both cases. If we don't have enough funds for any reason, we'll let the user retry.

Copy link
Member Author

Choose a reason for hiding this comment

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

But yes, we never auto-retry. But that wasn't what this was testing. This was testing whether or not the deal failed if we were below the limit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, you seem to be right...

@Stebalien Stebalien marked this pull request as ready for review July 8, 2022 01:11
@Stebalien Stebalien requested a review from a team as a code owner July 8, 2022 01:11
@Stebalien Stebalien requested review from nonsense and arajasek July 8, 2022 01:12
@@ -156,6 +157,10 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri
ctx, span := trace.StartSpan(ctx, "statemanager.CallWithGas")
defer span.End()

// Copy the message as we'll be modifying the nonce.
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why we need this copy now, and not before?

Copy link
Member Author

Choose a reason for hiding this comment

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

We needed it before as well, technically. In practice, this doesn't matter because there's exactly one caller of this method (gasEstimateGasLimit) and that caller also copies the message.

Otherwise, an account will need funds to estimate the max possible gas a
message could take (which is usually the block gas limit).

This does mean gas estimation no longer checks if the sending account
has enough funds to cover the message cost, but MpoolPush will now do
this.
@Stebalien Stebalien force-pushed the fix/estimate-with-zero-base-fee branch from 8244a6f to d192b82 Compare July 8, 2022 16:47
@Stebalien Stebalien requested a review from magik6k July 8, 2022 18:01
@codecov
Copy link

codecov bot commented Jul 8, 2022

Codecov Report

Merging #8991 (9b75390) into master (a825682) will decrease coverage by 0.06%.
The diff coverage is 78.57%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8991      +/-   ##
==========================================
- Coverage   40.65%   40.59%   -0.07%     
==========================================
  Files         707      707              
  Lines       78716    78725       +9     
==========================================
- Hits        32004    31960      -44     
- Misses      41242    41286      +44     
- Partials     5470     5479       +9     
Impacted Files Coverage Δ
chain/stmgr/call.go 67.02% <66.66%> (-6.42%) ⬇️
node/impl/full/gas.go 68.96% <100.00%> (+1.72%) ⬆️
node/impl/full/mpool.go 47.41% <100.00%> (+0.45%) ⬆️
storage/sealer/sched_resources.go 76.19% <0.00%> (-7.62%) ⬇️
storage/sealer/worker_tracked.go 80.83% <0.00%> (-6.67%) ⬇️
chain/events/observer.go 73.79% <0.00%> (-6.21%) ⬇️
chain/consensus/filcns/weight.go 70.58% <0.00%> (-5.89%) ⬇️
chain/exchange/peer_tracker.go 66.66% <0.00%> (-4.31%) ⬇️
chain/consensus/filcns/mine.go 64.28% <0.00%> (-2.39%) ⬇️
... and 26 more

Copy link
Contributor

@arajasek arajasek left a 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 PR, looks pretty landable, but a couple things.

itests/gas_estimation_test.go Outdated Show resolved Hide resolved
@@ -178,69 +186,3 @@ func TestDealsRetryLackOfFunds_blockInPublishDeal(t *testing.T) {
case <-time.After(time.Second * 15):
}
}

func TestDealsRetryLackOfFunds_belowLimit(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that's true -- I believe we explicitly don't auto-retry (can be manually triggered, or happens on restart, per discussion here).

Is this test failing as a result of your change? It may just need to have its funds lowered to, like, 1 attoFIL.

@Stebalien
Copy link
Member Author

Addressed CR.

@arajasek arajasek merged commit 57e5aa6 into master Jul 13, 2022
@arajasek arajasek deleted the fix/estimate-with-zero-base-fee branch July 13, 2022 15: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.

3 participants