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

Validate transactions against local mempool state #338

Merged
merged 1 commit into from
Oct 11, 2023
Merged

Conversation

charithabandi
Copy link
Contributor

@charithabandi charithabandi commented Oct 4, 2023

List of changes:

  1. ABCI App depends on the account store and accepts configurations such as WithoutGasCosts
  2. ABCI maintains mempool state which gets reset per block. All transactions are validated against this mempool state. This weeds out any invalid txns at the mempool level and protects them from getting picked into the block
  3. P2P hardening using CheckTx: Validates Tx payload, gas costs, nonces wrt local mempool state
  4. ProcessProposal() checks for nonce ordering, gaps, duplicates, and continuity.
  5. Fixed the error propagation by the Cancel() calls of Committer types
  6. gas costs for validator operations is now managed by the Validator pkg

Gonna add integration tests, once the nonce override PR is pushed to the main.

pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/mempool.go Show resolved Hide resolved
pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/interfaces.go Show resolved Hide resolved
pkg/abci/mempool.go Outdated Show resolved Hide resolved
pkg/abci/mempool.go Show resolved Hide resolved
pkg/abci/mempool.go Outdated Show resolved Hide resolved
pkg/abci/mempool.go Outdated Show resolved Hide resolved
pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/abci.go Show resolved Hide resolved
pkg/abci/abci.go Outdated
@@ -184,12 +205,72 @@ func (a *AbciApp) CheckTx(incoming abciTypes.RequestCheckTx) abciTypes.ResponseC
zap.String("sender", hex.EncodeToString(tx.Sender)),
zap.String("PayloadType", tx.Body.PayloadType.String()))

err = tx.Verify()
a.mempoolState.mu.Lock()
defer a.mempoolState.mu.Unlock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm trying to think of a way to better abstract this. The other place that the mempool state gets locked is abstracted by a mempoolState method. I'd love to figure out how to do the same thing here, but I think it would require a larger change to better abstract mempool

pkg/abci/mempool.go Outdated Show resolved Hide resolved
pkg/sessions/session.go Show resolved Hide resolved
@brennanjl
Copy link
Collaborator

Still thinking a bit more, but it seems like we can maybe abstract away the mempool a bit better? This might not be possible, so if nothing comes to mind today then we will just continue as-is. But it just feels like the ABCI needs a lot of context on mempool, but mempool seems like it is really only account store specific, and could therefore be better abstracted

Copy link
Member

@jchappelow jchappelow left a comment

Choose a reason for hiding this comment

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

Just a couple quick comments that pertain to active discussions.
Still going through

pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/interfaces.go Show resolved Hide resolved
pkg/abci/mempool.go Outdated Show resolved Hide resolved
Copy link
Member

@jchappelow jchappelow left a comment

Choose a reason for hiding this comment

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

Looks to work as advertised, but have comments.

The one explicit panic is making me think though. Like why the method checks the map when it can just update the values in the *userAccount that reference the map entry that we just pulled.

Some thought via hacking a diff (don't cherry-pick directly, just consider pls): ff28bad

pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/abci.go Outdated Show resolved Hide resolved
@charithabandi charithabandi force-pushed the mempool branch 12 times, most recently from 6147f31 to 8cefede Compare October 9, 2023 20:07
internal/app/kwild/server/build.go Show resolved Hide resolved
@@ -193,33 +208,46 @@ func (a *AbciApp) BeginBlock(req abciTypes.RequestBeginBlock) abciTypes.Response
func (a *AbciApp) CheckTx(incoming abciTypes.RequestCheckTx) abciTypes.ResponseCheckTx {
logger := a.log.With(zap.String("stage", "ABCI CheckTx"))
logger.Debug("check tx")
ctx := context.Background()
Copy link
Contributor

Choose a reason for hiding this comment

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

Just an observation.
It seems all AbciApp.*Tx methods, won't provide us a context through parameter, so it's really to us to manage context.
And all our abci modules methods receive Context.
So it's bit awkward to see in those AbciApp.*Tx methods, we just created a context.Background() context, without any kind of context management, I guess we'll add later ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we should manage our own contexts. Will raise an Issue on it

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This is genuinely good, it feels right ABCI call the app with context

pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/abci.go Outdated Show resolved Hide resolved
pkg/abci/abci_test.go Show resolved Hide resolved
pkg/abci/abci_test.go Outdated Show resolved Hide resolved
pkg/abci/mempool.go Outdated Show resolved Hide resolved
Copy link
Contributor

@Yaiba Yaiba left a comment

Choose a reason for hiding this comment

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

lgtm

if len(errs) > 0 {
s.log.Error("errors while cancelling session", zap.Error(errors.Join(errs...)))
if errs != nil {
s.log.Error("errors while cancelling session", zap.Error(errs))
Copy link
Member

Choose a reason for hiding this comment

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

OK to leave, but if you return an error you don't also log it.

pkg/sessions/session.go Outdated Show resolved Hide resolved
if err != nil {
return nil, err
return resp(price), err
Copy link
Member

Choose a reason for hiding this comment

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

Why return a non-nil *ExecutionResponse if error is non-nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had this doubt too, but in databases we seem to be returning execution response with tx price even during the errored scenarios. It's kinda unclear right now on the correct behavior as we don't have gas. Even with gas, what should be the tx fee on failed transactions?

* added extensible auth using build tags

* go mod tidied

* made gavins requested changes
@jchappelow jchappelow merged commit 3b1edb2 into main Oct 11, 2023
2 checks passed
@jchappelow jchappelow deleted the mempool branch October 11, 2023 15:12
@jchappelow jchappelow added this to the v0.6.0 milestone Nov 6, 2023
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.

block proposal and approval must ensure nonce continuity mempool needs more acceptance checks
4 participants