-
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 7 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,7 +24,7 @@ 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, One}}; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| use polkadot_collator::Network as CollatorNetwork; | ||||||||||||||||||||||
| use polkadot_network::legacy::gossip::{GossipMessage, GossipStatement}; | ||||||||||||||||||||||
|
|
@@ -51,32 +51,48 @@ use parking_lot::Mutex; | |||||||||||||||||||||
| /// the justification. | ||||||||||||||||||||||
| /// | ||||||||||||||||||||||
| /// Note: if no justification is provided the annouce is considered valid. | ||||||||||||||||||||||
| pub struct JustifiedBlockAnnounceValidator<B, P> { | ||||||||||||||||||||||
| pub struct JustifiedBlockAnnounceValidator<B, P, C> { | ||||||||||||||||||||||
| phantom: PhantomData<B>, | ||||||||||||||||||||||
| polkadot_client: Arc<P>, | ||||||||||||||||||||||
| parachain_client: Arc<C>, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| impl<B, P> JustifiedBlockAnnounceValidator<B, P> { | ||||||||||||||||||||||
| pub fn new(polkadot_client: Arc<P>) -> Self { | ||||||||||||||||||||||
| impl<B, P, C> JustifiedBlockAnnounceValidator<B, P, C> { | ||||||||||||||||||||||
| pub fn new(polkadot_client: Arc<P>, parachain_client: Arc<C>) -> Self { | ||||||||||||||||||||||
| Self { | ||||||||||||||||||||||
| phantom: Default::default(), | ||||||||||||||||||||||
| polkadot_client, | ||||||||||||||||||||||
| parachain_client, | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| impl<B: BlockT, P> BlockAnnounceValidator<B> for JustifiedBlockAnnounceValidator<B, P> | ||||||||||||||||||||||
| impl<B: BlockT, P, C> BlockAnnounceValidator<B> for JustifiedBlockAnnounceValidator<B, P, C> | ||||||||||||||||||||||
| where | ||||||||||||||||||||||
| P: ProvideRuntimeApi<PBlock> + HeaderBackend<PBlock>, | ||||||||||||||||||||||
| P::Api: ParachainHost<PBlock>, | ||||||||||||||||||||||
| C: HeaderBackend<B>, | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| fn validate( | ||||||||||||||||||||||
| &mut self, | ||||||||||||||||||||||
| header: &B::Header, | ||||||||||||||||||||||
| mut data: &[u8], | ||||||||||||||||||||||
| ) -> Result<Validation, Box<dyn std::error::Error + Send>> { | ||||||||||||||||||||||
| // If no data is provided the announce is valid. | ||||||||||||||||||||||
| // If no data is provided the announce is probably valid | ||||||||||||||||||||||
| if data.is_empty() { | ||||||||||||||||||||||
| // Check if block is one higher than best | ||||||||||||||||||||||
| let best_number = self.parachain_client.info().best_number; | ||||||||||||||||||||||
| 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
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.
Okay, I thought again about this. And I made a mistake.
We should extract the last parachain header that was stored on the relay chain. We get the number of this Parachain header an make sure that:
block_number == parachain_header_number + 1
This way we make sure that we support forks on the same height
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 this condition holds, we need to make sure that there is a justification.
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.
You need a justification if this is a new best block.
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.
like this? 2f9131c