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::fresh_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),
},
fresh_leaf(*new_head, number),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at the side: We found this fresh/stale mechanism to be redundant. We should remove it at some point.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed it to new_leaf to account for this issue being worked on. Also with this helper function, we won't have to modify tons of files to implement this issue.

))),
)
.await;
Expand Down
25 changes: 5 additions & 20 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::fresh_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 @@ -223,12 +223,7 @@ fn runtime_api_error_does_not_stop_the_subsystem() {

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(fresh_leaf(new_leaf, 1))),
)
.await;

Expand Down Expand Up @@ -853,12 +848,7 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {

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(fresh_leaf(new_leaf, 4))),
)
.await;

Expand Down Expand Up @@ -1170,12 +1160,7 @@ async fn import_leaf(

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(fresh_leaf(new_leaf, 1))),
)
.await;

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::fresh_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),
},
fresh_leaf(test_state.relay_parent, 1),
))))
.await;

Expand Down
72 changes: 11 additions & 61 deletions polkadot/node/core/backing/src/tests/prospective_parachains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use polkadot_node_subsystem::{
messages::{ChainApiMessage, FragmentTreeMembership},
TimeoutExt,
ActivatedLeaf, TimeoutExt,
};
use polkadot_primitives::{vstaging as vstaging_primitives, BlockNumber, Header, OccupiedCore};

Expand Down Expand Up @@ -327,25 +327,15 @@ fn seconding_sanity_check_allowed() {
// `a` is grandparent of `b`.
let leaf_a_hash = Hash::from_low_u64_be(130);
let leaf_a_parent = get_parent_hash(leaf_a_hash);
let activated = ActivatedLeaf {
hash: leaf_a_hash,
number: LEAF_A_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = fresh_leaf(leaf_a_hash, LEAF_A_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_A_BLOCK_NUMBER - LEAF_A_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };

const LEAF_B_BLOCK_NUMBER: BlockNumber = LEAF_A_BLOCK_NUMBER + 2;
const LEAF_B_ANCESTRY_LEN: BlockNumber = 4;

let leaf_b_hash = Hash::from_low_u64_be(128);
let activated = ActivatedLeaf {
hash: leaf_b_hash,
number: LEAF_B_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = fresh_leaf(leaf_b_hash, LEAF_B_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_B_BLOCK_NUMBER - LEAF_B_ANCESTRY_LEN)];
let test_leaf_b = TestLeaf { activated, min_relay_parents };

Expand Down Expand Up @@ -484,24 +474,14 @@ fn seconding_sanity_check_disallowed() {
// `a` is grandparent of `b`.
let leaf_a_hash = Hash::from_low_u64_be(130);
let leaf_a_parent = get_parent_hash(leaf_a_hash);
let activated = ActivatedLeaf {
hash: leaf_a_hash,
number: LEAF_A_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = fresh_leaf(leaf_a_hash, LEAF_A_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_A_BLOCK_NUMBER - LEAF_A_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };

const LEAF_B_BLOCK_NUMBER: BlockNumber = LEAF_A_BLOCK_NUMBER + 2;
const LEAF_B_ANCESTRY_LEN: BlockNumber = 4;

let activated = ActivatedLeaf {
hash: leaf_b_hash,
number: LEAF_B_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = fresh_leaf(leaf_b_hash, LEAF_B_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_B_BLOCK_NUMBER - LEAF_B_ANCESTRY_LEN)];
let test_leaf_b = TestLeaf { activated, min_relay_parents };

Expand Down Expand Up @@ -703,12 +683,7 @@ fn prospective_parachains_reject_candidate() {

let leaf_a_hash = Hash::from_low_u64_be(130);
let leaf_a_parent = get_parent_hash(leaf_a_hash);
let activated = ActivatedLeaf {
hash: leaf_a_hash,
number: LEAF_A_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = fresh_leaf(leaf_a_hash, LEAF_A_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_A_BLOCK_NUMBER - LEAF_A_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };

Expand Down Expand Up @@ -886,12 +861,7 @@ fn second_multiple_candidates_per_relay_parent() {
let leaf_hash = Hash::from_low_u64_be(130);
let leaf_parent = get_parent_hash(leaf_hash);
let leaf_grandparent = get_parent_hash(leaf_parent);
let activated = ActivatedLeaf {
hash: leaf_hash,
number: LEAF_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = fresh_leaf(leaf_hash, LEAF_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_BLOCK_NUMBER - LEAF_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };

Expand Down Expand Up @@ -1027,12 +997,7 @@ fn backing_works() {

let leaf_hash = Hash::from_low_u64_be(130);
let leaf_parent = get_parent_hash(leaf_hash);
let activated = ActivatedLeaf {
hash: leaf_hash,
number: LEAF_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = fresh_leaf(leaf_hash, LEAF_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_BLOCK_NUMBER - LEAF_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };

Expand Down Expand Up @@ -1193,12 +1158,7 @@ fn concurrent_dependent_candidates() {
let leaf_hash = Hash::from_low_u64_be(130);
let leaf_parent = get_parent_hash(leaf_hash);
let leaf_grandparent = get_parent_hash(leaf_parent);
let activated = ActivatedLeaf {
hash: leaf_hash,
number: LEAF_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = fresh_leaf(leaf_hash, LEAF_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_BLOCK_NUMBER - LEAF_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };

Expand Down Expand Up @@ -1425,12 +1385,7 @@ fn seconding_sanity_check_occupy_same_depth() {
let leaf_hash = Hash::from_low_u64_be(130);
let leaf_parent = get_parent_hash(leaf_hash);

let activated = ActivatedLeaf {
hash: leaf_hash,
number: LEAF_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = fresh_leaf(leaf_hash, LEAF_BLOCK_NUMBER);

let min_block_number = LEAF_BLOCK_NUMBER - LEAF_ANCESTRY_LEN;
let min_relay_parents = vec![(para_id_a, min_block_number), (para_id_b, min_block_number)];
Expand Down Expand Up @@ -1584,12 +1539,7 @@ fn occupied_core_assignment() {

let leaf_a_hash = Hash::from_low_u64_be(130);
let leaf_a_parent = get_parent_hash(leaf_a_hash);
let activated = ActivatedLeaf {
hash: leaf_a_hash,
number: LEAF_A_BLOCK_NUMBER,
status: LeafStatus::Fresh,
span: Arc::new(jaeger::Span::Disabled),
};
let activated = fresh_leaf(leaf_a_hash, LEAF_A_BLOCK_NUMBER);
let min_relay_parents = vec![(para_id, LEAF_A_BLOCK_NUMBER - LEAF_A_ANCESTRY_LEN)];
let test_leaf_a = TestLeaf { activated, min_relay_parents };

Expand Down