Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into rb-update-payee-wei…
Browse files Browse the repository at this point in the history
…ghts
  • Loading branch information
parity-processbot committed Aug 17, 2023
2 parents ac5fbce + 56d45fe commit ccc0a75
Show file tree
Hide file tree
Showing 64 changed files with 4,403 additions and 2,089 deletions.
372 changes: 186 additions & 186 deletions Cargo.lock

Large diffs are not rendered by default.

42 changes: 6 additions & 36 deletions node/core/backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use polkadot_node_subsystem_util::{
request_validators, Validator,
};
use polkadot_primitives::{
BackedCandidate, CandidateCommitments, CandidateHash, CandidateReceipt, CollatorId,
BackedCandidate, CandidateCommitments, CandidateHash, CandidateReceipt,
CommittedCandidateReceipt, CoreIndex, CoreState, Hash, Id as ParaId, PvfExecTimeoutKind,
SigningContext, ValidatorId, ValidatorIndex, ValidatorSignature, ValidityAttestation,
};
Expand Down Expand Up @@ -354,7 +354,7 @@ async fn handle_active_leaves_update<Context>(
let group_index = group_rotation_info.group_for_core(core_index, n_cores);
if let Some(g) = validator_groups.get(group_index.0 as usize) {
if validator.as_ref().map_or(false, |v| g.contains(&v.index())) {
assignment = Some((scheduled.para_id, scheduled.collator));
assignment = Some(scheduled.para_id);
}
groups.insert(scheduled.para_id, g.clone());
}
Expand All @@ -363,15 +363,15 @@ async fn handle_active_leaves_update<Context>(

let table_context = TableContext { groups, validators, validator };

let (assignment, required_collator) = match assignment {
let assignment = match assignment {
None => {
assignments_span.add_string_tag("assigned", "false");
(None, None)
None
},
Some((assignment, required_collator)) => {
Some(assignment) => {
assignments_span.add_string_tag("assigned", "true");
assignments_span.add_para_id(assignment);
(Some(assignment), required_collator)
Some(assignment)
},
};

Expand All @@ -381,7 +381,6 @@ async fn handle_active_leaves_update<Context>(
let job = CandidateBackingJob {
parent,
assignment,
required_collator,
issued_statements: HashSet::new(),
awaiting_validation: HashSet::new(),
fallbacks: HashMap::new(),
Expand Down Expand Up @@ -412,8 +411,6 @@ struct CandidateBackingJob<Context> {
parent: Hash,
/// The `ParaId` assigned to this validator
assignment: Option<ParaId>,
/// The collator required to author the candidate, if any.
required_collator: Option<CollatorId>,
/// Spans for all candidates that are not yet backable.
unbacked_candidates: HashMap<CandidateHash, jaeger::Span>,
/// We issued `Seconded`, `Valid` or `Invalid` statements on about these candidates.
Expand Down Expand Up @@ -913,21 +910,6 @@ impl<Context> CandidateBackingJob<Context> {
candidate: &CandidateReceipt,
pov: Arc<PoV>,
) -> Result<(), Error> {
// Check that candidate is collated by the right collator.
if self
.required_collator
.as_ref()
.map_or(false, |c| c != &candidate.descriptor().collator)
{
// Break cycle - bounded as there is only one candidate to
// second per block.
ctx.send_unbounded_message(CollatorProtocolMessage::Invalid(
self.parent,
candidate.clone(),
));
return Ok(())
}

let candidate_hash = candidate.hash();
let mut span = self.get_unbacked_validation_child(
root_span,
Expand Down Expand Up @@ -1171,25 +1153,13 @@ impl<Context> CandidateBackingJob<Context> {
return Ok(())
}

let descriptor = attesting.candidate.descriptor().clone();

gum::debug!(
target: LOG_TARGET,
candidate_hash = ?candidate_hash,
candidate_receipt = ?attesting.candidate,
"Kicking off validation",
);

// Check that candidate is collated by the right collator.
if self.required_collator.as_ref().map_or(false, |c| c != &descriptor.collator) {
// If not, we've got the statement in the table but we will
// not issue validation work for it.
//
// Act as though we've issued a statement.
self.issued_statements.insert(candidate_hash);
return Ok(())
}

let bg_sender = ctx.sender().clone();
let pov = PoVData::FetchFromValidator {
from_validator: attesting.from_validator,
Expand Down
120 changes: 3 additions & 117 deletions node/core/backing/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ use polkadot_node_subsystem::{
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_primitives::{
CandidateDescriptor, CollatorId, GroupRotationInfo, HeadData, PersistedValidationData,
PvfExecTimeoutKind, ScheduledCore,
CandidateDescriptor, GroupRotationInfo, HeadData, PersistedValidationData, PvfExecTimeoutKind,
ScheduledCore,
};
use sp_application_crypto::AppCrypto;
use sp_keyring::Sr25519Keyring;
Expand Down Expand Up @@ -98,14 +98,10 @@ impl Default for TestState {
let group_rotation_info =
GroupRotationInfo { session_start_block: 0, group_rotation_frequency: 100, now: 1 };

let thread_collator: CollatorId = Sr25519Keyring::Two.public().into();
let availability_cores = vec![
CoreState::Scheduled(ScheduledCore { para_id: chain_a, collator: None }),
CoreState::Scheduled(ScheduledCore { para_id: chain_b, collator: None }),
CoreState::Scheduled(ScheduledCore {
para_id: thread_a,
collator: Some(thread_collator.clone()),
}),
CoreState::Scheduled(ScheduledCore { para_id: thread_a, collator: None }),
];

let mut head_data = HashMap::new();
Expand Down Expand Up @@ -1186,116 +1182,6 @@ fn backing_works_after_failed_validation() {
});
}

// Test that a `CandidateBackingMessage::Second` issues validation work
// and in case validation is successful issues a `StatementDistributionMessage`.
#[test]
fn backing_doesnt_second_wrong_collator() {
let mut test_state = TestState::default();
test_state.availability_cores[0] = CoreState::Scheduled(ScheduledCore {
para_id: ParaId::from(1),
collator: Some(Sr25519Keyring::Bob.public().into()),
});

test_harness(test_state.keystore.clone(), |mut virtual_overseer| async move {
test_startup(&mut virtual_overseer, &test_state).await;

let pov = PoV { block_data: BlockData(vec![42, 43, 44]) };

let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap();

let pov_hash = pov.hash();
let candidate = TestCandidateBuilder {
para_id: test_state.chain_ids[0],
relay_parent: test_state.relay_parent,
pov_hash,
head_data: expected_head_data.clone(),
erasure_root: make_erasure_root(&test_state, pov.clone()),
}
.build();

let second = CandidateBackingMessage::Second(
test_state.relay_parent,
candidate.to_plain(),
pov.clone(),
);

virtual_overseer.send(FromOrchestra::Communication { msg: second }).await;

assert_matches!(
virtual_overseer.recv().await,
AllMessages::CollatorProtocol(
CollatorProtocolMessage::Invalid(parent, c)
) if parent == test_state.relay_parent && c == candidate.to_plain() => {
}
);

virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::stop_work(test_state.relay_parent),
)))
.await;
virtual_overseer
});
}

#[test]
fn validation_work_ignores_wrong_collator() {
let mut test_state = TestState::default();
test_state.availability_cores[0] = CoreState::Scheduled(ScheduledCore {
para_id: ParaId::from(1),
collator: Some(Sr25519Keyring::Bob.public().into()),
});

test_harness(test_state.keystore.clone(), |mut virtual_overseer| async move {
test_startup(&mut virtual_overseer, &test_state).await;

let pov = PoV { block_data: BlockData(vec![1, 2, 3]) };

let pov_hash = pov.hash();

let expected_head_data = test_state.head_data.get(&test_state.chain_ids[0]).unwrap();

let candidate_a = TestCandidateBuilder {
para_id: test_state.chain_ids[0],
relay_parent: test_state.relay_parent,
pov_hash,
head_data: expected_head_data.clone(),
erasure_root: make_erasure_root(&test_state, pov.clone()),
}
.build();

let public2 = Keystore::sr25519_generate_new(
&*test_state.keystore,
ValidatorId::ID,
Some(&test_state.validators[2].to_seed()),
)
.expect("Insert key into keystore");
let seconding = SignedFullStatement::sign(
&test_state.keystore,
Statement::Seconded(candidate_a.clone()),
&test_state.signing_context,
ValidatorIndex(2),
&public2.into(),
)
.ok()
.flatten()
.expect("should be signed");

let statement =
CandidateBackingMessage::Statement(test_state.relay_parent, seconding.clone());

virtual_overseer.send(FromOrchestra::Communication { msg: statement }).await;

// The statement will be ignored because it has the wrong collator.
virtual_overseer
.send(FromOrchestra::Signal(OverseerSignal::ActiveLeaves(
ActiveLeavesUpdate::stop_work(test_state.relay_parent),
)))
.await;
virtual_overseer
});
}

#[test]
fn candidate_backing_reorders_votes() {
use sp_core::Encode;
Expand Down
1 change: 1 addition & 0 deletions node/network/collator-protocol/src/validator_side/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ async fn process_incoming_peer_message<Context>(
.span_per_relay_parent
.get(&relay_parent)
.map(|s| s.child("advertise-collation"));

if !state.view.contains(&relay_parent) {
gum::debug!(
target: LOG_TARGET,
Expand Down
1 change: 0 additions & 1 deletion node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ sp-session = { git = "https://github.com/paritytech/substrate", branch = "master
sp-storage = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-transaction-pool = { git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-timestamp = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master" }
Expand Down
5 changes: 1 addition & 4 deletions node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ fn default_parachains_host_configuration(
max_pov_size: MAX_POV_SIZE,
max_head_data_size: 32 * 1024,
group_rotation_frequency: 20,
chain_availability_period: 4,
thread_availability_period: 4,
paras_availability_period: 4,
max_upward_queue_count: 8,
max_upward_queue_size: 1024 * 1024,
max_downward_message_size: 1024 * 1024,
Expand All @@ -223,10 +222,8 @@ fn default_parachains_host_configuration(
hrmp_channel_max_capacity: 8,
hrmp_channel_max_total_size: 8 * 1024,
hrmp_max_parachain_inbound_channels: 4,
hrmp_max_parathread_inbound_channels: 4,
hrmp_channel_max_message_size: 1024 * 1024,
hrmp_max_parachain_outbound_channels: 4,
hrmp_max_parathread_outbound_channels: 4,
hrmp_max_message_num_per_candidate: 5,
dispute_period: 6,
no_show_slots: 2,
Expand Down
14 changes: 3 additions & 11 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ use {
sc_client_api::BlockBackend,
sc_transaction_pool_api::OffchainTransactionPoolFactory,
sp_core::traits::SpawnNamed,
sp_trie::PrefixedMemoryDB,
};

use polkadot_node_subsystem_util::database::Database;
Expand Down Expand Up @@ -475,7 +474,7 @@ fn new_partial<ChainSelection>(
FullClient,
FullBackend,
ChainSelection,
sc_consensus::DefaultImportQueue<Block, FullClient>,
sc_consensus::DefaultImportQueue<Block>,
sc_transaction_pool::FullPool<Block, FullClient>,
(
impl Fn(
Expand Down Expand Up @@ -1321,15 +1320,8 @@ macro_rules! chain_ops {
pub fn new_chain_ops(
config: &mut Configuration,
jaeger_agent: Option<std::net::SocketAddr>,
) -> Result<
(
Arc<FullClient>,
Arc<FullBackend>,
sc_consensus::BasicQueue<Block, PrefixedMemoryDB<BlakeTwo256>>,
TaskManager,
),
Error,
> {
) -> Result<(Arc<FullClient>, Arc<FullBackend>, sc_consensus::BasicQueue<Block>, TaskManager), Error>
{
config.keystore = service::config::KeystoreConfig::InMemory;

if config.chain_spec.is_rococo() ||
Expand Down
3 changes: 1 addition & 2 deletions node/test/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ fn polkadot_testnet_genesis(
max_pov_size: MAX_POV_SIZE,
max_head_data_size: 32 * 1024,
group_rotation_frequency: 20,
chain_availability_period: 4,
thread_availability_period: 4,
paras_availability_period: 4,
no_show_slots: 10,
minimum_validation_upgrade_delay: 5,
..Default::default()
Expand Down
3 changes: 2 additions & 1 deletion primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ pub use v5::{
UpgradeRestriction, UpwardMessage, ValidDisputeStatementKind, ValidationCode,
ValidationCodeHash, ValidatorId, ValidatorIndex, ValidatorSignature, ValidityAttestation,
ValidityError, ASSIGNMENT_KEY_TYPE_ID, LOWEST_PUBLIC_ID, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE,
MAX_POV_SIZE, PARACHAINS_INHERENT_IDENTIFIER, PARACHAIN_KEY_TYPE_ID,
MAX_POV_SIZE, ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE, PARACHAINS_INHERENT_IDENTIFIER,
PARACHAIN_KEY_TYPE_ID,
};

#[cfg(feature = "std")]
Expand Down
Loading

0 comments on commit ccc0a75

Please sign in to comment.