Skip to content

Commit 329df04

Browse files
ordianAnk4n
authored andcommitted
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
1 parent 3ff561f commit 329df04

33 files changed

Lines changed: 387 additions & 620 deletions

File tree

Cargo.lock

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cumulus/client/relay-chain-minimal-node/src/collator_overseer.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ use polkadot_node_network_protocol::{
3636
use polkadot_node_subsystem_util::metrics::{prometheus::Registry, Metrics};
3737
use polkadot_overseer::{
3838
BlockInfo, DummySubsystem, Handle, Overseer, OverseerConnector, OverseerHandle, SpawnGlue,
39-
KNOWN_LEAVES_CACHE_SIZE,
39+
UnpinHandle, KNOWN_LEAVES_CACHE_SIZE,
4040
};
4141
use polkadot_primitives::CollatorPair;
4242

4343
use sc_authority_discovery::Service as AuthorityDiscoveryService;
4444
use sc_network::NetworkStateInfo;
4545
use sc_service::TaskManager;
46+
use sc_utils::mpsc::tracing_unbounded;
4647
use sp_runtime::traits::Block as BlockT;
4748

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

225229
loop {
226230
select! {
227231
f = finality.next() => {
228232
match f {
229233
Some(header) => {
234+
let hash = header.hash();
230235
tracing::info!(
231236
target: "minimal-polkadot-node",
232237
"Received finalized block via RPC: #{} ({} -> {})",
233238
header.number,
234239
header.parent_hash,
235-
header.hash()
240+
hash,
236241
);
237-
let block_info = BlockInfo { hash: header.hash(), parent_hash: header.parent_hash, number: header.number };
242+
let unpin_handle = dummy_unpin_handle.clone();
243+
let block_info = BlockInfo { hash, parent_hash: header.parent_hash, number: header.number, unpin_handle };
238244
handle.block_finalized(block_info).await;
239245
}
240246
None => return Err(RelayChainError::GenericError("Relay chain finality stream ended.".to_string())),
@@ -243,14 +249,16 @@ async fn forward_collator_events(
243249
i = imports.next() => {
244250
match i {
245251
Some(header) => {
252+
let hash = header.hash();
246253
tracing::info!(
247254
target: "minimal-polkadot-node",
248255
"Received imported block via RPC: #{} ({} -> {})",
249256
header.number,
250257
header.parent_hash,
251-
header.hash()
258+
hash,
252259
);
253-
let block_info = BlockInfo { hash: header.hash(), parent_hash: header.parent_hash, number: header.number };
260+
let unpin_handle = dummy_unpin_handle.clone();
261+
let block_info = BlockInfo { hash, parent_hash: header.parent_hash, number: header.number, unpin_handle };
254262
handle.block_imported(block_info).await;
255263
}
256264
None => return Err(RelayChainError::GenericError("Relay chain import stream ended.".to_string())),

polkadot/node/core/approval-voting/src/tests.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use self::test_helpers::mock::new_leaf;
1718
use super::*;
1819
use polkadot_node_primitives::{
1920
approval::{
@@ -26,7 +27,7 @@ use polkadot_node_subsystem::{
2627
messages::{
2728
AllMessages, ApprovalVotingMessage, AssignmentCheckResult, AvailabilityRecoveryMessage,
2829
},
29-
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
30+
ActiveLeavesUpdate,
3031
};
3132
use polkadot_node_subsystem_test_helpers as test_helpers;
3233
use polkadot_node_subsystem_util::TimeoutExt;
@@ -777,12 +778,7 @@ async fn import_block(
777778
overseer_send(
778779
overseer,
779780
FromOrchestra::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(
780-
ActivatedLeaf {
781-
hash: *new_head,
782-
number,
783-
status: LeafStatus::Fresh,
784-
span: Arc::new(jaeger::Span::Disabled),
785-
},
781+
new_leaf(*new_head, number),
786782
))),
787783
)
788784
.await;

polkadot/node/core/av-store/src/tests.rs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ use super::*;
1919
use assert_matches::assert_matches;
2020
use futures::{channel::oneshot, executor, future, Future};
2121

22+
use self::test_helpers::mock::new_leaf;
2223
use ::test_helpers::TestCandidateBuilder;
2324
use parking_lot::Mutex;
2425
use polkadot_node_primitives::{AvailableData, BlockData, PoV, Proof};
2526
use polkadot_node_subsystem::{
2627
errors::RuntimeApiError,
27-
jaeger,
2828
messages::{AllMessages, RuntimeApiMessage, RuntimeApiRequest},
29-
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus,
29+
ActiveLeavesUpdate,
3030
};
3131
use polkadot_node_subsystem_test_helpers as test_helpers;
3232
use polkadot_node_subsystem_util::{database::Database, TimeoutExt};
@@ -219,16 +219,11 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
219219
let store = test_store();
220220

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

224224
overseer_signal(
225225
&mut virtual_overseer,
226-
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
227-
hash: new_leaf,
228-
number: 1,
229-
status: LeafStatus::Fresh,
230-
span: Arc::new(jaeger::Span::Disabled),
231-
})),
226+
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(a_leaf, 1))),
232227
)
233228
.await;
234229

@@ -246,7 +241,7 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
246241
relay_parent,
247242
tx,
248243
)) => {
249-
assert_eq!(relay_parent, new_leaf);
244+
assert_eq!(relay_parent, a_leaf);
250245
tx.send(Ok(Some(header))).unwrap();
251246
}
252247
);
@@ -258,7 +253,7 @@ fn runtime_api_error_does_not_stop_the_subsystem() {
258253
relay_parent,
259254
RuntimeApiRequest::CandidateEvents(tx),
260255
)) => {
261-
assert_eq!(relay_parent, new_leaf);
256+
assert_eq!(relay_parent, a_leaf);
262257
#[derive(Debug)]
263258
struct FauxError;
264259
impl std::error::Error for FauxError {}
@@ -741,7 +736,7 @@ fn stored_data_kept_until_finalized() {
741736
available_data,
742737
);
743738

744-
let new_leaf = import_leaf(
739+
let a_leaf = import_leaf(
745740
&mut virtual_overseer,
746741
parent,
747742
block_number,
@@ -764,7 +759,7 @@ fn stored_data_kept_until_finalized() {
764759

765760
overseer_signal(
766761
&mut virtual_overseer,
767-
OverseerSignal::BlockFinalized(new_leaf, block_number),
762+
OverseerSignal::BlockFinalized(a_leaf, block_number),
768763
)
769764
.await;
770765

@@ -849,16 +844,11 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
849844
extrinsics_root: Hash::zero(),
850845
digest: Default::default(),
851846
};
852-
let new_leaf = Hash::repeat_byte(4);
847+
let a_leaf = Hash::repeat_byte(4);
853848

854849
overseer_signal(
855850
&mut virtual_overseer,
856-
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
857-
hash: new_leaf,
858-
number: 4,
859-
status: LeafStatus::Fresh,
860-
span: Arc::new(jaeger::Span::Disabled),
861-
})),
851+
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(a_leaf, 4))),
862852
)
863853
.await;
864854

@@ -868,7 +858,7 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
868858
relay_parent,
869859
tx,
870860
)) => {
871-
assert_eq!(relay_parent, new_leaf);
861+
assert_eq!(relay_parent, a_leaf);
872862
tx.send(Ok(Some(header))).unwrap();
873863
}
874864
);
@@ -886,7 +876,7 @@ fn we_dont_miss_anything_if_import_notifications_are_missed() {
886876
k,
887877
response_channel: tx,
888878
}) => {
889-
assert_eq!(hash, new_leaf);
879+
assert_eq!(hash, a_leaf);
890880
assert_eq!(k, 2);
891881
let _ = tx.send(Ok(vec![
892882
Hash::repeat_byte(3),
@@ -1166,16 +1156,11 @@ async fn import_leaf(
11661156
extrinsics_root: Hash::zero(),
11671157
digest: Default::default(),
11681158
};
1169-
let new_leaf = header.hash();
1159+
let a_leaf = header.hash();
11701160

11711161
overseer_signal(
11721162
virtual_overseer,
1173-
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(ActivatedLeaf {
1174-
hash: new_leaf,
1175-
number: 1,
1176-
status: LeafStatus::Fresh,
1177-
span: Arc::new(jaeger::Span::Disabled),
1178-
})),
1163+
OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(new_leaf(a_leaf, 1))),
11791164
)
11801165
.await;
11811166

@@ -1185,7 +1170,7 @@ async fn import_leaf(
11851170
relay_parent,
11861171
tx,
11871172
)) => {
1188-
assert_eq!(relay_parent, new_leaf);
1173+
assert_eq!(relay_parent, a_leaf);
11891174
tx.send(Ok(Some(header))).unwrap();
11901175
}
11911176
);
@@ -1196,7 +1181,7 @@ async fn import_leaf(
11961181
relay_parent,
11971182
RuntimeApiRequest::CandidateEvents(tx),
11981183
)) => {
1199-
assert_eq!(relay_parent, new_leaf);
1184+
assert_eq!(relay_parent, a_leaf);
12001185
tx.send(Ok(events)).unwrap();
12011186
}
12021187
);
@@ -1212,7 +1197,7 @@ async fn import_leaf(
12121197
}
12131198
);
12141199

1215-
new_leaf
1200+
a_leaf
12161201
}
12171202

12181203
#[test]

polkadot/node/core/backing/src/tests/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use self::test_helpers::mock::new_leaf;
1718
use super::*;
1819
use ::test_helpers::{
1920
dummy_candidate_receipt_bad_sig, dummy_collator, dummy_collator_signature,
@@ -24,12 +25,11 @@ use futures::{future, Future};
2425
use polkadot_node_primitives::{BlockData, InvalidCandidate, SignedFullStatement, Statement};
2526
use polkadot_node_subsystem::{
2627
errors::RuntimeApiError,
27-
jaeger,
2828
messages::{
2929
AllMessages, CollatorProtocolMessage, RuntimeApiMessage, RuntimeApiRequest,
3030
ValidationFailed,
3131
},
32-
ActivatedLeaf, ActiveLeavesUpdate, FromOrchestra, LeafStatus, OverseerSignal, TimeoutExt,
32+
ActiveLeavesUpdate, FromOrchestra, OverseerSignal, TimeoutExt,
3333
};
3434
use polkadot_node_subsystem_test_helpers as test_helpers;
3535
use polkadot_primitives::{
@@ -234,12 +234,7 @@ async fn test_startup(virtual_overseer: &mut VirtualOverseer, test_state: &TestS
234234
// Start work on some new parent.
235235
virtual_overseer
236236
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(ActiveLeavesUpdate::start_work(
237-
ActivatedLeaf {
238-
hash: test_state.relay_parent,
239-
number: 1,
240-
status: LeafStatus::Fresh,
241-
span: Arc::new(jaeger::Span::Disabled),
242-
},
237+
new_leaf(test_state.relay_parent, 1),
243238
))))
244239
.await;
245240

0 commit comments

Comments
 (0)