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!: Branch antehandlers and commit to state before runMsgs #11942

Closed
wants to merge 20 commits into from

Conversation

amaury1093
Copy link
Contributor

@amaury1093 amaury1093 commented May 11, 2022

Description

This PR is to make sure v0.46 middleware logic matches v0.45's baseapp runTx logic


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Comment on lines 70 to 71
beginAnteBranch, endAnteBranch := middleware.WithBranchAnte()
beginRunMsgsBranch, endRunMsgsBranch := middleware.WithBranchRunMsgs()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if this is the best API, but couldn't think of anything else for now

@aaronc
Copy link
Member

aaronc commented May 11, 2022

I generally think cache wrap and branch aren't the clearest names for what this does outside of the cosmos space. In other db terminology people would say transaction isolation. So maybe WrapTransaction or BeginTransaction?

@amaury1093 amaury1093 mentioned this pull request May 12, 2022
56 tasks
@amaury1093 amaury1093 marked this pull request as ready for review May 12, 2022 10:30
@amaury1093 amaury1093 requested a review from a team as a code owner May 12, 2022 10:30
@amaury1093
Copy link
Contributor Author

R4R.

@aaronc I remember having this conversation already: #8102 (comment). At that time it was decided to use "branching", and docs have been updated to reflect that. I can create an issue to rename that wording, but I think this PR should still use "branching" to be consistent.

@amaury1093 amaury1093 requested a review from yihuang May 12, 2022 12:39
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Nice work @AmauryM. I left a few questions.

x/auth/middleware/branch_store.go Outdated Show resolved Hide resolved
}

// CheckTx implements tx.Handler.CheckTx method.
// Do nothing during CheckTx.
func (sh branchStoreHandler) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) {
func (sh anteBranchBegin) CheckTx(ctx context.Context, req tx.Request, checkReq tx.RequestCheckTx) (tx.Response, tx.ResponseCheckTx, error) {
return sh.next.CheckTx(ctx, req, checkReq)
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we just call next here? I recall that in previous versions, we also write state (to checkTxState)

Copy link
Contributor Author

@amaury1093 amaury1093 May 12, 2022

Choose a reason for hiding this comment

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

oh yeah, you're right, just had another look at 0.45's code.

fixed in 062ddd4

x/auth/middleware/branch_store_test.go Show resolved Hide resolved
WithBranchedStore,
// - Storage writes below this middleware should ALWAYS be discarded
// together when middleware fails, but those above can have state writes.
WithRunMsgsBranch,
// Consume block gas. All middlewares whose gas consumption after their `next` handler
// should be accounted for, should go below this middleware.
ConsumeBlockGasMiddleware,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This ConsumeBlockGasMiddleware is a new middleware added in v0.46, which afair differs from v0.45 logic. #10770.

I would love @yihuang (or someone else) to double-check the current PR still does what #10770 intended.

Copy link
Collaborator

Choose a reason for hiding this comment

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

looks alright, the WithRunMsgsBranch is just renamed WithBranchedStore right?

Copy link
Collaborator

@yihuang yihuang May 13, 2022

Choose a reason for hiding this comment

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

would it be clearer if we keep two separate middleware stacks for ante handlers and runMsgs, and they are run under different branched stores (db transaction)?
Personally, I'm more familiar with the old runTx code structure, the panic recovery logic is also clearer in the old code structure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yihuang I think there are multiple people saying that middlewares are confusing. I created #11955

sdkCtx = sdkCtx.WithMultiStore(originalStore)
}

branchedStore.Write()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused...where do we actually check for errors if say there is an error in any of the middleware ante-handlers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If any of the antehandlers fails, then this anteBranchWrite one is never called. Take a look at the middleware stack in middleware.go, endAnteBranch is below all the antehandlers.

amaury1093 and others added 4 commits May 13, 2022 10:48
Co-authored-by: Levi Schoen <levismschoen@gmail.com>
Co-authored-by: Levi Schoen <levismschoen@gmail.com>
@amaury1093
Copy link
Contributor Author

superseded by #11979

@amaury1093 amaury1093 closed this May 17, 2022
@amaury1093 amaury1093 deleted the am/fix-branch-middleware branch May 17, 2022 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants