-
Notifications
You must be signed in to change notification settings - Fork 371
Reject blocks without justification which don't have the best number #105
Changes from 12 commits
ae3ce09
ee60e12
5bb6082
bf53b31
86b8403
2cac26a
c2a063a
36fc71a
a86bfdd
452586e
d92acd6
615e949
3a4a6ba
36ecce0
4b022b1
8bccf15
65c571b
3b3bf98
2f9131c
a5bc4bd
eb6103b
b33c2ba
1394c70
64a3302
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,12 +24,12 @@ mod tests; | |||||||||||||||||||||
| use sp_api::ProvideRuntimeApi; | ||||||||||||||||||||||
| use sp_blockchain::{Error as ClientError, HeaderBackend}; | ||||||||||||||||||||||
| use sp_consensus::block_validation::{BlockAnnounceValidator, Validation}; | ||||||||||||||||||||||
| use sp_runtime::{generic::BlockId, traits::Block as BlockT}; | ||||||||||||||||||||||
| use sp_runtime::{generic::BlockId, traits::{Block as BlockT, Header as HeaderT}}; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| use polkadot_collator::Network as CollatorNetwork; | ||||||||||||||||||||||
| use polkadot_network::legacy::gossip::{GossipMessage, GossipStatement}; | ||||||||||||||||||||||
| use polkadot_primitives::{ | ||||||||||||||||||||||
| parachain::ParachainHost, | ||||||||||||||||||||||
| parachain::{ParachainHost, Id as ParaId}, | ||||||||||||||||||||||
| Block as PBlock, Hash as PHash, | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| use polkadot_statement_table::{SignedStatement, Statement}; | ||||||||||||||||||||||
|
|
@@ -45,6 +45,12 @@ use log::{error, trace}; | |||||||||||||||||||||
| use std::{marker::PhantomData, sync::Arc}; | ||||||||||||||||||||||
| use parking_lot::Mutex; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// The head data of the parachain, stored in the relay chain. | ||||||||||||||||||||||
| #[derive(Decode, Encode, Debug)] | ||||||||||||||||||||||
| struct HeadData<Block: BlockT> { | ||||||||||||||||||||||
| header: Block::Header, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /// Validate that data is a valid justification from a relay-chain validator that the block is a | ||||||||||||||||||||||
| /// valid parachain-block candidate. | ||||||||||||||||||||||
| /// Data encoding is just `GossipMessage`, the relay-chain validator candidate statement message is | ||||||||||||||||||||||
|
|
@@ -54,13 +60,15 @@ use parking_lot::Mutex; | |||||||||||||||||||||
| pub struct JustifiedBlockAnnounceValidator<B, P> { | ||||||||||||||||||||||
| phantom: PhantomData<B>, | ||||||||||||||||||||||
| polkadot_client: Arc<P>, | ||||||||||||||||||||||
| para_id: ParaId, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| impl<B, P> JustifiedBlockAnnounceValidator<B, P> { | ||||||||||||||||||||||
| pub fn new(polkadot_client: Arc<P>) -> Self { | ||||||||||||||||||||||
| pub fn new(polkadot_client: Arc<P>, para_id: ParaId) -> Self { | ||||||||||||||||||||||
| Self { | ||||||||||||||||||||||
| phantom: Default::default(), | ||||||||||||||||||||||
| polkadot_client, | ||||||||||||||||||||||
| para_id, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -75,8 +83,34 @@ where | |||||||||||||||||||||
| header: &B::Header, | ||||||||||||||||||||||
| mut data: &[u8], | ||||||||||||||||||||||
| ) -> Result<Validation, Box<dyn std::error::Error + Send>> { | ||||||||||||||||||||||
| // If no data is provided the announce is valid. | ||||||||||||||||||||||
| 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 | ||||||||||||||||||||||
|
||||||||||||||||||||||
| let runtime_api_block_id = BlockId::Hash(polkadot_info.best_hash); | ||||||||||||||||||||||
| let block_number: <<B as BlockT>::Header as HeaderT>::Number = *header.number(); | ||||||||||||||||||||||
|
||||||||||||||||||||||
| let block_number: <<B as BlockT>::Header as HeaderT>::Number = *header.number(); | |
| let block_number = header.number().clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cecton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
cecton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if !(block_number < known_best_number) { | |
| let res = if block_number >= known_best_number { |
Negations always makes stuff much more complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cecton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return Ok(Validation::Failure); | |
| } | |
| return Ok(Validation::Success); | |
| Validation::Failure | |
| } else { | |
| Validation::Success | |
| }; | |
| return Ok(res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eww no, the rest of the function follows the pattern:
if <condition> {
return ... // short-circuit
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but here a else makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move that into
primitivesand consolidate with the one incollatorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done