polkadot_subsystem_bench/mock/
availability_recovery.rs1use std::sync::Arc;
20
21use futures::FutureExt;
22use polkadot_node_primitives::{AvailableData, BlockData, PoV};
23use polkadot_node_subsystem::{
24 messages::AvailabilityRecoveryMessage, overseer, SpawnedSubsystem, SubsystemError,
25};
26use polkadot_node_subsystem_types::OverseerSignal;
27use polkadot_primitives::{Hash, HeadData, PersistedValidationData};
28
29const LOG_TARGET: &str = "subsystem-bench::availability-recovery-mock";
30
31pub struct MockAvailabilityRecovery {}
32
33impl MockAvailabilityRecovery {
34 pub fn new() -> Self {
35 Self {}
36 }
37}
38
39#[overseer::subsystem(AvailabilityRecovery, error=SubsystemError, prefix=self::overseer)]
40impl<Context> MockAvailabilityRecovery {
41 fn start(self, ctx: Context) -> SpawnedSubsystem {
42 let future = self.run(ctx).map(|_| Ok(())).boxed();
43
44 SpawnedSubsystem { name: "test-environment", future }
45 }
46}
47
48#[overseer::contextbounds(AvailabilityRecovery, prefix = self::overseer)]
49impl MockAvailabilityRecovery {
50 async fn run<Context>(self, mut ctx: Context) {
51 loop {
52 let msg = ctx.recv().await.expect("Overseer never fails us");
53 match msg {
54 orchestra::FromOrchestra::Signal(signal) =>
55 if signal == OverseerSignal::Conclude {
56 return
57 },
58 orchestra::FromOrchestra::Communication { msg } => match msg {
59 AvailabilityRecoveryMessage::RecoverAvailableData(receipt, _, _, _, tx) => {
60 gum::debug!(target: LOG_TARGET, "RecoverAvailableData for candidate {:?}", receipt.hash());
61 let available_data = AvailableData {
62 pov: Arc::new(PoV { block_data: BlockData(Vec::new()) }),
63 validation_data: PersistedValidationData {
64 parent_head: HeadData(Vec::new()),
65 relay_parent_number: 0,
66 relay_parent_storage_root: Hash::default(),
67 max_pov_size: 2,
68 },
69 };
70 tx.send(Ok(available_data)).unwrap();
71 },
72 },
73 }
74 }
75 }
76}