import route contains ommited blocks

This commit is contained in:
debris 2016-04-24 19:40:04 +02:00
parent 0b78a1ead9
commit d5555de1b9
2 changed files with 24 additions and 4 deletions

View File

@ -186,7 +186,7 @@ impl BlockProvider for BlockChain {
self.extras_db.exists_with_cache(&self.block_details, hash) self.extras_db.exists_with_cache(&self.block_details, hash)
} }
// We do not store tracing information. /// We do not store tracing information.
fn have_tracing(&self) -> bool { false } fn have_tracing(&self) -> bool { false }
/// Get raw block data /// Get raw block data
@ -541,7 +541,7 @@ impl BlockChain {
Some(ret) Some(ret)
} }
/// Get inserted block info which is critical to preapre extras updates. /// Get inserted block info which is critical to prepare extras updates.
fn block_info(&self, block_bytes: &[u8]) -> BlockInfo { fn block_info(&self, block_bytes: &[u8]) -> BlockInfo {
let block = BlockView::new(block_bytes); let block = BlockView::new(block_bytes);
let header = block.header_view(); let header = block.header_view();
@ -950,21 +950,25 @@ mod tests {
assert_eq!(ir1, ImportRoute { assert_eq!(ir1, ImportRoute {
enacted: vec![b1_hash], enacted: vec![b1_hash],
retracted: vec![], retracted: vec![],
ommited: vec![],
}); });
assert_eq!(ir2, ImportRoute { assert_eq!(ir2, ImportRoute {
enacted: vec![b2_hash], enacted: vec![b2_hash],
retracted: vec![], retracted: vec![],
ommited: vec![],
}); });
assert_eq!(ir3b, ImportRoute { assert_eq!(ir3b, ImportRoute {
enacted: vec![b3b_hash], enacted: vec![b3b_hash],
retracted: vec![], retracted: vec![],
ommited: vec![],
}); });
assert_eq!(ir3a, ImportRoute { assert_eq!(ir3a, ImportRoute {
enacted: vec![b3a_hash], enacted: vec![b3a_hash],
retracted: vec![b3b_hash], retracted: vec![b3b_hash],
ommited: vec![],
}); });
assert_eq!(bc.best_block_hash(), best_block_hash); assert_eq!(bc.best_block_hash(), best_block_hash);

View File

@ -26,6 +26,8 @@ pub struct ImportRoute {
pub retracted: Vec<H256>, pub retracted: Vec<H256>,
/// Blocks that were validated by new block. /// Blocks that were validated by new block.
pub enacted: Vec<H256>, pub enacted: Vec<H256>,
/// Blocks which are neither retracted nor enacted.
pub ommited: Vec<H256>,
} }
impl ImportRoute { impl ImportRoute {
@ -33,6 +35,7 @@ impl ImportRoute {
ImportRoute { ImportRoute {
retracted: vec![], retracted: vec![],
enacted: vec![], enacted: vec![],
ommited: vec![],
} }
} }
} }
@ -43,13 +46,19 @@ impl From<BlockInfo> for ImportRoute {
BlockLocation::CanonChain => ImportRoute { BlockLocation::CanonChain => ImportRoute {
retracted: vec![], retracted: vec![],
enacted: vec![info.hash], enacted: vec![info.hash],
ommited: vec![],
},
BlockLocation::Branch => ImportRoute {
retracted: vec![],
enacted: vec![],
ommited: vec![info.hash],
}, },
BlockLocation::Branch => ImportRoute::none(),
BlockLocation::BranchBecomingCanonChain(mut data) => { BlockLocation::BranchBecomingCanonChain(mut data) => {
data.enacted.push(info.hash); data.enacted.push(info.hash);
ImportRoute { ImportRoute {
retracted: data.retracted, retracted: data.retracted,
enacted: data.enacted, enacted: data.enacted,
ommited: vec![],
} }
} }
} }
@ -68,6 +77,7 @@ mod tests {
assert_eq!(ImportRoute::none(), ImportRoute { assert_eq!(ImportRoute::none(), ImportRoute {
enacted: vec![], enacted: vec![],
retracted: vec![], retracted: vec![],
ommited: vec![],
}); });
} }
@ -80,7 +90,11 @@ mod tests {
location: BlockLocation::Branch, location: BlockLocation::Branch,
}; };
assert_eq!(ImportRoute::from(info), ImportRoute::none()); assert_eq!(ImportRoute::from(info), ImportRoute {
retracted: vec![],
enacted: vec![],
ommited: vec![H256::from(U256::from(1))],
});
} }
#[test] #[test]
@ -95,6 +109,7 @@ mod tests {
assert_eq!(ImportRoute::from(info), ImportRoute { assert_eq!(ImportRoute::from(info), ImportRoute {
retracted: vec![], retracted: vec![],
enacted: vec![H256::from(U256::from(1))], enacted: vec![H256::from(U256::from(1))],
ommited: vec![],
}); });
} }
@ -114,6 +129,7 @@ mod tests {
assert_eq!(ImportRoute::from(info), ImportRoute { assert_eq!(ImportRoute::from(info), ImportRoute {
retracted: vec![H256::from(U256::from(3)), H256::from(U256::from(4))], retracted: vec![H256::from(U256::from(3)), H256::from(U256::from(4))],
enacted: vec![H256::from(U256::from(1)), H256::from(U256::from(2))], enacted: vec![H256::from(U256::from(1)), H256::from(U256::from(2))],
ommited: vec![],
}); });
} }
} }