mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 08:41:02 +00:00
adder-collator: add velocity measurement and make elastic scaling test more robust (#4016)
Improves `adder-collator` to also compute the parachain velocity. The velocity is defined as number of parachain blocks progressing per relay chain block. In this test we're asserting that the elastic parachain always progresses by 3 blocks per RCB, while the non-elastic parachain progresses normally - 1 block per RCB. --------- Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> Co-authored-by: ordian <write@reusable.software>
This commit is contained in:
@@ -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.
|
/// The collator of the adder parachain.
|
||||||
pub struct Collator {
|
pub struct Collator {
|
||||||
state: Arc<Mutex<State>>,
|
state: Arc<Mutex<State>>,
|
||||||
key: CollatorPair,
|
key: CollatorPair,
|
||||||
seconded_collations: Arc<AtomicU32>,
|
seconded_collations: Arc<AtomicU32>,
|
||||||
|
collator_state: Arc<Mutex<LocalCollatorState>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Collator {
|
impl Collator {
|
||||||
@@ -116,6 +152,7 @@ impl Collator {
|
|||||||
state: Arc::new(Mutex::new(State::genesis())),
|
state: Arc::new(Mutex::new(State::genesis())),
|
||||||
key: CollatorPair::generate().0,
|
key: CollatorPair::generate().0,
|
||||||
seconded_collations: Arc::new(AtomicU32::new(0)),
|
seconded_collations: Arc::new(AtomicU32::new(0)),
|
||||||
|
collator_state: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,12 +193,18 @@ impl Collator {
|
|||||||
use futures::FutureExt as _;
|
use futures::FutureExt as _;
|
||||||
|
|
||||||
let state = self.state.clone();
|
let state = self.state.clone();
|
||||||
|
let collator_state = self.collator_state.clone();
|
||||||
let seconded_collations = self.seconded_collations.clone();
|
let seconded_collations = self.seconded_collations.clone();
|
||||||
|
|
||||||
Box::new(move |relay_parent, validation_data| {
|
Box::new(move |relay_parent, validation_data| {
|
||||||
let parent = HeadData::decode(&mut &validation_data.parent_head.0[..])
|
let parent = HeadData::decode(&mut &validation_data.parent_head.0[..])
|
||||||
.expect("Decodes parent head");
|
.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);
|
let (block_data, head_data) = state.lock().unwrap().advance(parent);
|
||||||
|
|
||||||
log::info!(
|
log::info!(
|
||||||
|
|||||||
@@ -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,0" return is 0 within 600 seconds
|
||||||
elastic-validator-0: js-script ./assign-core.js with "2000,1" 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
|
# Wait for 20 relay chain blocks
|
||||||
elastic-validator-0: reports substrate_block_height{status="best"} is at least 20 within 120 seconds
|
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
|
# Non elastic parachain should progress normally
|
||||||
# at least 50, assuming some tolerance
|
some-parachain-1: count of log lines containing "Parachain velocity: 1" is at least 9 within 20 seconds
|
||||||
some-parachain: log line contains "BlockData { state: 50, add: 2 }" within 10 seconds
|
# Sanity
|
||||||
some-parachain-1: count of log lines containing "BlockData { state: 24, add: 2 }" is 0 within 10 seconds
|
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user