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

chore: add create client macro #1874

Closed
wants to merge 1 commit into from
Closed

Conversation

nadin-Starkware
Copy link
Collaborator

@nadin-Starkware nadin-Starkware commented Nov 7, 2024

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.

Project coverage is 5.50%. Comparing base (e3165c4) to head (8a6d6c1).
Report is 279 commits behind head on main.

Files with missing lines Patch % Lines
crates/sequencer_node/src/clients.rs 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #1874       +/-   ##
==========================================
- Coverage   40.10%   5.50%   -34.60%     
==========================================
  Files          26     261      +235     
  Lines        1895   30326    +28431     
  Branches     1895   30326    +28431     
==========================================
+ Hits          760    1670      +910     
- Misses       1100   28601    +27501     
- Partials       35      55       +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 8 unresolved discussions (waiting on @nadin-Starkware)


crates/sequencer_node/src/clients.rs line 44 at r1 (raw file):

/// This macro simplifies the creation of a client by evaluating the execution mode
/// and conditionally constructing the client only if the mode is enabled (either
/// LocalExecutionWithRemoteDisabled or LocalExecutionWithRemoteEnabled).

Let's make this more concise: wydt about

A macro for creating a component client, determined by the component's execution mode. Returns a local client if the component is run locally, otherwise `None`.

Later when adding the remote client we can modify this doc to detail the remote client option as well.

Code quote:

/// A macro to create a shared client based on the component's execution mode.
///
/// This macro simplifies the creation of a client by evaluating the execution mode
/// and conditionally constructing the client only if the mode is enabled (either
/// LocalExecutionWithRemoteDisabled or LocalExecutionWithRemoteEnabled).

crates/sequencer_node/src/clients.rs line 49 at r1 (raw file):

///
/// * $execution_mode - A reference to the execution mode to evaluate, expected to be of type
///   ComponentExecutionMode.

A reference to the component's execution mode, i.e., type &ComponentExecutionMode

Code quote:

/// * $execution_mode - A reference to the execution mode to evaluate, expected to be of type
///   ComponentExecutionMode.

crates/sequencer_node/src/clients.rs line 50 at r1 (raw file):

/// * $execution_mode - A reference to the execution mode to evaluate, expected to be of type
///   ComponentExecutionMode.
/// * $client_type - The type of the client to create, such as LocalBatcherClient.

The client type to create, e.g., LocalBatcherClient. The client type should have a function $client_type::new(tx : $channel_expr).

Code quote:

The type of the client to create, such as LocalBatcherClient.

crates/sequencer_node/src/clients.rs line 51 at r1 (raw file):

///   ComponentExecutionMode.
/// * $client_type - The type of the client to create, such as LocalBatcherClient.
/// * $channel_expr - An expression to retrieve the channel required for the client, e.g.,

Sender side for the client.

Code quote:

An expression to retrieve the channel required for the client

crates/sequencer_node/src/clients.rs line 52 at r1 (raw file):

/// * $client_type - The type of the client to create, such as LocalBatcherClient.
/// * $channel_expr - An expression to retrieve the channel required for the client, e.g.,
///   channels.take_batcher_tx().

Let's make this the 2nd arguement (i.e., replace the order with client type), so we can better describe what client type is.

Code quote:

/// * $channel_expr - An expression to retrieve the channel required for the client, e.g.,
///   channels.take_batcher_tx().

crates/sequencer_node/src/clients.rs line 57 at r1 (raw file):

///
/// An `Option<Arc<dyn ClientType>>` containing the client if the execution mode is enabled,
/// or None if the execution mode is Disabled.

Be more explicit regarding the enabled option, as Disabled is an actual enum variant whereas enabled isn't.

Code quote:

/// An `Option<Arc<dyn ClientType>>` containing the client if the execution mode is enabled,
/// or None if the execution mode is Disabled.

crates/sequencer_node/src/clients.rs line 74 at r1 (raw file):

///     None => println!("Client not created because the execution mode is disabled."),
/// }
/// ```

Can you make this example compile/pass?
I.e., drop the ignore

Code quote:

/// ```rust,ignore
/// // Assuming ComponentExecutionMode and channels are defined, and LocalBatcherClient
/// // has a new method that accepts a channel.
/// let batcher_client: Option<SharedBatcherClient> = create_client!(
///     &config.components.batcher.execution_mode,
///     LocalBatcherClient,
///     channels.take_batcher_tx()
/// );
///
/// match batcher_client {
///     Some(client) => println!("Client created: {:?}", client),
///     None => println!("Client not created because the execution mode is disabled."),
/// }
/// ```

crates/sequencer_node/src/clients.rs line 91 at r1 (raw file):

    channels: &mut SequencerNodeCommunication,
) -> SequencerNodeClients {
    let batcher_client: Option<SharedBatcherClient> = create_client!(

Are these type annotations required?

Code quote:

Option<SharedBatcherClient>

Copy link
Contributor

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 8 unresolved discussions (waiting on @nadin-Starkware)


crates/sequencer_node/src/clients.rs line 110 at r1 (raw file):

        &config.components.mempool_p2p.execution_mode,
        LocalMempoolP2pPropagatorClient,
        channels.take_mempool_p2p_propagator_tx()

Not for this pr:

When'll have the remote clients, they will also need the channel_tx, so we'd have to switch from using take to clone. FYI.

Code quote:

channels.take_mempool_p2p_propagator_tx()

Copy link
Collaborator Author

@nadin-Starkware nadin-Starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 8 unresolved discussions (waiting on @Itay-Tsabary-Starkware)


crates/sequencer_node/src/clients.rs line 44 at r1 (raw file):

Previously, Itay-Tsabary-Starkware wrote…

Let's make this more concise: wydt about

A macro for creating a component client, determined by the component's execution mode. Returns a local client if the component is run locally, otherwise `None`.

Later when adding the remote client we can modify this doc to detail the remote client option as well.

Done.


crates/sequencer_node/src/clients.rs line 49 at r1 (raw file):

Previously, Itay-Tsabary-Starkware wrote…

A reference to the component's execution mode, i.e., type &ComponentExecutionMode

Done.


crates/sequencer_node/src/clients.rs line 50 at r1 (raw file):

Previously, Itay-Tsabary-Starkware wrote…

The client type to create, e.g., LocalBatcherClient. The client type should have a function $client_type::new(tx : $channel_expr).

Done.


crates/sequencer_node/src/clients.rs line 51 at r1 (raw file):

Previously, Itay-Tsabary-Starkware wrote…

Sender side for the client.

Done.


crates/sequencer_node/src/clients.rs line 52 at r1 (raw file):

Previously, Itay-Tsabary-Starkware wrote…

Let's make this the 2nd arguement (i.e., replace the order with client type), so we can better describe what client type is.

Done.


crates/sequencer_node/src/clients.rs line 57 at r1 (raw file):

Previously, Itay-Tsabary-Starkware wrote…

Be more explicit regarding the enabled option, as Disabled is an actual enum variant whereas enabled isn't.

Done.


crates/sequencer_node/src/clients.rs line 74 at r1 (raw file):

Previously, Itay-Tsabary-Starkware wrote…

Can you make this example compile/pass?
I.e., drop the ignore

No, I get not found in this scope on the macro.


crates/sequencer_node/src/clients.rs line 91 at r1 (raw file):

Previously, Itay-Tsabary-Starkware wrote…

Are these type annotations required?

The type annotation is necessary because it tells Rust to treat LocalComponentClient<BatcherRequest, BatcherResponse> as the trait object BatcherClient. This annotation triggers a coercion from Arc to Arc, which Rust wouldn’t do automatically without the annotation, resulting in a type mismatch.

@nadin-Starkware nadin-Starkware changed the base branch from spr/main/7ca0f454 to main November 10, 2024 11:02
Copy link

Artifacts upload triggered. View details here

Copy link

Benchmark movements:
full_committer_flow performance regressed!
full_committer_flow time: [29.875 ms 29.924 ms 29.982 ms]
change: [+2.0339% +2.2475% +2.4777%] (p = 0.00 < 0.05)
Performance has regressed.
Found 4 outliers among 100 measurements (4.00%)
2 (2.00%) high mild
2 (2.00%) high severe

@nadin-Starkware nadin-Starkware force-pushed the spr/main/73967fda branch 2 times, most recently from a7631f4 to 3c496da Compare November 10, 2024 12:25
Copy link
Contributor

@Itay-Tsabary-Starkware Itay-Tsabary-Starkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @nadin-Starkware)

@nadin-Starkware
Copy link
Collaborator Author

✓ Commit merged in pull request #1909

@github-actions github-actions bot locked and limited conversation to collaborators Nov 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants