Skip to content

Conversation

dhrubabasu
Copy link
Contributor

@dhrubabasu dhrubabasu commented Nov 23, 2023

Why this should be merged

MempoolTxVerifier is a thin wrapper on StandardTxVerifier. It is only used in the P-Chain block executor manager VerifyTx function. I found this pattern confusing when trying to figure out how mempool txs were being verified. This is an attempt at making this process easier to understand.

How this works

In-lines MempoolTxVerifier logic to improve readability

How this was tested

CI

@dhrubabasu dhrubabasu added the cleanup Code quality improvement label Nov 23, 2023
@dhrubabasu dhrubabasu self-assigned this Nov 23, 2023
@@ -359,15 +348,6 @@ func TestStandardTxExecutorAddDelegator(t *testing.T) {
}
err = tx.Unsigned.Visit(&executor)
require.ErrorIs(err, tt.expectedExecutionErr)

mempoolExecutor := MempoolTxVerifier{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We run all the txs through the StandardTxExecutor already which the MempoolTxVerifier called internally anyway. This can be removed outside of this PR.

@dhrubabasu dhrubabasu changed the title vms/platformvm: Remove mempool tx verifier struct [WIP] vms/platformvm: Remove mempool tx verifier struct Nov 23, 2023
@dhrubabasu dhrubabasu changed the title [WIP] vms/platformvm: Remove mempool tx verifier struct vms/platformvm: Remove mempool tx verifier struct Nov 24, 2023
@dhrubabasu dhrubabasu marked this pull request as ready for review November 24, 2023 01:56
Copy link
Contributor

@abi87 abi87 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 this is a step in the wrong direction:

  1. I am fine having small structs that do one clear thing, even if a small one. To me MempoolTxVerifier says clearly that mempool txs are validated not on chain tip state (as you may naively assume) but on a state version built on top of it. MempoolTxVerifier does call then the StandardTxExecutor, which tells us that, apart from the state, we reuse the very same code to validator blocks and mempool txs. This seems good engineering to me
  2. Block manager is already too big and it's doing many so many stuff that should be break up. The way I see it currently:
    • Support blocks verification, acceptance and rejection
    • Holds chain state at different heights (probably it's main function)
    • Verify mempool txs, which does not make sense at all to me, but that I accepted as a temporary solution to move forward with the mempool cleanup.

I think if we want to keep refactoring code, we should focus on breaking block Manager into smaller chunks, rather than extending its scope.

@dhrubabasu dhrubabasu force-pushed the remove-tx-mempool-verifier branch from abe32c5 to d41fd0b Compare December 12, 2023 12:09
@dhrubabasu
Copy link
Contributor Author

dhrubabasu commented Dec 12, 2023

In-lining the struct can save us one alloc/op (and is marginally faster). Since this is run for each tx received from AppGossip, I think we should consider in-lining it. The manager already has the VerifyTx function so this PR does not make the interface any bigger

// dev branch
Benchmark/manager.VerifyTx-10                  1537694              7424 ns/op            4744 B/op          62 allocs/op

// this PR
Benchmark/manager.VerifyTx-10                  1678203              7138 ns/op            4680 B/op          61 allocs/op

Unfortunately we can't re-use the MempoolTxVerifier logic when we're verifying the mempool txs before putting them into a block so this logic is only used here (#2359)

@dhrubabasu dhrubabasu changed the title vms/platformvm: Remove mempool tx verifier struct vms/platformvm: Remove MempoolTxVerifier Jan 17, 2024
Copy link
Contributor

@abi87 abi87 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 question about naming. Other than that LGTM

ParentID: m.preferred,
StateVersions: m,
Tx: tx,
stateDiff, err := state.NewDiff(m.preferred, m)
Copy link
Contributor

Choose a reason for hiding this comment

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

q: since we're dropping the mempool verifier, should we rename this VerifyTx method as VerifyMempoolTx?

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 think we already use VerifyTx exclusively for mempool verification (including in the network pkg). Since we're not modifying the function usage, I think the same name is okay and keeps the diff minimal

@dhrubabasu dhrubabasu force-pushed the remove-tx-mempool-verifier branch from 65d8c92 to 4e0df0c Compare January 18, 2024 17:27
@dhrubabasu dhrubabasu changed the base branch from dev to modify-AdvanceTimeTo January 18, 2024 21:40
@dhrubabasu dhrubabasu added this to the v1.10.19 milestone Jan 18, 2024
Base automatically changed from modify-AdvanceTimeTo to master January 18, 2024 21:50
@StephenButtolph StephenButtolph added this pull request to the merge queue Jan 18, 2024
Merged via the queue into master with commit 4d16cc3 Jan 18, 2024
@StephenButtolph StephenButtolph deleted the remove-tx-mempool-verifier branch January 18, 2024 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants