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: extract chunk producer logic from Client #12852

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

Longarithm
Copy link
Member

Reducing number of fields in Client from 36 to 31 and number of lines in client.rs from 2913 to 2624.
This is done by separating logic exclusive to chunk production, thus new struct is named ChunkProducer. It is almost as simple as moving some methods from Client to ChunkProducer.

I had to pass chain_validate: &dyn Fn(&SignedTransaction) -> bool, through which is not great but already used in other places. Also, I remove mut keywords because the closure doesn't mutate neither environment nor variable.

Later, we can also hide produce_chunks and state witness production logic. This process is a bit heavy because currently access to the whole Client is used everywhere - which is not really needed.
Another next step can be separating BlockProducer logic.

@Longarithm Longarithm requested a review from a team as a code owner January 31, 2025 13:35
Copy link

codecov bot commented Jan 31, 2025

Codecov Report

Attention: Patch coverage is 80.68670% with 45 lines in your changes missing coverage. Please review.

Project coverage is 70.39%. Comparing base (cb4c02f) to head (f3826ef).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
chain/client/src/chunk_producer.rs 75.30% 32 Missing and 8 partials ⚠️
chain/chain/src/store/mod.rs 93.75% 0 Missing and 2 partials ⚠️
chain/chain/src/chain.rs 50.00% 0 Missing and 1 partial ⚠️
chain/client/src/client_actor.rs 0.00% 1 Missing ⚠️
chain/client/src/debug.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12852      +/-   ##
==========================================
+ Coverage   70.22%   70.39%   +0.17%     
==========================================
  Files         851      852       +1     
  Lines      174195   174261      +66     
  Branches   174195   174261      +66     
==========================================
+ Hits       122322   122674     +352     
+ Misses      46644    46340     -304     
- Partials     5229     5247      +18     
Flag Coverage Δ
backward-compatibility 0.16% <0.00%> (-0.01%) ⬇️
db-migration 0.16% <0.00%> (-0.01%) ⬇️
genesis-check 1.41% <0.00%> (?)
linux 70.07% <86.05%> (+0.16%) ⬆️
linux-nightly 70.03% <80.25%> (+<0.01%) ⬆️
pytests 1.70% <0.00%> (+1.54%) ⬆️
sanity-checks 1.52% <0.00%> (?)
unittests 70.22% <80.68%> (+<0.01%) ⬆️
upgradability 0.20% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Contributor

@shreyan-gupta shreyan-gupta 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!

@@ -352,8 +368,8 @@ impl ChainStore {
/// But we need to implement a more theoretically correct algorithm if shard layouts will change
/// more often in the future
/// <https://github.com/near/nearcore/issues/4877>
pub fn get_outgoing_receipts_for_shard(
&self,
pub fn get_outgoing_receipts_for_shard_from_store(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! Does it make sense to push this in the same helper module we had created last time?

@@ -8,13 +8,16 @@ pub use near_client_primitives::types::{
QueryError, Status, StatusResponse, SyncStatus, TxStatus, TxStatusError,
};

pub use crate::client::{Client, ProduceChunkResult};
#[cfg(feature = "test_features")]
pub use crate::chunk_producer::AdvProduceChunksMode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking, do we need to expose this outside the module?

@@ -6,7 +6,8 @@

use near_chain_configs::Genesis;
use near_client::test_utils::{create_chunk_on_height, TestEnv};
use near_client::{ProcessTxResponse, ProduceChunkResult};
use near_client::ProcessTxResponse;
use near_client::ProduceChunkResult;
Copy link
Contributor

Choose a reason for hiding this comment

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

mini nit: Can revert to use near_client::{ProcessTxResponse, ProduceChunkResult};? Fine to leave as is.

@@ -1966,14 +1671,16 @@ impl Client {
.with_label_values(&[&shard_id.to_string()])
.start_timer();
let last_header = Chain::get_prev_chunk_header(epoch_manager, block, shard_id).unwrap();
match self.try_produce_chunk(
let result = self.chunk_producer.produce_chunk(
Copy link
Contributor

@shreyan-gupta shreyan-gupta Jan 31, 2025

Choose a reason for hiding this comment

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

How did we determine if the parent function produce_chunks was supposed to be a part of client.rs or chunk_producer.rs module?

Copy link
Contributor

Choose a reason for hiding this comment

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

Line 1625

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.

2 participants