polkadot: pin one block per session (#1220)

* polkadot: propagate UnpinHandle to ActiveLeafUpdate

Also extract the leaf creation for tests
into a common function.

* dispute-coordinator: try pinned blocks for slashin

* apparently 1.72 is smarter than 1.70

* address nits

* rename fresh_leaf to new_leaf
This commit is contained in:
ordian
2023-09-07 12:24:40 +02:00
committed by GitHub
parent 1346143194
commit 15503883e2
33 changed files with 387 additions and 620 deletions
@@ -435,42 +435,6 @@ impl Future for Yield {
#[cfg(test)]
mod tests {
use super::*;
use futures::executor::block_on;
use polkadot_node_subsystem::messages::CollatorProtocolMessage;
use polkadot_overseer::{dummy::dummy_overseer_builder, Handle, HeadSupportsParachains};
use polkadot_primitives::Hash;
use sp_core::traits::SpawnNamed;
struct AlwaysSupportsParachains;
#[async_trait::async_trait]
impl HeadSupportsParachains for AlwaysSupportsParachains {
async fn head_supports_parachains(&self, _head: &Hash) -> bool {
true
}
}
#[test]
fn forward_subsystem_works() {
let spawner = sp_core::testing::TaskExecutor::new();
let (tx, rx) = mpsc::channel(2);
let (overseer, handle) =
dummy_overseer_builder(spawner.clone(), AlwaysSupportsParachains, None)
.unwrap()
.replace_collator_protocol(|_| ForwardSubsystem(tx))
.build()
.unwrap();
let mut handle = Handle::new(handle);
spawner.spawn("overseer", None, overseer.run().then(|_| async { () }).boxed());
block_on(handle.send_msg_anon(CollatorProtocolMessage::CollateOn(Default::default())));
assert!(matches!(
block_on(rx.into_future()).0.unwrap(),
CollatorProtocolMessage::CollateOn(_)
));
}
#[test]
fn macro_arbitrary_order() {
@@ -16,12 +16,15 @@
use std::sync::Arc;
use polkadot_node_subsystem::{jaeger, ActivatedLeaf, LeafStatus};
use sc_client_api::UnpinHandle;
use sc_keystore::LocalKeystore;
use sc_utils::mpsc::tracing_unbounded;
use sp_application_crypto::AppCrypto;
use sp_keyring::Sr25519Keyring;
use sp_keystore::{Keystore, KeystorePtr};
use polkadot_primitives::{AuthorityDiscoveryId, ValidatorId};
use polkadot_primitives::{AuthorityDiscoveryId, Block, BlockNumber, Hash, ValidatorId};
/// Get mock keystore with `Ferdie` key.
pub fn make_ferdie_keystore() -> KeystorePtr {
@@ -40,3 +43,20 @@ pub fn make_ferdie_keystore() -> KeystorePtr {
.expect("Insert key into keystore");
keystore
}
/// Create a meaningless unpin handle for a block.
pub fn dummy_unpin_handle(block: Hash) -> UnpinHandle<Block> {
let (dummy_sink, _) = tracing_unbounded("Expect Chaos", 69);
UnpinHandle::new(block, dummy_sink)
}
/// Create a new leaf with the given hash and number.
pub fn new_leaf(hash: Hash, number: BlockNumber) -> ActivatedLeaf {
ActivatedLeaf {
hash,
number,
status: LeafStatus::Fresh,
unpin_handle: dummy_unpin_handle(hash),
span: Arc::new(jaeger::Span::Disabled),
}
}