Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cli/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ impl Node {
self.slasher_config,
&mc_state,
)
.await
.context("failed to create slasher")?;

let validator = ValidatorStdImpl::new(
Expand Down Expand Up @@ -280,6 +281,7 @@ impl Node {
CollatorStdImplFactory {
wu_tuner_event_sender: Some(wu_tuner.event_sender.clone()),
},
slasher.validator_events_listener(),
self.mempool_config_override.clone(),
);
let collator_subcriber = CollatorStateSubscriber {
Expand Down
1 change: 1 addition & 0 deletions collator/src/collator/anchors_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ mod tests {
chain_time,
author: PeerId([0; 32]),
externals: Default::default(),
stats: None,
})
}

Expand Down
33 changes: 33 additions & 0 deletions collator/src/collator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub(super) mod tests;

#[cfg(test)]
pub(crate) use messages_reader::tests::{TestInternalMessage, TestMessageFactory};
use tycho_slasher_traits::ValidatorEventsListener;

// FACTORY

Expand All @@ -82,6 +83,7 @@ pub struct CollatorContext {
pub config: Arc<CollatorConfig>,
pub collation_session: Arc<CollationSessionInfo>,
pub zerostate_id: ZerostateId,
pub stats_recorder: Arc<dyn ValidatorEventsListener>,
pub shard_id: ShardIdent,
pub prev_blocks_ids: Vec<BlockId>,

Expand Down Expand Up @@ -165,6 +167,7 @@ pub struct CollatorStdImpl {
collation_session: Arc<CollationSessionInfo>,
zerostate_id: ZerostateId,

stats_recorder: Arc<dyn ValidatorEventsListener>,
mq_adapter: Arc<dyn MessageQueueAdapter<EnqueuedMessage>>,
mpool_adapter: Arc<dyn MempoolAdapter>,
state_node_adapter: Arc<dyn StateNodeAdapter>,
Expand Down Expand Up @@ -263,6 +266,7 @@ impl CollatorStdImpl {
config,
collation_session,
zerostate_id,
stats_recorder,
shard_id,
prev_blocks_ids,
mempool_config_override,
Expand All @@ -285,6 +289,7 @@ impl CollatorStdImpl {
config,
collation_session,
zerostate_id,
stats_recorder,
mq_adapter,
mpool_adapter,
state_node_adapter,
Expand Down Expand Up @@ -1564,6 +1569,20 @@ impl CollatorStdImpl {
)
.record(elapsed_from_prev_anchor);

if let Some(stats) = &next_anchor.stats {
let (catchain_seqno, vset_switch_round) =
self.collation_session.get_validation_session_id();

self.stats_recorder.on_anchor_import(
tycho_slasher_traits::ValidationSessionId {
catchain_seqno,
vset_switch_round,
},
&self.next_block_info,
stats.clone(),
);
}

working_state.wu_used_from_last_anchor = 0;

// time between anchors
Expand Down Expand Up @@ -1770,6 +1789,20 @@ impl CollatorStdImpl {
"imported next anchor, will notify collation manager",
);

if let Some(stats) = &next_anchor.stats {
let (catchain_seqno, vset_switch_round) =
self.collation_session.get_validation_session_id();

self.stats_recorder.on_anchor_import(
tycho_slasher_traits::ValidationSessionId {
catchain_seqno,
vset_switch_round,
},
&self.next_block_info,
stats.clone(),
);
}

// this may start master block collation or cause next anchor import
let res = CollatorResult::skipped(
working_state.mc_data.block_id,
Expand Down
1 change: 1 addition & 0 deletions collator/src/collator/tests/messages_reader_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,7 @@ where
author: PeerId(Default::default()),
chain_time: anchor_ct,
externals,
stats: None,
});

self.mempool.insert(anchor_id, anchor.clone());
Expand Down
4 changes: 4 additions & 0 deletions collator/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use parking_lot::{Mutex, RwLock};
use tycho_block_util::state::ShardStateStuff;
use tycho_core::global_config::MempoolGlobalConfig;
use tycho_crypto::ed25519::KeyPair;
use tycho_slasher_traits::ValidatorEventsListener;
use tycho_types::models::{BlockId, BlockIdShort, CollationConfig, ProcessedUptoInfo, ShardIdent};
use tycho_util::futures::JoinTask;
use tycho_util::metrics::HistogramGuard;
Expand Down Expand Up @@ -77,6 +78,7 @@ where

validator: Arc<V>,
cancel_validation_runner: Mutex<CancelValidationRunnerState>,
stats_recorder: Arc<dyn ValidatorEventsListener>,

active_collation_sessions: RwLock<FastHashMap<ShardIdent, Arc<CollationSessionInfo>>>,
active_collators: FastDashMap<ShardIdent, ActiveCollator<Box<CF::Collator>>>,
Expand Down Expand Up @@ -136,6 +138,7 @@ where
mpool_adapter_factory: MPF,
validator: V,
collator_factory: CF,
stats_recorder: Arc<dyn ValidatorEventsListener>,
mempool_config_override: Option<MempoolGlobalConfig>,
) -> Arc<CollationManager<CF, V>>
where
Expand Down Expand Up @@ -170,6 +173,7 @@ where

validator,
cancel_validation_runner: Default::default(),
stats_recorder,

active_collation_sessions: Default::default(),
active_collators: Default::default(),
Expand Down
28 changes: 17 additions & 11 deletions collator/src/manager/state_update_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,20 @@ where
);

let next_block_id_short = calc_next_block_id_short(&prev_blocks_ids);
let add_validator_session = || {
// need to add validation session only for masterchain blocks,
// shard blocks are not being validated
if shard_id.is_masterchain() {
self.validator.add_session(AddSession {
shard_ident: shard_id,
session_id: new_session_info.get_validation_session_id(),
start_block_seqno: next_block_id_short.seqno,
vset_hash: raw_validators_set.repr_hash(),
validators: &new_session_info.collators().validators,
})?;
}
anyhow::Ok(())
};

match self.active_collators.entry(shard_id) {
DashMapEntry::Occupied(_) => {
Expand All @@ -344,6 +358,7 @@ where
"Active collator exists for collation session {:?}. Will resume it",
new_session_info.id(),
);
add_validator_session()?;
sessions_to_keep.push((shard_id, new_session_info.clone(), prev_blocks_ids));
}
DashMapEntry::Vacant(entry) => {
Expand All @@ -364,6 +379,7 @@ where
config: self.config.clone(),
collation_session: new_session_info.clone(),
zerostate_id: *self.state_node_adapter.zerostate_id(),
stats_recorder: self.stats_recorder.clone(),
shard_id,
prev_blocks_ids: prev_blocks_ids.clone(),
mempool_config_override: self.mempool_config_override.clone(),
Expand All @@ -382,6 +398,7 @@ where
}
Ok(collator) => {
let collator = Box::new(collator);
add_validator_session()?;

// init collator
let collator =
Expand Down Expand Up @@ -409,17 +426,6 @@ where
}
}

// need to add validation session only for masterchain blocks, shard blocks are not being validated
if shard_id.is_masterchain() {
self.validator.add_session(AddSession {
shard_ident: shard_id,
session_id: new_session_info.get_validation_session_id(),
start_block_seqno: next_block_id_short.seqno,
vset_hash: raw_validators_set.repr_hash(),
validators: &new_session_info.collators().validators,
})?;
}

self.active_collation_sessions
.write()
.insert(shard_id, new_session_info);
Expand Down
4 changes: 4 additions & 0 deletions collator/src/manager/tests/manager_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use tycho_block_util::state::{MinRefMcStateTracker, ShardStateStuff};
use tycho_core::global_config::ZerostateId;
use tycho_core::storage::{BlockHandle, LoadStateHint, NewBlockMeta, StoreStateHint};
use tycho_crypto::ed25519::{KeyPair, SecretKey};
use tycho_slasher_traits::NoopValidatorEventsRecorder;
use tycho_types::boc::Boc;
use tycho_types::cell::{Cell, CellBuilder, CellFamily, HashBytes, Lazy};
use tycho_types::merkle::MerkleUpdate;
Expand Down Expand Up @@ -1914,6 +1915,7 @@ async fn test_should_not_sync_without_applied_range_after_known_sync() {
},
validator: Arc::new(NoopValidator),
cancel_validation_runner: Default::default(),
stats_recorder: Arc::new(NoopValidatorEventsRecorder),
active_collation_sessions: Default::default(),
active_collators: Default::default(),
blocks_cache: BlocksCache::new(&Default::default()),
Expand Down Expand Up @@ -3764,6 +3766,7 @@ async fn test_skipped_validation_does_not_commit_collated_master() {
},
validator: Arc::new(NoopValidator),
cancel_validation_runner: Default::default(),
stats_recorder: Arc::new(NoopValidatorEventsRecorder),
active_collation_sessions: Default::default(),
active_collators: Default::default(),
blocks_cache: test_adapter.blocks_cache.clone(),
Expand Down Expand Up @@ -3977,6 +3980,7 @@ async fn test_cache_gc_on_skipped_sync() {
CollatorStdImplFactory {
wu_tuner_event_sender: None,
},
Arc::new(NoopValidatorEventsRecorder),
None,
);
Arc::get_mut(&mut manager)
Expand Down
1 change: 1 addition & 0 deletions collator/src/mempool/impls/common/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ mod tests {
author: PeerId(Default::default()),
chain_time: id as u64,
externals: vec![],
stats: None,
})
}

Expand Down
1 change: 1 addition & 0 deletions collator/src/mempool/impls/common/shuttle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl Shuttle {
chain_time,
author: *committed.anchor.author(),
externals: unique_messages,
stats: committed.stats.clone(),
});

metrics::counter!("tycho_mempool_msgs_unique_count")
Expand Down
1 change: 1 addition & 0 deletions collator/src/mempool/impls/dump_anchors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ impl TryFrom<DumpedAnchor> for MempoolAnchor {
author: value.author,
chain_time: value.chain_time,
externals,
stats: None,
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl SingleNodeAnchorHandler {
chain_time,
author: self.peer_id,
externals: unique_messages,
stats: None,
}))
.expect("push new anchor");

Expand Down
3 changes: 3 additions & 0 deletions collator/src/mempool/impls/stub_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ pub(crate) fn make_empty_anchor(
author: PeerId(Default::default()),
chain_time,
externals: vec![],
stats: None,
})
}

Expand All @@ -467,6 +468,7 @@ pub(crate) fn make_stub_anchor(id: MempoolAnchorId, prev_id: MempoolAnchorId) ->
author: PeerId(Default::default()),
chain_time,
externals,
stats: None,
}
}

Expand Down Expand Up @@ -530,6 +532,7 @@ pub(crate) fn make_anchor_from_file(
author: PeerId(Default::default()),
chain_time,
externals,
stats: None,
}))
}

Expand Down
2 changes: 2 additions & 0 deletions collator/src/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use anyhow::Result;
use async_trait::async_trait;
use bytes::Bytes;
use tycho_network::PeerId;
use tycho_slasher_traits::AnchorStats;
use tycho_types::models::*;
use tycho_types::prelude::*;

Expand Down Expand Up @@ -126,6 +127,7 @@ pub struct MempoolAnchor {
pub author: PeerId,
pub chain_time: u64,
pub externals: Vec<Arc<ExternalMessage>>,
pub stats: Option<AnchorStats>,
}

impl MempoolAnchor {
Expand Down
4 changes: 2 additions & 2 deletions collator/src/validator/impls/std_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ impl ValidatorStdImpl {
net_context: ValidatorNetworkContext,
keypair: Arc<KeyPair>,
config: ValidatorStdImplConfig,
recorder: Arc<dyn ValidatorEventsListener>,
stats_recorder: Arc<dyn ValidatorEventsListener>,
) -> Self {
Self {
inner: Arc::new(Inner {
net_context,
keypair,
sessions: Default::default(),
config,
events: ValidatorEvents::new(recorder),
events: ValidatorEvents::new(stats_recorder),
}),
}
}
Expand Down
4 changes: 4 additions & 0 deletions collator/tests/collation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use tycho_core::global_config::ZerostateId;
use tycho_core::node::NodeKeys;
use tycho_core::storage::CoreStorage;
use tycho_crypto::ed25519;
use tycho_slasher_traits::NoopValidatorEventsRecorder;
use tycho_storage::StorageContext;
use tycho_types::models::{BlockId, BlockIdShort, ShardIdent};

Expand Down Expand Up @@ -219,6 +220,8 @@ fn start_collation_manager(
ctx: &DumpCollationContext,
dumped_anchors: Vec<DumpedAnchor>,
) -> RunningCollationManager {
let recorder = Arc::new(NoopValidatorEventsRecorder);

CollationManager::create(
ctx.keypair.clone(),
ctx.config.clone(),
Expand All @@ -240,6 +243,7 @@ fn start_collation_manager(
CollatorStdImplFactory {
wu_tuner_event_sender: None,
},
recorder,
None,
)
}
Expand Down
3 changes: 2 additions & 1 deletion consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ weedb = { workspace = true }

# local deps
tycho-network = { workspace = true }
tycho-util = { workspace = true }
tycho-slasher-traits = { workspace = true }
tycho-storage = { workspace = true }
tycho-util = { workspace = true }

[dev-dependencies]
humantime = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions consensus/src/dag/commit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ impl Committer {
proof_key: next.proof.key(),
history: committed,
is_executable,
stats: None, // may be set later
})
}
}
Expand Down
Loading
Loading