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): refactor batch graph to use dependency graph #533

Merged
merged 9 commits into from
Oct 30, 2024

Conversation

Mirko-von-Leipzig
Copy link
Contributor

This PR ports BatchGraph to use DependencyGraph as its foundation.

I implemented this by extending DependencyGraph to have a new pending stage, where the node exists but does not yet have an associated value. For batches this value is its proof i.e. TransactionBatch.

Effectively nodes now have a pending state, and must be promoted by passing in a value for it. I'm not 100% happy with the naming of things. Pending, promotions, processed, committed.

This model does not quite match the TransactionGraph lifecycle, however this was easy to adjust by having TransacionGraph::insert invoke both actions.

The main benefit of this is reducing the test surface.

@Mirko-von-Leipzig Mirko-von-Leipzig marked this pull request as ready for review October 29, 2024 15:06
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! I left some comments inline - but most are minor.

crates/block-producer/src/mempool/dependency_graph.rs Outdated Show resolved Hide resolved
crates/block-producer/src/mempool/batch_graph.rs Outdated Show resolved Hide resolved
crates/block-producer/src/mempool/batch_graph.rs Outdated Show resolved Hide resolved
crates/block-producer/src/mempool/batch_graph.rs Outdated Show resolved Hide resolved
Comment on lines +310 to +312
if self.pending.contains(&key) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is it not an error to try to make a pending node into a root?

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 method is private and called from a few locations. Effectively either callers have to perform this check, or this method could enforce it. I thought it safer to do it here in one place.

More specifically, this is called when

  1. A pending node is promoted (so this check isn't necessary)
  2. A root node is processed, so we check all of its children. We would have to filter children here.
  3. Subgraphs are reverted, where we have to check and filter a bunch of nodes

@Mirko-von-Leipzig Mirko-von-Leipzig merged commit ad20a30 into next-block-producer Oct 30, 2024
8 checks passed
@Mirko-von-Leipzig Mirko-von-Leipzig deleted the mirko-port-batch-graph branch October 30, 2024 09:32
Mirko-von-Leipzig added a commit that referenced this pull request Nov 3, 2024
)

`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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants