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:
Stanislav Tkach
2019-05-08 22:19:39 +03:00
committed by Robert Habermeier
parent 36dd42523d
commit e8fcb43fcf
10 changed files with 130 additions and 61 deletions
+15 -16
View File
@@ -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