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

CAT Part 2: write pool for handling CRUD-like operations #942

Merged
merged 22 commits into from
Feb 6, 2023

Conversation

cmwaters
Copy link
Contributor

Ref: #935

@evan-forbes evan-forbes requested review from a team and MSevey and removed request for a team January 16, 2023 14:47
@MSevey MSevey removed the request for review from a team January 20, 2023 19:27
// be broadcasted to peers. Only populated if `broadcast` is enabled
broadcastCh chan types.TxKey
broadcastMtx sync.Mutex
txsToBeBroadcast map[types.TxKey]struct{}
Copy link
Member

Choose a reason for hiding this comment

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

The comment for the TxPool struct says that txns are gossiped in the order that they arrive, however the combination of the channel and map doesn't preserve the order.

See simplified example https://go.dev/play/p/KSy7W4u4Fwc

If the order doesn't matter, I would update the comment. If the order does matter, then we should use a list or something to ensure FIFO ordering.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. I was too focused on ensuring that transactions aren't dropped on their way to the reactor. Ordering isn't so important so long as transactions arrive in a timely manner (they are reordered by priority when it comes to block construction).

}

// Early exit if the proxy connection has an error.
if err := txmp.proxyAppConn.Error(); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

should we check the connection before running the preCheck function? Or does the ordering of these two checks not matter much? If so, why?

Copy link
Member

Choose a reason for hiding this comment

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

to me the error with a connection would trump the error from the preCheck which is why i would think it connection check would be first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're unrelated in the sense that different components are validating it.

We could call txmp.proxyAppConn.Error() earlier in the method if we wanted to. I believe it just needs to run before CheckTxSync to check that the application hasn't for some reason already errored and stopped.

Tbh, I think it's also possible that the application errors after Error() is called but before CheckTx so I think the application needs to handle this anyway and I'm not sure why Error() exists in the first place

mempool/cat/pool.go Outdated Show resolved Hide resolved
mempool/cat/pool.go Outdated Show resolved Hide resolved
mempool/cat/pool.go Outdated Show resolved Hide resolved
Copy link
Contributor Author

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

I think the problem with making a direct copy of the priority mempool is that there are a lot of changes here that are just inherited from previous authors. Not that we shouldn't go over the work in it's entirety it's just that I've made it difficult to identify the changed that I've actually made and the ones that previously existed. I think what I would do next time is to have the first PR just be directly copying the v1 mempool as cat and then build the rest of the PR's of that. I guess I could still do that if people wanted. The nice thing about having the complete change is people can learn more about the workings of the mempool in its entirety.

mempool/cat/pool.go Show resolved Hide resolved
mempool/cat/pool.go Outdated Show resolved Hide resolved
// be broadcasted to peers. Only populated if `broadcast` is enabled
broadcastCh chan types.TxKey
broadcastMtx sync.Mutex
txsToBeBroadcast map[types.TxKey]struct{}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. I was too focused on ensuring that transactions aren't dropped on their way to the reactor. Ordering isn't so important so long as transactions arrive in a timely manner (they are reordered by priority when it comes to block construction).

}

// Early exit if the proxy connection has an error.
if err := txmp.proxyAppConn.Error(); err != 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.

They're unrelated in the sense that different components are validating it.

We could call txmp.proxyAppConn.Error() earlier in the method if we wanted to. I believe it just needs to run before CheckTxSync to check that the application hasn't for some reason already errored and stopped.

Tbh, I think it's also possible that the application errors after Error() is called but before CheckTx so I think the application needs to handle this anyway and I'm not sure why Error() exists in the first place

mempool/cat/pool.go Outdated Show resolved Hide resolved
mempool/cat/pool.go Show resolved Hide resolved
mempool/cat/pool.go Show resolved Hide resolved
mempool/cat/pool.go Outdated Show resolved Hide resolved
mempool/cat/pool.go Show resolved Hide resolved
mempool/cat/pool.go Show resolved Hide resolved
Base automatically changed from cal/cat-part-1 to v0.34.x-celestia January 30, 2023 09:54
evan-forbes
evan-forbes previously approved these changes Jan 30, 2023
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

no blocking feedback other than that from the original PR! LGTM 👍 👍

we might want to add a test for BlobTxs similar to

func TestRemoveBlobTx(t *testing.T) {
txmp := setup(t, 500)
originalTx := []byte{1, 2, 3, 4}
indexWrapper, err := types.MarshalIndexWrapper(originalTx, 100)
require.NoError(t, err)
// create the blobTx
b := tmproto.Blob{
NamespaceId: []byte{1, 2, 3, 4, 5, 6, 7, 8},
Data: []byte{1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 9},
ShareVersion: 0,
}
bTx, err := types.MarshalBlobTx(originalTx, &b)
require.NoError(t, err)
err = txmp.CheckTx(bTx, nil, mempool.TxInfo{})
require.NoError(t, err)
err = txmp.Update(1, []types.Tx{indexWrapper}, abciResponses(1, abci.CodeTypeOK), nil, nil)
require.NoError(t, err)
assert.EqualValues(t, 0, txmp.Size())
assert.EqualValues(t, 0, txmp.SizeBytes())
}

mempool/cat/pool_test.go Outdated Show resolved Hide resolved
mempool/cat/pool_test.go Outdated Show resolved Hide resolved
@cmwaters
Copy link
Contributor Author

@MSevey do you mind giving this a second pass when you've got a moment

mempool/cat/pool.go Outdated Show resolved Hide resolved
Copy link
Member

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

LGTM, happy to approve once the open conversations are resolved.

MSevey
MSevey previously approved these changes Feb 2, 2023
Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

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

I have made some final suggestions that are non-blocking and everything looks good to me.

mempool/cat/pool.go Outdated Show resolved Hide resolved
mempool/cat/pool.go Outdated Show resolved Hide resolved
Comment on lines +119 to +120
// returns an error. This is executed before CheckTx. It only applies to the
// first created block. After that, Update() overwrites the existing value.
Copy link
Contributor

Choose a reason for hiding this comment

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

It only applies to the
// first created block. After that, Update() overwrites the existing value.

What does the first created block mean? You mean f(tx) is applied to all the transaction in the Genesis block?
Also, can you please expand on the second part i.e.,

After that, Update() overwrites the existing value.

It is not clear immediately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes all the txs before height 1 will use this preCheck and postCheck function. Afterwards, the Update function includes new preCheck and postCheck functions that will overwrite the ones initially provided in the constructor. Does that make sense? Shall I modify the comments as so (for the record those weren't my comments to begin with)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the clarification!

Shall I modify the comments as so (for the record those weren't my comments to begin with)

I'd say yes, that would help the readability of the code

mempool/cat/pool.go Outdated Show resolved Hide resolved
mempool/cat/pool.go Show resolved Hide resolved
mempool/cat/pool.go Show resolved Hide resolved
mempool/cat/pool.go Outdated Show resolved Hide resolved
mempool/cat/pool.go Outdated Show resolved Hide resolved
mempool/cat/pool.go Outdated Show resolved Hide resolved
Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

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

No further comments from my side, Looks good to me!

@cmwaters cmwaters merged commit 07b8dbc into v0.34.x-celestia Feb 6, 2023
@cmwaters cmwaters deleted the cal/cat-part-2 branch February 6, 2023 02:03
cmwaters pushed a commit that referenced this pull request Sep 20, 2023
Bumps [docker/login-action](https://github.com/docker/login-action) from 2.1.0 to 2.2.0.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](docker/login-action@v2.1.0...v2.2.0)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

4 participants