Skip to content
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

adder-collator: add velocity measurement and make elastic scaling test more robust #4016

Merged
merged 4 commits into from
Apr 8, 2024
Merged
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
43 changes: 43 additions & 0 deletions polkadot/parachain/test-parachains/adder/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,47 @@ impl State {
}
}

/// Local collator state so we can compute how fast we are advancing
/// per relay parent.
#[derive(Default)]
pub struct LocalCollatorState {
/// First relay block number on which we've built on.
first_relay_parent: Option<u32>,
/// Last relay block number on which we've built on.
last_relay_parent: Option<u32>,
}

impl LocalCollatorState {
fn advance(&mut self, new_relay_parent: u32, best_block: u64) {
match (self.first_relay_parent, self.last_relay_parent) {
(Some(first_relay_parent), Some(last_relay_parent)) => {
// Compute the parachain velocity when relay parent changes vs our last
// recorded relay parent. We do this to only print out the velocity
// once per relay parent.
if new_relay_parent > last_relay_parent {
let building_for = (new_relay_parent - first_relay_parent) as f32;
// Round it up, as we don't expect perfect runs in CI.
let velocity = (best_block as f32 / building_for).ceil() as u32;

log::info!("Parachain velocity: {:}", velocity);
}
},
_ => {},
}

if self.first_relay_parent.is_none() {
self.first_relay_parent = Some(new_relay_parent);
}
self.last_relay_parent = Some(new_relay_parent);
}
}

/// The collator of the adder parachain.
pub struct Collator {
state: Arc<Mutex<State>>,
key: CollatorPair,
seconded_collations: Arc<AtomicU32>,
collator_state: Arc<Mutex<LocalCollatorState>>,
}

impl Collator {
Expand All @@ -116,6 +152,7 @@ impl Collator {
state: Arc::new(Mutex::new(State::genesis())),
key: CollatorPair::generate().0,
seconded_collations: Arc::new(AtomicU32::new(0)),
collator_state: Default::default(),
}
}

Expand Down Expand Up @@ -156,12 +193,18 @@ impl Collator {
use futures::FutureExt as _;

let state = self.state.clone();
let collator_state = self.collator_state.clone();
let seconded_collations = self.seconded_collations.clone();

Box::new(move |relay_parent, validation_data| {
let parent = HeadData::decode(&mut &validation_data.parent_head.0[..])
.expect("Decodes parent head");

collator_state
.lock()
.unwrap()
.advance(validation_data.relay_parent_number, parent.number);

let (block_data, head_data) = state.lock().unwrap().advance(parent);

log::info!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ elastic-validator-4: reports node_roles is 4
elastic-validator-0: js-script ./assign-core.js with "2000,0" return is 0 within 600 seconds
elastic-validator-0: js-script ./assign-core.js with "2000,1" return is 0 within 600 seconds

# Wait for 10 relay chain blocks
elastic-validator-0: reports substrate_block_height{status="best"} is at least 20 within 120 seconds
# Wait for 20 relay chain blocks
elastic-validator-0: reports substrate_block_height{status="best"} is at least 20 within 600 seconds

# Parachain should progress with 3 blocks per relay chain block, so it's reasonable to expect state to be
# at least 50, assuming some tolerance
some-parachain: log line contains "BlockData { state: 50, add: 2 }" within 10 seconds
some-parachain-1: count of log lines containing "BlockData { state: 24, add: 2 }" is 0 within 10 seconds
# Non elastic parachain should progress normally
some-parachain-1: count of log lines containing "Parachain velocity: 1" is at least 9 within 20 seconds
# Sanity
some-parachain-1: count of log lines containing "Parachain velocity: 2" is 0 within 20 seconds

# Parachain should progress 3 blocks per relay chain block ideally, however this measurement does
# `ceil()` on the actual velocity to account for CI overload.
some-parachain: count of log lines containing "Parachain velocity: 3" is at least 9 within 20 seconds

Loading