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

[Refactor] 3: Switch legacy to coordinator #239

Merged
merged 29 commits into from
Dec 6, 2024
Merged

Conversation

QuentinI
Copy link
Contributor

@QuentinI QuentinI commented Nov 6, 2024

Closes #206

This PR:

Switches legacy builder to builder state coordinator.

This PR does not:

Key places to review:

@QuentinI QuentinI changed the title [Refactor] 3: Switch legacy to coordinator [WIP] [Refactor] 3: Switch legacy to coordinator Nov 6, 2024
@coveralls
Copy link

coveralls commented Nov 6, 2024

Coverage Status

Changes unknown
when pulling d418ff6 on ag/refactor-legacy
into ** on main**.

@QuentinI QuentinI force-pushed the ag/refactor-legacy branch 3 times, most recently from a685fff to 03e7677 Compare November 8, 2024 19:26
@QuentinI QuentinI changed the base branch from main to ag/refactor-marketplace November 8, 2024 19:26
@QuentinI QuentinI force-pushed the ag/refactor-marketplace branch from ce9a7dd to 09a1df3 Compare November 8, 2024 19:58
@QuentinI QuentinI force-pushed the ag/refactor-legacy branch 3 times, most recently from 92455e6 to f361ed2 Compare November 11, 2024 16:52
@QuentinI QuentinI force-pushed the ag/refactor-marketplace branch from 09a1df3 to 4a09ecb Compare November 11, 2024 16:53
@QuentinI QuentinI force-pushed the ag/refactor-marketplace branch from 4a09ecb to 269a518 Compare November 12, 2024 14:32
@QuentinI QuentinI force-pushed the ag/refactor-marketplace branch 2 times, most recently from 28d258d to 25012a1 Compare November 12, 2024 15:15
@QuentinI QuentinI force-pushed the ag/refactor-legacy branch 2 times, most recently from 294d4e7 to 4454c92 Compare November 12, 2024 15:27
@QuentinI QuentinI force-pushed the ag/refactor-marketplace branch from 25012a1 to 26433c1 Compare November 12, 2024 15:27
@QuentinI QuentinI force-pushed the ag/refactor-legacy branch 3 times, most recently from 30842fa to b306471 Compare November 12, 2024 15:35
@QuentinI QuentinI force-pushed the ag/refactor-marketplace branch from 26433c1 to 25e9b7b Compare November 12, 2024 15:37
@QuentinI QuentinI force-pushed the ag/refactor-marketplace branch from 25e9b7b to bd92200 Compare November 12, 2024 15:40
@QuentinI QuentinI force-pushed the ag/refactor-legacy branch 4 times, most recently from 0bb5c40 to 9de7a38 Compare November 14, 2024 15:48
@@ -159,6 +159,24 @@ where
<Types::BlockPayload as BlockPayload<Types>>::from_bytes(encoded_txns, metadata);
let txn_commitments = block_payload.transaction_commitments(metadata);

let views_since_nonempty_block = if txn_commitments.is_empty() {
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 is used by legacy builder to decide whether we want to build empty block to prioritize finalization.

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 was moved to its own file. The only change is making it atomic to reduce amount of locks we juggle in the legacy builder.

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 file factors out the blocks and block_cache fields of legacy's GlobalState.
The only actual change made is instead of Lru this uses the tiered map, so that we can prune blocks we know we won't need instead of hoping our Lru size is just right and we don't evict blocks we may yet need but also don't keep around too many blocks we'll never need again.

/// `WaitAndKeep` is a helper enum that allows for the lazy polling of a single
/// value from an unbound receiver.
#[derive(Debug)]
pub enum WaitAndKeep<T> {
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 was moved to the shared crate and refactored a bit.


// TODO: Update commitment calculation with the new `commit`.
// <https://github.com/EspressoSystems/marketplace-builder-core/issues/143>
trait LegacyCommit<T: NodeType> {
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 don't need this anymore!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where most of the actual refactoring happened.

@@ -41,6 +42,28 @@ pub use marketplace_builder_shared::utils::EventServiceStream;

use crate::hooks::BuilderHooks;

/// Configuration to initialize the builder
#[derive(Debug, Clone)]
pub struct BuilderConfig<Types: NodeType> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sneaked in a config for the service instead of passing a bajilion parameters to the constructor

pub mod basic_test;
pub mod integration;
pub mod order_test;

pub(crate) struct SimulatedChainState {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to shared crate, so that legacy tests can take advantage of this as well.

@QuentinI QuentinI changed the title [WIP] [Refactor] 3: Switch legacy to coordinator [Refactor] 3: Switch legacy to coordinator Nov 25, 2024
Copy link
Member

@shenkeyao shenkeyao left a comment

Choose a reason for hiding this comment

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

This is a big one! I left many comments but structure-wise this looks really good.

crates/legacy/src/service.rs Outdated Show resolved Hide resolved
crates/marketplace/src/lib.rs Outdated Show resolved Hide resolved
crates/shared/src/coordinator/mod.rs Outdated Show resolved Hide resolved
crates/marketplace/src/testing/basic_test.rs Show resolved Hide resolved
crates/marketplace/src/testing/integration.rs Show resolved Hide resolved
crates/shared/src/state.rs Outdated Show resolved Hide resolved
crates/shared/src/block.rs Outdated Show resolved Hide resolved
crates/legacy/src/testing/mod.rs Outdated Show resolved Hide resolved
crates/legacy/src/testing/mod.rs Outdated Show resolved Hide resolved
crates/legacy/src/service.rs Outdated Show resolved Hide resolved
#[repr(C)]
pub(crate) struct MutableState {
pub max_block_size: u64,
pub last_block_size_increment: u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to have a comment on what last_block_size_increment is about?

/// If increment period has elapsed or `force` flag is set,
/// increment [`Self::max_block_size`] by current value * [`Self::MAX_BLOCK_SIZE_CHANGE_DIVISOR`]
/// with [`Self::protocol_max_block_size`] as a ceiling
pub fn try_increment_block_size(&self, force: bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the use case of this function? Just trying to get more understanding on the design motivation of try_increment_block_size and decrement_block_size.

Copy link
Contributor Author

@QuentinI QuentinI Nov 27, 2024

Choose a reason for hiding this comment

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

I added some docs to the BlockSizeLimits struct itself, LMK if they don't clear it up enough

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 detailed comment!

@@ -4,8 +4,29 @@ use async_trait::async_trait;
use hotshot::types::Event;
use hotshot_types::traits::node_implementation::NodeType;

/// A trait for hooks into the builder service. Used to further customize
/// builder behaviour in ways not possible in builder core.
/// If you don't such customisation, use [`NoHooks`].
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "If you don't use such"

self.parent_block_references.last_nonempty_view
} else {
// This block is non-empty
Some(quorum_proposal.view_number)
Copy link
Member

Choose a reason for hiding this comment

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

IIRC in the previous commit you updated self.parent_block_references.last_nonempty_view as well. Should we keep it?

Copy link
Contributor Author

@QuentinI QuentinI Nov 28, 2024

Choose a reason for hiding this comment

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

Sorry, not sure I understand what you mean. Could you please clarify?

Copy link
Member

Choose a reason for hiding this comment

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

As discussed today this actually looks good!

crates/legacy/src/service.rs Outdated Show resolved Hide resolved
crates/shared/src/testing/constants.rs Outdated Show resolved Hide resolved
@QuentinI QuentinI merged commit 95de223 into main Dec 6, 2024
10 checks passed
@QuentinI QuentinI deleted the ag/refactor-legacy branch December 6, 2024 17:48
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.

[Builder State Refactor] - Integrate into the legacy builder
4 participants