Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
Forked at: 8f02e23
Parent branch: origin/master
  • Loading branch information
cecton committed May 28, 2020
commit a86bfdd322eb285651eac4b1e881f015b59f9ce6
56 changes: 30 additions & 26 deletions network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,35 @@ where
header: &B::Header,
mut data: &[u8],
) -> Result<Validation, Box<dyn std::error::Error + Send>> {
let runtime_api = self.polkadot_client.runtime_api();
let polkadot_info = self.polkadot_client.info();

if data.is_empty() {
// Check if block is one higher than best
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need a justification if this is a new best block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like this? 2f9131c

let runtime_api_block_id = BlockId::Hash(polkadot_info.best_hash);
let block_number: <<B as BlockT>::Header as HeaderT>::Number = *header.number();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let block_number: <<B as BlockT>::Header as HeaderT>::Number = *header.number();
let block_number = header.number().clone();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


let local_validation_data = runtime_api
.local_validation_data(&runtime_api_block_id, self.para_id)
.map_err(|e| Box::new(ClientError::Msg(format!("{:?}", e))) as Box<_>)?
.ok_or_else(|| {
Box::new(ClientError::Msg("no local validation data".to_string())) as Box<_>
})?;
let parent_head = HeadData::<B>::decode(&mut &local_validation_data.parent_head.0[..])
.map_err(|e| Box::new(ClientError::Msg(format!("{:?}", e))) as Box<_>)?;
let known_best_number = *parent_head.header.number();

if block_number < known_best_number {
trace!(
target: "cumulus-network",
"validation failed because the block number is not at least the best block \
number known",
);

return Ok(Validation::Failure);
}
}

// Check data is a gossip message.
let gossip_message = GossipMessage::decode(&mut data).map_err(|_| {
Box::new(ClientError::BadJustification(
Expand Down Expand Up @@ -114,7 +143,7 @@ where
} = gossip_statement;

// Check that the relay chain parent of the block is the relay chain head
let best_number = self.polkadot_client.info().best_number;
let best_number = polkadot_info.best_number;

match self.polkadot_client.number(relay_chain_leaf) {
Err(err) => {
Expand All @@ -139,36 +168,11 @@ where
},
}

let runtime_api = self.polkadot_client.runtime_api();
let runtime_api_block_id = BlockId::Hash(relay_chain_leaf);
let signing_context = runtime_api
.signing_context(&runtime_api_block_id)
.map_err(|e| Box::new(ClientError::Msg(format!("{:?}", e))) as Box<_>)?;

if data.is_empty() {
// Check if block is one higher than best
let local_validation_data = runtime_api
.local_validation_data(&runtime_api_block_id, self.para_id)
.map_err(|e| Box::new(ClientError::Msg(format!("{:?}", e))) as Box<_>)?
.ok_or_else(|| {
Box::new(ClientError::Msg("no local validation data".to_string())) as Box<_>
})?;
let parent_head = HeadData::<B>::decode(&mut &local_validation_data.parent_head.0[..])
.map_err(|e| Box::new(ClientError::Msg(format!("{:?}", e))) as Box<_>)?;
let known_best_number = *parent_head.header.number();
let block_number: <<B as BlockT>::Header as HeaderT>::Number = *header.number();

if block_number < known_best_number {
trace!(
target: "cumulus-network",
"validation failed because the block number is not at least the best block \
number known",
);

return Ok(Validation::Failure);
}
}

// Check that the signer is a legit validator.
let authorities = runtime_api.validators(&runtime_api_block_id)
.map_err(|e| Box::new(ClientError::Msg(format!("{:?}", e))) as Box<_>)?;
Expand Down