Skip to content

Commit 19f5a19

Browse files
committed
refactor(collator): use McDataStuff to store previous McData
1 parent e32b0c8 commit 19f5a19

File tree

10 files changed

+286
-251
lines changed

10 files changed

+286
-251
lines changed

collator/src/collator/do_collate/execute.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl PhaseState for ExecuteState {}
2424
impl Phase<ExecuteState> {
2525
pub fn execute_special_transactions(&mut self) -> Result<()> {
2626
let new_messages = self.extra.executor.create_special_transactions(
27-
&self.state.mc_data.config,
27+
&self.state.mc_data_stuff.current.config,
2828
&mut self.state.collation_data,
2929
)?;
3030
self.extra.messages_reader.add_new_messages(new_messages);
@@ -33,7 +33,7 @@ impl Phase<ExecuteState> {
3333

3434
pub fn execute_tick_transactions(&mut self) -> Result<()> {
3535
let new_messages = self.extra.executor.create_ticktock_transactions(
36-
&self.state.mc_data.config,
36+
&self.state.mc_data_stuff.current.config,
3737
TickTock::Tick,
3838
&mut self.state.collation_data,
3939
)?;
@@ -43,7 +43,7 @@ impl Phase<ExecuteState> {
4343

4444
pub fn execute_tock_transactions(&mut self) -> Result<()> {
4545
let new_messages = self.extra.executor.create_ticktock_transactions(
46-
&self.state.mc_data.config,
46+
&self.state.mc_data_stuff.current.config,
4747
TickTock::Tock,
4848
&mut self.state.collation_data,
4949
)?;

collator/src/collator/do_collate/finalize.rs

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ use crate::queue_adapter::MessageQueueAdapter;
3535
use crate::tracing_targets;
3636
use crate::types::processed_upto::{ProcessedUptoInfoExtension, ProcessedUptoInfoStuff};
3737
use crate::types::{
38-
BlockCandidate, CollationSessionInfo, CollatorConfig, McData, ShardDescriptionShortExt,
39-
ShardHashesExt,
38+
BlockCandidate, CollationSessionInfo, CollatorConfig, McData, McDataStuff,
39+
ShardDescriptionShortExt, ShardHashesExt,
4040
};
4141
use crate::utils::block::detect_top_processed_to_anchor;
4242

@@ -92,7 +92,8 @@ impl Phase<FinalizeState> {
9292
} else {
9393
let mut top_other_updated_shard_blocks_ids: Vec<BlockId> = self
9494
.state
95-
.mc_data
95+
.mc_data_stuff
96+
.current
9697
.shards
9798
.iter()
9899
.filter(|(shard, descr)| {
@@ -101,7 +102,7 @@ impl Phase<FinalizeState> {
101102
.map(|(shard_ident, descr)| descr.get_block_id(*shard_ident))
102103
.collect();
103104

104-
top_other_updated_shard_blocks_ids.push(self.state.mc_data.block_id);
105+
top_other_updated_shard_blocks_ids.push(self.state.mc_data_stuff.current.block_id);
105106

106107
top_other_updated_shard_blocks_ids
107108
};
@@ -288,15 +289,15 @@ impl Phase<FinalizeState> {
288289
let mut public_libraries = executor.executor_params().libraries.clone();
289290

290291
let is_masterchain = shard.is_masterchain();
291-
let config_address = &self.state.mc_data.config.address;
292+
let config_address = &self.state.mc_data_stuff.current.config.address;
292293

293294
// Compute a masterchain block seqno which will reference this block.
294295
let ref_by_mc_seqno = if is_masterchain {
295296
// The block itself for the masterchain
296297
collation_data.block_id_short.seqno
297298
} else {
298299
// And the next masterchain block for shards
299-
self.state.mc_data.block_id.seqno + 1
300+
self.state.mc_data_stuff.current.block_id.seqno + 1
300301
};
301302

302303
let mut processed_accounts_res = Ok(Default::default());
@@ -357,15 +358,15 @@ impl Phase<FinalizeState> {
357358
&processed_accounts.shard_accounts,
358359
&in_msgs,
359360
&out_msgs,
360-
&self.state.mc_data.config,
361+
&self.state.mc_data_stuff.current.config,
361362
)?;
362363

363364
// Validate value flow with simple rules.
364365
if collator_config.check_value_flow {
365366
Self::check_value_flow(
366367
&value_flow,
367368
&self.state.collation_data,
368-
&self.state.mc_data.config,
369+
&self.state.mc_data_stuff.current.config,
369370
&self.state.prev_shard_data,
370371
&in_msgs,
371372
&out_msgs,
@@ -412,7 +413,10 @@ impl Phase<FinalizeState> {
412413
(Some(extra), None)
413414
} else {
414415
build_mc_state_extra_elapsed = Duration::ZERO;
415-
(None, Some(self.state.mc_data.make_block_ref()))
416+
(
417+
None,
418+
Some(self.state.mc_data_stuff.current.make_block_ref()),
419+
)
416420
};
417421

418422
// HACK: make every 3-d block incorrect on debug if env variable defined
@@ -438,7 +442,7 @@ impl Phase<FinalizeState> {
438442
gen_validator_list_hash_short: collation_session.collators().short_hash,
439443
gen_catchain_seqno: collation_session.seqno(),
440444
min_ref_mc_seqno: self.state.collation_data.min_ref_mc_seqno,
441-
prev_key_block_seqno: self.state.mc_data.prev_key_block_seqno,
445+
prev_key_block_seqno: self.state.mc_data_stuff.current.prev_key_block_seqno,
442446
master_ref: master_ref.as_ref().map(Lazy::new).transpose()?,
443447
..Default::default()
444448
};
@@ -452,7 +456,12 @@ impl Phase<FinalizeState> {
452456
// info.want_split = false;
453457
// info.want_merge = false;
454458

455-
let bc_global_version = self.state.mc_data.config.get_global_version()?;
459+
let bc_global_version = self
460+
.state
461+
.mc_data_stuff
462+
.current
463+
.config
464+
.get_global_version()?;
456465
if bc_global_version
457466
.capabilities
458467
.contains(GlobalCapability::CapReportVersion)
@@ -500,7 +509,8 @@ impl Phase<FinalizeState> {
500509
// because mempool will not produce more anchors
501510
let max_consensus_lag_rounds = self
502511
.state
503-
.mc_data
512+
.mc_data_stuff
513+
.current
504514
.config
505515
.get_consensus_config()?
506516
.max_consensus_lag_rounds as u64;
@@ -525,7 +535,7 @@ impl Phase<FinalizeState> {
525535

526536
// build new state
527537
let mut new_observable_state = Box::new(ShardStateUnsplit {
528-
global_id: self.state.mc_data.global_id,
538+
global_id: self.state.mc_data_stuff.current.global_id,
529539
shard_ident: new_block_info.shard,
530540
seqno: new_block_info.seqno,
531541
vert_seqno: 0,
@@ -629,7 +639,7 @@ impl Phase<FinalizeState> {
629639

630640
// construct block
631641
let block = Block {
632-
global_id: self.state.mc_data.global_id,
642+
global_id: self.state.mc_data_stuff.current.global_id,
633643
info: Lazy::new(&new_block_info)?,
634644
value_flow: Lazy::new(&value_flow)?,
635645
state_update: Lazy::new(&state_update)?,
@@ -702,7 +712,7 @@ impl Phase<FinalizeState> {
702712

703713
let processed_to_anchor_id = processed_upto.get_min_externals_processed_to()?.0;
704714

705-
let new_mc_data = match mc_state_extra {
715+
let mc_data_stuff = match mc_state_extra {
706716
None => None,
707717
Some(extra) => {
708718
let prev_key_block_seqno = if extra.after_key_block {
@@ -720,7 +730,7 @@ impl Phase<FinalizeState> {
720730
processed_to_anchor_id,
721731
);
722732

723-
Some(Arc::new(McData {
733+
let current_mc_data = Arc::new(McData {
724734
global_id: new_block.as_ref().global_id,
725735
block_id: *new_block.id(),
726736

@@ -744,8 +754,15 @@ impl Phase<FinalizeState> {
744754
.collation_data
745755
.mc_shards_processed_to_by_partitions
746756
.clone(),
747-
prev_mc_block_id: Some(self.state.mc_data.block_id),
748-
}))
757+
prev_mc_block_id: Some(self.state.mc_data_stuff.current.block_id),
758+
});
759+
760+
let mc_data_stuff = McDataStuff {
761+
current: current_mc_data,
762+
previous: Some(self.state.mc_data_stuff.current.clone()),
763+
};
764+
765+
Some(mc_data_stuff)
749766
}
750767
};
751768

@@ -772,9 +789,9 @@ impl Phase<FinalizeState> {
772789
value_flow,
773790
created_by: self.state.collation_data.created_by,
774791
queue_diff_aug: queue_diff.build(&new_block_id),
775-
consensus_info: new_mc_data.as_ref().map_or_else(
776-
|| self.state.mc_data.consensus_info,
777-
|mcd| mcd.consensus_info,
792+
consensus_info: mc_data_stuff.as_ref().map_or_else(
793+
|| self.state.mc_data_stuff.current.consensus_info,
794+
|mcd| mcd.current.consensus_info,
778795
),
779796
processed_upto,
780797
});
@@ -798,11 +815,11 @@ impl Phase<FinalizeState> {
798815
FinalizeBlockResult {
799816
collation_data: self.state.collation_data,
800817
block_candidate,
801-
mc_data: new_mc_data,
818+
mc_data_stuff,
819+
old_mc_data_stuff: self.state.mc_data_stuff,
802820
new_state_root,
803821
new_observable_state,
804822
finalize_wu_total,
805-
old_mc_data: self.state.mc_data,
806823
collation_config: self.state.collation_config,
807824
},
808825
self.extra.execute_result,

0 commit comments

Comments
 (0)