-
Notifications
You must be signed in to change notification settings - Fork 672
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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( |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 1625
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 removemut
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.