Skip to content

Commit

Permalink
Remove availability statement (paritytech#79)
Browse files Browse the repository at this point in the history
* remove availability vote type from statement-table

* expunge availability statement from consensus module

* expunge availability from duty roster

* rename StatementProducer to ParachainWork

* fix runtime tests and remove availability statement variant

* update wasm
  • Loading branch information
rphmeier authored and gavofyork committed Jan 18, 2019
1 parent fbfcaa1 commit ef8a6c7
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 621 deletions.
11 changes: 4 additions & 7 deletions consensus/src/collation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ impl<C: Collators, P: ProvideRuntimeApi> Future for CollationFetch<C, P>
};

match validate_collation(&*self.client, &self.relay_parent, &x) {
Ok(()) => {
// TODO: generate extrinsic while verifying.
return Ok(Async::Ready((x, Extrinsic)));
}
Ok(e) => return Ok(Async::Ready((x, e))),
Err(e) => {
debug!("Failed to validate parachain due to API error: {}", e);

Expand Down Expand Up @@ -140,12 +137,12 @@ error_chain! {
}
}

/// Check whether a given collation is valid. Returns `Ok` on success, error otherwise.
/// Check whether a given collation is valid. Returns `Ok` on success, error otherwise.
pub fn validate_collation<P>(
client: &P,
relay_parent: &BlockId,
collation: &Collation
) -> Result<(), Error> where
) -> Result<Extrinsic, Error> where
P: ProvideRuntimeApi,
P::Api: ParachainHost<Block>
{
Expand All @@ -167,7 +164,7 @@ pub fn validate_collation<P>(
match parachain::wasm::validate_candidate(&validation_code, params) {
Ok(result) => {
if result.head_data == collation.receipt.head_data.0 {
Ok(())
Ok(Extrinsic)
} else {
Err(ErrorKind::WrongHeadData(
collation.receipt.head_data.0.clone(),
Expand Down
33 changes: 8 additions & 25 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ use dynamic_inclusion::DynamicInclusion;

pub use self::collation::{validate_collation, Collators};
pub use self::error::{ErrorKind, Error};
pub use self::shared_table::{SharedTable, StatementProducer, ProducedStatements, Statement, SignedStatement, GenericStatement};
pub use self::shared_table::{SharedTable, ParachainWork, PrimedParachainWork, Validated, Statement, SignedStatement, GenericStatement};

mod attestation_service;
mod dynamic_inclusion;
Expand Down Expand Up @@ -147,12 +147,8 @@ pub trait Network {
pub struct GroupInfo {
/// Authorities meant to check validity of candidates.
pub validity_guarantors: HashSet<SessionKey>,
/// Authorities meant to check availability of candidate data.
pub availability_guarantors: HashSet<SessionKey>,
/// Number of votes needed for validity.
pub needed_validity: usize,
/// Number of votes needed for availability.
pub needed_availability: usize,
}

/// Sign a table statement against a parent hash.
Expand Down Expand Up @@ -183,15 +179,11 @@ fn make_group_info(roster: DutyRoster, authorities: &[AuthorityId], local_id: Au
bail!(ErrorKind::InvalidDutyRosterLength(authorities.len(), roster.validator_duty.len()))
}

if roster.guarantor_duty.len() != authorities.len() {
bail!(ErrorKind::InvalidDutyRosterLength(authorities.len(), roster.guarantor_duty.len()))
}

let mut local_validation = None;
let mut map = HashMap::new();

let duty_iter = authorities.iter().zip(&roster.validator_duty).zip(&roster.guarantor_duty);
for ((authority, v_duty), a_duty) in duty_iter {
let duty_iter = authorities.iter().zip(&roster.validator_duty);
for (authority, v_duty) in duty_iter {
if authority == &local_id {
local_validation = Some(v_duty.clone());
}
Expand All @@ -204,23 +196,11 @@ fn make_group_info(roster: DutyRoster, authorities: &[AuthorityId], local_id: Au
.insert(authority.clone());
}
}

match *a_duty {
Chain::Relay => {}, // does nothing for now.
Chain::Parachain(ref id) => {
map.entry(id.clone()).or_insert_with(GroupInfo::default)
.availability_guarantors
.insert(authority.clone());
}
}
}

for live_group in map.values_mut() {
let validity_len = live_group.validity_guarantors.len();
let availability_len = live_group.availability_guarantors.len();

live_group.needed_validity = validity_len / 2 + validity_len % 2;
live_group.needed_availability = availability_len / 2 + availability_len % 2;
}

match local_validation {
Expand Down Expand Up @@ -470,8 +450,11 @@ fn dispatch_collation_work<R, C, P>(
});

match res {
Ok(()) =>
router.local_candidate(collation.receipt, collation.block_data, extrinsic),
Ok(()) => {
// TODO: https://github.com/paritytech/polkadot/issues/51
// Erasure-code and provide merkle branches.
router.local_candidate(collation.receipt, collation.block_data, extrinsic)
}
Err(e) =>
warn!(target: "consensus", "Failed to make collation data available: {:?}", e),
}
Expand Down
Loading

0 comments on commit ef8a6c7

Please sign in to comment.