Skip to content

Commit

Permalink
feature(collator): moved pre-accept blocks under feature
Browse files Browse the repository at this point in the history
  • Loading branch information
SmaGMan committed Jun 24, 2024
1 parent e10add2 commit 7dc37d2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tycho-storage = { workspace = true }
tycho-util = { workspace = true }

[dev-dependencies]
tycho-collator = { workspace = true, features = ["test"] }
tycho-collator = { workspace = true, features = ["test", "pre-accept-blocks"] }
tycho-storage = { workspace = true, features = ["test"] }

[build-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ tycho-storage = { workspace = true, features = ["test"] }
tycho-util = { workspace = true, features = ["test"] }

[features]
default = []
default = ["pre-accept-blocks"]
test = []
block-creator-stats = []
pre-accept-blocks = []

[lints]
workspace = true
13 changes: 11 additions & 2 deletions collator/src/collator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,18 @@ impl CollatorStdImpl {
let _histogram =
HistogramGuardWithLabels::begin("tycho_collator_update_mc_data_time", &labels);

let prev_states_loaded_from_storage = self.working_state().prev_states_loaded_from_storage;
#[cfg(feature = "pre-accept-blocks")]
let new_mc_state = self
.state_node_adapter
.load_state(new_mc_state.block_id())
.await?;

#[cfg(feature = "pre-accept-blocks")]
let load_prev_states_from_storage = !self.working_state().prev_states_loaded_from_storage;
#[cfg(not(feature = "pre-accept-blocks"))]
let load_prev_states_from_storage = false;

if prev_states_loaded_from_storage {
if !load_prev_states_from_storage {
let working_state_mut = self
.working_state
.as_mut()
Expand Down
3 changes: 2 additions & 1 deletion collator/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,8 @@ where
.clone();

// pre-accept shard block to store new shard state
if !candidate_id.shard.is_masterchain() {
#[cfg(feature = "pre-accept-blocks")]
{
let histogram = HistogramGuard::begin_with_labels(
"tycho_collator_process_collated_block_candidate_pre_accept_total_time",
labels,
Expand Down
8 changes: 7 additions & 1 deletion collator/src/state_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub trait StateNodeAdapter: Send + Sync + 'static {
async fn load_block_handle(&self, block_id: &BlockId) -> Result<Option<BlockHandle>>;

/// Just store updated state
#[cfg(feature = "pre-accept-blocks")]
async fn pre_accept_block(
&self,
block: BlockStuffForSync,
Expand Down Expand Up @@ -133,6 +134,7 @@ impl StateNodeAdapter for StateNodeAdapterStdImpl {
Ok(self.storage.block_handle_storage().load_handle(block_id))
}

#[cfg(feature = "pre-accept-blocks")]
async fn pre_accept_block(
&self,
block: BlockStuffForSync,
Expand All @@ -145,7 +147,11 @@ impl StateNodeAdapter for StateNodeAdapterStdImpl {
let block_stuff = &block.block_stuff_aug.data;
let archive_data = &block.block_stuff_aug.archive_data;
let info = block_stuff.load_info()?;
let mc_ref_seqno = info.min_ref_mc_seqno + 1;
let mc_ref_seqno = if block.block_id.shard.is_masterchain() {
block.block_id.seqno
} else {
info.min_ref_mc_seqno + 1
};
let store_res = block_storage
.store_block_data(block_stuff, archive_data, BlockMetaData {
is_key_block: info.key_block,
Expand Down

0 comments on commit 7dc37d2

Please sign in to comment.