mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 16:51:03 +00:00
Don't pass validators' public keys with attestations (#186)
* Don't pass validators' public keys with attestations * Update statement-table's Misbehaviour typedef * Update network/router * Expand MessageValidationData * Try to fix tests * Extend ApiContext * Remove 'index_mapping' from the SessionParams * Construct index_mapping from authorities * Move index_mapping to TableContext * Add test for index_mapping order
This commit is contained in:
committed by
Robert Habermeier
parent
36dd42523d
commit
e8fcb43fcf
@@ -22,7 +22,7 @@ use substrate_network::consensus_gossip::{
|
||||
ValidatorContext,
|
||||
};
|
||||
use polkadot_validation::SignedStatement;
|
||||
use polkadot_primitives::{Block, Hash, SessionKey};
|
||||
use polkadot_primitives::{Block, Hash, SessionKey, parachain::ValidatorIndex};
|
||||
use codec::Decode;
|
||||
|
||||
use std::collections::HashMap;
|
||||
@@ -120,19 +120,26 @@ impl RegisteredMessageValidator {
|
||||
}
|
||||
}
|
||||
|
||||
// data needed for validating gossip.
|
||||
/// The data needed for validating gossip.
|
||||
pub(crate) struct MessageValidationData {
|
||||
/// The authorities at a block.
|
||||
pub(crate) authorities: Vec<SessionKey>,
|
||||
/// Mapping from validator index to `SessionKey`.
|
||||
pub(crate) index_mapping: HashMap<ValidatorIndex, SessionKey>,
|
||||
}
|
||||
|
||||
impl MessageValidationData {
|
||||
fn check_statement(&self, relay_parent: &Hash, statement: &SignedStatement) -> bool {
|
||||
self.authorities.contains(&statement.sender) &&
|
||||
let sender = match self.index_mapping.get(&statement.sender) {
|
||||
Some(val) => val,
|
||||
None => return false,
|
||||
};
|
||||
|
||||
self.authorities.contains(&sender) &&
|
||||
::polkadot_validation::check_statement(
|
||||
&statement.statement,
|
||||
&statement.signature,
|
||||
statement.sender.clone(),
|
||||
sender.clone(),
|
||||
relay_parent,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -27,10 +27,9 @@ use sr_primitives::traits::{ProvideRuntimeApi, BlakeTwo256, Hash as HashT};
|
||||
use polkadot_validation::{
|
||||
SharedTable, TableRouter, SignedStatement, GenericStatement, ParachainWork, Outgoing, Validated
|
||||
};
|
||||
use polkadot_primitives::{Block, Hash, SessionKey};
|
||||
use polkadot_primitives::parachain::{
|
||||
Extrinsic, CandidateReceipt, ParachainHost, Id as ParaId, Message,
|
||||
Collation, PoVBlock,
|
||||
use polkadot_primitives::{Block, Hash};
|
||||
use polkadot_primitives::parachain::{Extrinsic, CandidateReceipt, ParachainHost, Id as ParaId, Message,
|
||||
ValidatorIndex, Collation, PoVBlock,
|
||||
};
|
||||
use gossip::RegisteredMessageValidator;
|
||||
|
||||
@@ -163,12 +162,14 @@ impl<P: ProvideRuntimeApi + Send + Sync + 'static, E, N, T> Router<P, E, N, T> w
|
||||
);
|
||||
// dispatch future work as necessary.
|
||||
for (producer, statement) in producers.into_iter().zip(statements) {
|
||||
self.fetcher.knowledge().lock().note_statement(statement.sender, &statement.statement);
|
||||
if let Some(sender) = self.table.index_to_id(statement.sender) {
|
||||
self.fetcher.knowledge().lock().note_statement(sender, &statement.statement);
|
||||
|
||||
if let Some(work) = producer.map(|p| self.create_work(c_hash, p)) {
|
||||
trace!(target: "validation", "driving statement work to completion");
|
||||
let work = work.select2(self.fetcher.exit().clone()).then(|_| Ok(()));
|
||||
self.fetcher.executor().spawn(work);
|
||||
if let Some(work) = producer.map(|p| self.create_work(c_hash, p)) {
|
||||
trace!(target: "validation", "driving statement work to completion");
|
||||
let work = work.select2(self.fetcher.exit().clone()).then(|_| Ok(()));
|
||||
self.fetcher.executor().spawn(work);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -270,8 +271,8 @@ impl<P, E, N: NetworkService, T> Drop for Router<P, E, N, T> {
|
||||
// A unique trace for valid statements issued by a validator.
|
||||
#[derive(Hash, PartialEq, Eq, Clone, Debug)]
|
||||
enum StatementTrace {
|
||||
Valid(SessionKey, Hash),
|
||||
Invalid(SessionKey, Hash),
|
||||
Valid(ValidatorIndex, Hash),
|
||||
Invalid(ValidatorIndex, Hash),
|
||||
}
|
||||
|
||||
// helper for deferring statements whose associated candidate is unknown.
|
||||
@@ -325,19 +326,17 @@ impl DeferredStatements {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use substrate_primitives::crypto::UncheckedInto;
|
||||
use polkadot_primitives::parachain::ValidatorId;
|
||||
|
||||
#[test]
|
||||
fn deferred_statements_works() {
|
||||
let mut deferred = DeferredStatements::new();
|
||||
let hash = [1; 32].into();
|
||||
let sig = Default::default();
|
||||
let sender: ValidatorId = [255; 32].unchecked_into();
|
||||
let sender_index = 0;
|
||||
|
||||
let statement = SignedStatement {
|
||||
statement: GenericStatement::Valid(hash),
|
||||
sender: sender.clone(),
|
||||
sender: sender_index,
|
||||
signature: sig,
|
||||
};
|
||||
|
||||
@@ -358,7 +357,7 @@ mod tests {
|
||||
|
||||
assert_eq!(traces.len(), 1);
|
||||
assert_eq!(signed[0].clone(), statement);
|
||||
assert_eq!(traces[0].clone(), StatementTrace::Valid(sender, hash));
|
||||
assert_eq!(traces[0].clone(), StatementTrace::Valid(sender_index, hash));
|
||||
}
|
||||
|
||||
// after draining
|
||||
|
||||
@@ -401,6 +401,7 @@ fn make_table(data: &ApiData, local_key: &AuthorityKeyring, parent_hash: Hash) -
|
||||
).unwrap();
|
||||
|
||||
Arc::new(SharedTable::new(
|
||||
data.validators.as_slice(),
|
||||
group_info,
|
||||
Arc::new(local_key.pair()),
|
||||
parent_hash,
|
||||
|
||||
@@ -24,10 +24,7 @@ use substrate_network::Context as NetContext;
|
||||
use substrate_network::consensus_gossip::{TopicNotification, MessageRecipient as GossipMessageRecipient};
|
||||
use polkadot_validation::{Network as ParachainNetwork, SharedTable, Collators, Statement, GenericStatement};
|
||||
use polkadot_primitives::{Block, BlockId, Hash, SessionKey};
|
||||
use polkadot_primitives::parachain::{
|
||||
Id as ParaId, Collation, Extrinsic, ParachainHost, Message, CandidateReceipt,
|
||||
CollatorId, ValidatorId, PoVBlock,
|
||||
};
|
||||
use polkadot_primitives::parachain::{Id as ParaId, Collation, Extrinsic, ParachainHost, Message, CandidateReceipt, CollatorId, ValidatorId, PoVBlock, ValidatorIndex};
|
||||
use codec::{Encode, Decode};
|
||||
|
||||
use futures::prelude::*;
|
||||
@@ -195,13 +192,21 @@ impl<P, E, N, T> ValidationNetwork<P, E, N, T> where
|
||||
let task_executor = self.executor.clone();
|
||||
let exit = self.exit.clone();
|
||||
let message_validator = self.message_validator.clone();
|
||||
let index_mapping = params.authorities
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, k)| (i as ValidatorIndex, k.clone()))
|
||||
.collect();
|
||||
|
||||
let (tx, rx) = oneshot::channel();
|
||||
self.network.with_spec(move |spec, ctx| {
|
||||
// before requesting messages, note live consensus session.
|
||||
message_validator.note_session(
|
||||
parent_hash,
|
||||
MessageValidationData { authorities: params.authorities.clone() },
|
||||
MessageValidationData {
|
||||
authorities: params.authorities.clone(),
|
||||
index_mapping,
|
||||
},
|
||||
);
|
||||
|
||||
let session = spec.new_validation_session(ctx, params);
|
||||
|
||||
Reference in New Issue
Block a user