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

feat(block-producer): switch to mempool version #562

Merged
merged 19 commits into from
Dec 9, 2024

Conversation

Mirko-von-Leipzig
Copy link
Contributor

@Mirko-von-Leipzig Mirko-von-Leipzig commented Dec 4, 2024

This PR replaces the FIFO based block-producer with a dependency graph mempool variant.

This upgrade has largely already been reviewed via PRs into the next-block-producer feature branch, however this PR will provide the first holistic overview of the completed feature. As such, it would be helpful if those unfamiliar (I guess everyone excluding @bobbinth) would at minimum do a single somewhat thorough pass.

This dependency graph is a pre-requisite for adding fee support, and creating transaction/batch selection strategies.

Outstanding work

This feature is not 100% complete, outstanding tasks are tracked in #514. The new block-producer should however be functionally equivalent to the FIFO queue. Getting this work back into the development branch will make future additions much less painful.

Overview

We introduce a Mempool which acts as the co-ordination point between incoming transactions, batch and block producers.

Inflight state

Incoming transactions are validated against the inflight state i.e. is account state correct, and are the notes valid. The inflight state also adds transaction dependency information e.g. the new transaction becomes the child of the last transaction to update the account, or produce the note.

Dependency graphs

These parent - child dependencies between transactions are tracked in TransactionGraph. In addition we have a batch graph which acts as a sort of overlay on-top of the transaction graph. This complicates matters a bit because batch dependencies connect transactions which previously were not connected (which is why its a separate graph).

Concerns

I am not 100% happy with the mempool implementation. It feels a bit brittle in the sense that one must be careful when making changes. It easy to forget to cleanup a graph node, or remove state in one of the methods.

Its also possible that this shape is a poor match for various selection strategies i.e. one might want access to all meta-data at all stages. We'll have to see and adapt when we get there.

Meta

I'm unsure if I should squash merge this; or keep the various commits as is (which are effectively the various PRs already). Currently I'm leaning towards the latter..

Mirko-von-Leipzig and others added 18 commits October 7, 2024 13:05
Initial outline of the block-producer redesign.

Includes a new mempool which can track transaction and batch dependencies as a graph. This
enables more complex mempool strategies.
This makes `AuthenticatedTransaction` much cheaper to clone and move around.
)

`BatchGraph` now uses `DependencyGraph<BatchJobId, TransactionBatch` internally.

This allows us to focus test energy on a single graph type instead of replicating tests and edge cases with more specific implementations.

This requires adjusting `DependencyGraph` to separate the `insert` method into `insert_pending` and `promote_pending` to support inserting a batch into the graph while still waiting on its proof.
Doing this now in an effort to simplify subsequent work that will be less isolated.
feat(block-producer): merge next into next-block-producer
Replace FIFO with the mempool block-producer rework.

This still has known bugs and issues; notably the client's integration tests sometimes hang.
@Mirko-von-Leipzig Mirko-von-Leipzig marked this pull request as ready for review December 4, 2024 11:48
Copy link
Collaborator

@igamigo igamigo left a comment

Choose a reason for hiding this comment

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

Great work! I've left some minor comments on the parts I've already checked out. I still need to review the server and some of the mempool code.

self.try_build_block().await;
/// Wrapper around tokio's JoinSet that remains pending if the set is empty,
/// instead of returning None.
struct WorkerPool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any specific reason why the worker count is not a field in sthis struct rather than having to be managed in the BatchBuilder? Seems at first sight that it could be managed here, alongside asking for vacancy, etc. unless there's something I'm missing (not that it makes a big difference here). Then maybe BatchBuilder could just be BatchBuilder { batch_interval: Duration, worker_pool: WorkerPool }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its possible to do it that way sure. My thinking was that BatchBuilder contains the configuration options which includes the worker count. Right now these always just default, but I imagine we would want to expose all these options as cli args e.g.

miden-node start block-producer --batch.interval ... --batch.workers 10 --batch.failure-rate 0.1

which would then be passed in here. If we move this around then its no longer pure configuration values, and instead also contains state which means you can no longer do things like trivially overriding defaults and instead need a bunch of fn new-like functions.

I'll move the worker count into the worker pool regardless; since that still works and probably makes more sense.

crates/block-producer/src/mempool/batch_graph.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! Not a very deep review from my end (as I've reviewed most of this code before), but I left some small comments/questions throughout.

crates/block-producer/Cargo.toml Outdated Show resolved Hide resolved
crates/block-producer/Cargo.toml Outdated Show resolved Hide resolved
crates/block-producer/src/lib.rs Show resolved Hide resolved
crates/block-producer/src/store/mod.rs Show resolved Hide resolved
crates/block-producer/src/store/mod.rs Outdated Show resolved Hide resolved
crates/block-producer/src/server/mod.rs Outdated Show resolved Hide resolved
crates/block-producer/src/mempool/dependency_graph.rs Outdated Show resolved Hide resolved
crates/block-producer/src/block_builder/mod.rs Outdated Show resolved Hide resolved
crates/block-producer/src/batch_builder/mod.rs Outdated Show resolved Hide resolved
@bobbinth
Copy link
Contributor

bobbinth commented Dec 5, 2024

I'm unsure if I should squash merge this; or keep the various commits as is (which are effectively the various PRs already). Currently I'm leaning towards the latter..

I would probably merge as is (i.e., without squashing).

@Mirko-von-Leipzig
Copy link
Contributor Author

Note: Review: xxx commits will all be squashed into a single commit before merging, but I'll keep the original PR commits.

Copy link
Collaborator

@tomyrd tomyrd left a comment

Choose a reason for hiding this comment

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

I'm still a little unfamiliar with the node's codebase but I looked through the whole PR and I haven't found any big issues. Left some suggestions/comments, but overall it looks good. It's well explained, I like the graph figures showing the different states/transitions.

I tested this version of the node with the miden-client in the next branch (integration tests and manual tests with the CLI) and I haven't found any issues.

crates/block-producer/src/batch_builder/mod.rs Outdated Show resolved Hide resolved
crates/block-producer/src/batch_builder/mod.rs Outdated Show resolved Hide resolved
crates/block-producer/src/batch_builder/mod.rs Outdated Show resolved Hide resolved
crates/block-producer/src/mempool/batch_graph.rs Outdated Show resolved Hide resolved
@Mirko-von-Leipzig Mirko-von-Leipzig merged commit a1872c5 into next Dec 9, 2024
8 checks passed
@Mirko-von-Leipzig Mirko-von-Leipzig deleted the next-block-producer branch December 9, 2024 08:43
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.

5 participants