Skip to content

Commit

Permalink
feat(collator): impl block creator by anchor author
Browse files Browse the repository at this point in the history
  • Loading branch information
serejkaaa512 authored and SmaGMan committed Jun 28, 2024
1 parent 7e2b570 commit 3a11911
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
11 changes: 7 additions & 4 deletions collator/src/collator/do_collate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ impl CollatorStdImpl {
top_shard_blocks_info: Option<Vec<TopBlockDescription>>,
) -> Result<()> {
let labels = &[("workchain", self.shard_id.workchain().to_string())];
let histogram = HistogramGuard::begin_with_labels("tycho_do_collate_total_time", labels);
let total_collation_histogram =
HistogramGuard::begin_with_labels("tycho_do_collate_total_time", labels);

let prepare_histogram =
HistogramGuard::begin_with_labels("tycho_do_collate_prepare_time", labels);
Expand Down Expand Up @@ -75,8 +76,10 @@ impl CollatorStdImpl {
block_limits
);

// TODO: get from anchor
let created_by = HashBytes::default();
let created_by = self
.last_imported_anchor_author
.map(|a| HashBytes(a.0))
.unwrap_or_default();
let mut collation_data_builder = BlockCollationDataBuilder::new(
block_id_short,
rand_seed,
Expand Down Expand Up @@ -626,7 +629,7 @@ impl CollatorStdImpl {
collation_data.total_execute_msgs_time_mc = execute_msgs_total_elapsed.as_micros();
self.update_stats(&collation_data);

let total_elapsed = histogram.finish();
let total_elapsed = total_collation_histogram.finish();

// time elapsed from prev block
let elapsed_from_prev_block = self.timer.elapsed();
Expand Down
4 changes: 4 additions & 0 deletions collator/src/collator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use everscale_types::models::*;
use everscale_types::prelude::HashBytes;
use futures_util::future::{BoxFuture, Future};
use tycho_block_util::state::{MinRefMcStateTracker, ShardStateStuff};
use tycho_network::PeerId;
use tycho_util::metrics::HistogramGuardWithLabels;
use tycho_util::FastHashMap;

Expand Down Expand Up @@ -180,6 +181,7 @@ pub struct CollatorStdImpl {

last_imported_anchor_id: Option<MempoolAnchorId>,
last_imported_anchor_chain_time: Option<u64>,
last_imported_anchor_author: Option<PeerId>,

/// TRUE - when exist imported anchors in cache,
/// when they have externals for current shard of collator,
Expand Down Expand Up @@ -237,6 +239,7 @@ impl CollatorStdImpl {
anchors_cache: VecDeque::new(),
last_imported_anchor_id: None,
last_imported_anchor_chain_time: None,
last_imported_anchor_author: None,

has_pending_externals: false,

Expand Down Expand Up @@ -521,6 +524,7 @@ impl CollatorStdImpl {

self.last_imported_anchor_id = Some(next_anchor.id());
self.last_imported_anchor_chain_time = Some(next_anchor.chain_time());
self.last_imported_anchor_author = Some(next_anchor.author());
self.anchors_cache
.push_back((next_anchor.id(), CachedMempoolAnchor {
anchor: next_anchor.clone(),
Expand Down
1 change: 1 addition & 0 deletions collator/src/mempool/mempool_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ pub async fn handle_anchors(
anchor_id,
anchor.body().time.as_u64(),
messages,
anchor.body().location.author,
));

adapter.add_anchor(anchor);
Expand Down
15 changes: 13 additions & 2 deletions collator/src/mempool/mempool_adapter_ext_from_files_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use everscale_types::models::{MsgInfo, OwnedMessage};
use parking_lot::RwLock;
use rand::Rng;
use tycho_block_util::state::ShardStateStuff;
use tycho_network::PeerId;

use super::mempool_adapter_stub::{stub_get_anchor_by_id, stub_get_next_anchor};
use super::types::{ExternalMessage, MempoolAnchor, MempoolAnchorId};
Expand Down Expand Up @@ -151,10 +152,20 @@ pub fn create_anchor_with_externals_from_file(
externals.push(Arc::new(msg));
}

Arc::new(MempoolAnchor::new(anchor_id, timestamp, externals))
Arc::new(MempoolAnchor::new(
anchor_id,
timestamp,
externals,
PeerId(Default::default()),
))
}

pub fn create_empty_anchor(anchor_id: MempoolAnchorId, last_chain_time: u64) -> Arc<MempoolAnchor> {
let next_chain_time = last_chain_time + 600;
Arc::new(MempoolAnchor::new(anchor_id, next_chain_time, vec![]))
Arc::new(MempoolAnchor::new(
anchor_id,
next_chain_time,
vec![],
PeerId(Default::default()),
))
}
8 changes: 7 additions & 1 deletion collator/src/mempool/mempool_adapter_stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use everscale_types::models::{ExtInMsgInfo, IntAddr, StdAddr};
use parking_lot::RwLock;
use rand::Rng;
use tycho_block_util::state::ShardStateStuff;
use tycho_network::PeerId;

use super::types::{ExternalMessage, MempoolAnchor, MempoolAnchorId};
use crate::mempool::mempool_adapter::{MempoolAdapter, MempoolEventListener};
Expand Down Expand Up @@ -221,5 +222,10 @@ pub fn _stub_create_random_anchor_with_stub_externals(
externals.push(Arc::new(msg));
}

Arc::new(MempoolAnchor::new(anchor_id, chain_time, externals))
Arc::new(MempoolAnchor::new(
anchor_id,
chain_time,
externals,
PeerId(Default::default()),
))
}
13 changes: 12 additions & 1 deletion collator/src/mempool/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use everscale_types::models::{ExtInMsgInfo, ShardIdent};
use everscale_types::prelude::{Cell, HashBytes};
use tycho_network::PeerId;

use crate::types::ShardIdentExt;

Expand Down Expand Up @@ -39,16 +40,23 @@ impl ExternalMessage {
#[derive(Debug)]
pub struct MempoolAnchor {
id: MempoolAnchorId,
author: PeerId,
chain_time: u64,
externals: Vec<Arc<ExternalMessage>>,
}

impl MempoolAnchor {
pub fn new(id: MempoolAnchorId, chain_time: u64, externals: Vec<Arc<ExternalMessage>>) -> Self {
pub fn new(
id: MempoolAnchorId,
chain_time: u64,
externals: Vec<Arc<ExternalMessage>>,
author: PeerId,
) -> Self {
Self {
id,
chain_time,
externals,
author,
}
}

Expand All @@ -63,6 +71,9 @@ impl MempoolAnchor {
pub fn externals_count(&self) -> usize {
self.externals.len()
}
pub fn author(&self) -> PeerId {
self.author
}

pub fn externals_count_for(&self, shard_id: &ShardIdent) -> usize {
self.externals
Expand Down

0 comments on commit 3a11911

Please sign in to comment.