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

polkadot: pin one block per session #1220

Merged
merged 10 commits into from
Sep 7, 2023
7 changes: 6 additions & 1 deletion Cargo.lock

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

18 changes: 13 additions & 5 deletions cumulus/client/relay-chain-minimal-node/src/collator_overseer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ use polkadot_node_network_protocol::{
use polkadot_node_subsystem_util::metrics::{prometheus::Registry, Metrics};
use polkadot_overseer::{
BlockInfo, DummySubsystem, Handle, Overseer, OverseerConnector, OverseerHandle, SpawnGlue,
KNOWN_LEAVES_CACHE_SIZE,
UnpinHandle, KNOWN_LEAVES_CACHE_SIZE,
};
use polkadot_primitives::CollatorPair;

use sc_authority_discovery::Service as AuthorityDiscoveryService;
use sc_network::NetworkStateInfo;
use sc_service::TaskManager;
use sc_utils::mpsc::tracing_unbounded;
use sp_runtime::traits::Block as BlockT;

use cumulus_primitives_core::relay_chain::{Block, Hash as PHash};
Expand Down Expand Up @@ -221,20 +222,25 @@ async fn forward_collator_events(
) -> Result<(), RelayChainError> {
let mut finality = client.finality_notification_stream().await?.fuse();
let mut imports = client.import_notification_stream().await?.fuse();
// Collators do no need to pin any specific blocks
let (dummy_sink, _) = tracing_unbounded("does-not-matter", 42);
let dummy_unpin_handle = UnpinHandle::new(Default::default(), dummy_sink);

loop {
select! {
f = finality.next() => {
match f {
Some(header) => {
let hash = header.hash();
tracing::info!(
target: "minimal-polkadot-node",
"Received finalized block via RPC: #{} ({} -> {})",
header.number,
header.parent_hash,
header.hash()
hash,
);
let block_info = BlockInfo { hash: header.hash(), parent_hash: header.parent_hash, number: header.number };
let unpin_handle = dummy_unpin_handle.clone();
let block_info = BlockInfo { hash, parent_hash: header.parent_hash, number: header.number, unpin_handle };
handle.block_finalized(block_info).await;
}
None => return Err(RelayChainError::GenericError("Relay chain finality stream ended.".to_string())),
Expand All @@ -243,14 +249,16 @@ async fn forward_collator_events(
i = imports.next() => {
match i {
Some(header) => {
let hash = header.hash();
tracing::info!(
target: "minimal-polkadot-node",
"Received imported block via RPC: #{} ({} -> {})",
header.number,
header.parent_hash,
header.hash()
hash,
);
let block_info = BlockInfo { hash: header.hash(), parent_hash: header.parent_hash, number: header.number };
let unpin_handle = dummy_unpin_handle.clone();
let block_info = BlockInfo { hash, parent_hash: header.parent_hash, number: header.number, unpin_handle };
handle.block_imported(block_info).await;
}
None => return Err(RelayChainError::GenericError("Relay chain import stream ended.".to_string())),
Expand Down
10 changes: 3 additions & 7 deletions polkadot/node/core/approval-voting/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use self::test_helpers::mock::new_leaf;
use super::*;
use polkadot_node_primitives::{
approval::{
Expand All @@ -26,7 +27,7 @@ use polkadot_node_subsystem::{
messages::{
AllMessages, ApprovalVotingMessage, AssignmentCheckResult, AvailabilityRecoveryMessage,
},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
ActiveLeavesUpdate,
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_util::TimeoutExt;
Expand Down Expand Up @@ -777,12 +778,7 @@ async fn import_block(
overseer_send(
overseer,
FromOrchestra::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(
ActivatedLeaf {
hash: *new_head,
number,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
},
new_leaf(*new_head, number),
))),
)
.await;
Expand Down
49 changes: 17 additions & 32 deletions polkadot/node/core/av-store/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ use super::*;
use assert_matches::assert_matches;
use futures::{channel::oneshot, executor, future, Future};

use self::test_helpers::mock::new_leaf;
use ::test_helpers::TestCandidateBuilder;
use parking_lot::Mutex;
use polkadot_node_primitives::{AvailableData, BlockData, PoV, Proof};
use polkadot_node_subsystem::{
errors::RuntimeApiError,
jaeger,
messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest},
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
ActiveLeavesUpdate,
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_node_subsystem_util::{database::Database, TimeoutExt};
Expand Down Expand Up @@ -219,16 +219,11 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
let store = test_store();

test_harness(TestState::default(), store, |mut virtual_overseer| async move {
let new_leaf = Hash::repeat_byte(0x01);
let a_leaf = Hash::repeat_byte(0x01);

overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: new_leaf,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(a_leaf, 1))),
)
.await;

Expand All @@ -246,7 +241,7 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
relay_parent,
tx,
)) => {
assert_eq!(relay_parent, new_leaf);
assert_eq!(relay_parent, a_leaf);
tx.send(Ok(Some(header))).unwrap();
}
);
Expand All @@ -258,7 +253,7 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
relay_parent,
RuntimeApiRequest::CandidateEvents(tx),
)) => {
assert_eq!(relay_parent, new_leaf);
assert_eq!(relay_parent, a_leaf);
#[derive(Debug)]
struct FauxError;
impl std::error::Error for FauxError {}
Expand Down Expand Up @@ -741,7 +736,7 @@ fn stored_data_kept_until_finalized() {
available_data,
);

let new_leaf = import_leaf(
let a_leaf = import_leaf(
&mut virtual_overseer,
parent,
block_number,
Expand All @@ -764,7 +759,7 @@ fn stored_data_kept_until_finalized() {

overseer_signal(
&mut virtual_overseer,
OverseerSignal::BlockFinalized(new_leaf, block_number),
OverseerSignal::BlockFinalized(a_leaf, block_number),
)
.await;

Expand Down Expand Up @@ -849,16 +844,11 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
extrinsics_root: Hash::zero(),
digest: Default::default(),
};
let new_leaf = Hash::repeat_byte(4);
let a_leaf = Hash::repeat_byte(4);

overseer_signal(
&mut virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: new_leaf,
number: 4,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(a_leaf, 4))),
)
.await;

Expand All @@ -868,7 +858,7 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
relay_parent,
tx,
)) => {
assert_eq!(relay_parent, new_leaf);
assert_eq!(relay_parent, a_leaf);
tx.send(Ok(Some(header))).unwrap();
}
);
Expand All @@ -886,7 +876,7 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
k,
response_channel: tx,
}) => {
assert_eq!(hash, new_leaf);
assert_eq!(hash, a_leaf);
assert_eq!(k, 2);
let _ = tx.send(Ok(vec![
Hash::repeat_byte(3),
Expand Down Expand Up @@ -1166,16 +1156,11 @@ async fn import_leaf(
extrinsics_root: Hash::zero(),
digest: Default::default(),
};
let new_leaf = header.hash();
let a_leaf = header.hash();

overseer_signal(
virtual_overseer,
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
hash: new_leaf,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
})),
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(a_leaf, 1))),
)
.await;

Expand All @@ -1185,7 +1170,7 @@ async fn import_leaf(
relay_parent,
tx,
)) => {
assert_eq!(relay_parent, new_leaf);
assert_eq!(relay_parent, a_leaf);
tx.send(Ok(Some(header))).unwrap();
}
);
Expand All @@ -1196,7 +1181,7 @@ async fn import_leaf(
relay_parent,
RuntimeApiRequest::CandidateEvents(tx),
)) => {
assert_eq!(relay_parent, new_leaf);
assert_eq!(relay_parent, a_leaf);
tx.send(Ok(events)).unwrap();
}
);
Expand All @@ -1212,7 +1197,7 @@ async fn import_leaf(
}
);

new_leaf
a_leaf
}

#[test]
Expand Down
11 changes: 3 additions & 8 deletions polkadot/node/core/backing/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

use self::test_helpers::mock::new_leaf;
use super::*;
use ::test_helpers::{
dummy_candidate_receipt_bad_sig, dummy_collator, dummy_collator_signature,
Expand All @@ -24,12 +25,11 @@ use futures::{future, Future};
use polkadot_node_primitives::{BlockData, InvalidCandidate, SignedFullStatement, Statement};
use polkadot_node_subsystem::{
errors::RuntimeApiError,
jaeger,
messages::{
AllMessages, CollatorProtocolMessage, RuntimeApiMessage, RuntimeApiRequest,
ValidationFailed,
},
ActivatedLeaf, ActiveLeavesUpdate, FromOrchestra, LeafStatus, OverseerSignal, TimeoutExt,
ActiveLeavesUpdate, FromOrchestra, OverseerSignal, TimeoutExt,
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_primitives::{
Expand Down Expand Up @@ -234,12 +234,7 @@ async fn test_startup(virtual_overseer: &mut VirtualOverseer, test_state: &TestS
// Start work on some new parent.
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(
ActivatedLeaf {
hash: test_state.relay_parent,
number: 1,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
},
new_leaf(test_state.relay_parent, 1),
))))
.await;

Expand Down