Support synching of blocks that are not new_best (#6508)

* Start

* Remove debug println

* Add tests
This commit is contained in:
Bastian Köcher
2020-06-30 16:44:52 +02:00
committed by GitHub
parent 4fd770dcf9
commit 53be6ec510
9 changed files with 172 additions and 53 deletions
@@ -36,7 +36,10 @@ impl<T: Chain<B>, B: Block> Chain<B> for Arc<T> {
#[derive(Debug, PartialEq, Eq)]
pub enum Validation {
/// Valid block announcement.
Success,
Success {
/// Is this the new best block of the node?
is_new_best: bool,
},
/// Invalid block announcement.
Failure,
}
@@ -49,18 +52,10 @@ pub trait BlockAnnounceValidator<B: Block> {
/// Default implementation of `BlockAnnounceValidator`.
#[derive(Debug)]
pub struct DefaultBlockAnnounceValidator<C> {
chain: C
}
pub struct DefaultBlockAnnounceValidator;
impl<C> DefaultBlockAnnounceValidator<C> {
pub fn new(chain: C) -> Self {
Self { chain }
}
}
impl<B: Block, C: Chain<B>> BlockAnnounceValidator<B> for DefaultBlockAnnounceValidator<C> {
impl<B: Block> BlockAnnounceValidator<B> for DefaultBlockAnnounceValidator {
fn validate(&mut self, _h: &B::Header, _d: &[u8]) -> Result<Validation, Box<dyn Error + Send>> {
Ok(Validation::Success)
Ok(Validation::Success { is_new_best: false })
}
}