changed route name to enacted and retracted
This commit is contained in:
parent
4750d2f667
commit
0a7cda09ff
@ -44,8 +44,8 @@ pub enum BlockLocation {
|
||||
/// Hash of the newest common ancestor with old canon chain.
|
||||
ancestor: H256,
|
||||
/// Hashes of the blocks between ancestor and this block.
|
||||
route: Vec<H256>,
|
||||
enacted: Vec<H256>,
|
||||
/// Hashes of the blocks which were invalidated.
|
||||
old_route: Vec<H256>,
|
||||
retracted: Vec<H256>,
|
||||
}
|
||||
}
|
||||
|
@ -552,12 +552,12 @@ impl BlockChain {
|
||||
match route.blocks.len() {
|
||||
0 => BlockLocation::CanonChain,
|
||||
_ => {
|
||||
let old_route = route.blocks.iter().take(route.index).cloned().collect::<Vec<H256>>();
|
||||
let retracted = route.blocks.iter().take(route.index).cloned().collect::<Vec<H256>>();
|
||||
|
||||
BlockLocation::BranchBecomingCanonChain {
|
||||
ancestor: route.ancestor,
|
||||
route: route.blocks.into_iter().skip(route.index).collect(),
|
||||
old_route: old_route.into_iter().rev().collect(),
|
||||
enacted: route.blocks.into_iter().skip(route.index).collect(),
|
||||
retracted: retracted.into_iter().rev().collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -579,11 +579,11 @@ impl BlockChain {
|
||||
BlockLocation::CanonChain => {
|
||||
block_hashes.insert(number, info.hash.clone());
|
||||
},
|
||||
BlockLocation::BranchBecomingCanonChain { ref ancestor, ref route, .. } => {
|
||||
BlockLocation::BranchBecomingCanonChain { ref ancestor, ref enacted, .. } => {
|
||||
let ancestor_number = self.block_number(ancestor).unwrap();
|
||||
let start_number = ancestor_number + 1;
|
||||
|
||||
for (index, hash) in route.iter().cloned().enumerate() {
|
||||
for (index, hash) in enacted.iter().cloned().enumerate() {
|
||||
block_hashes.insert(start_number + index as BlockNumber, hash);
|
||||
}
|
||||
|
||||
@ -668,11 +668,11 @@ impl BlockChain {
|
||||
ChainFilter::new(self, self.bloom_indexer.index_size(), self.bloom_indexer.levels())
|
||||
.add_bloom(&header.log_bloom(), header.number() as usize)
|
||||
},
|
||||
BlockLocation::BranchBecomingCanonChain { ref ancestor, ref route, .. } => {
|
||||
BlockLocation::BranchBecomingCanonChain { ref ancestor, ref enacted, .. } => {
|
||||
let ancestor_number = self.block_number(ancestor).unwrap();
|
||||
let start_number = ancestor_number + 1;
|
||||
|
||||
let mut blooms: Vec<H2048> = route.iter()
|
||||
let mut blooms: Vec<H2048> = enacted.iter()
|
||||
.map(|hash| self.block(hash).unwrap())
|
||||
.map(|bytes| BlockView::new(&bytes).header_view().log_bloom())
|
||||
.collect();
|
||||
@ -956,23 +956,23 @@ mod tests {
|
||||
let ir3a = bc.insert_block(&b3a, vec![]);
|
||||
|
||||
assert_eq!(ir1, ImportRoute {
|
||||
validated_blocks: vec![b1_hash],
|
||||
invalidated_blocks: vec![],
|
||||
enacted: vec![b1_hash],
|
||||
retracted: vec![],
|
||||
});
|
||||
|
||||
assert_eq!(ir2, ImportRoute {
|
||||
validated_blocks: vec![b2_hash],
|
||||
invalidated_blocks: vec![],
|
||||
enacted: vec![b2_hash],
|
||||
retracted: vec![],
|
||||
});
|
||||
|
||||
assert_eq!(ir3b, ImportRoute {
|
||||
validated_blocks: vec![b3b_hash],
|
||||
invalidated_blocks: vec![],
|
||||
enacted: vec![b3b_hash],
|
||||
retracted: vec![],
|
||||
});
|
||||
|
||||
assert_eq!(ir3a, ImportRoute {
|
||||
validated_blocks: vec![b3a_hash],
|
||||
invalidated_blocks: vec![b3b_hash],
|
||||
enacted: vec![b3a_hash],
|
||||
retracted: vec![b3b_hash],
|
||||
});
|
||||
|
||||
assert_eq!(bc.best_block_hash(), best_block_hash);
|
||||
|
@ -23,16 +23,16 @@ use blockchain::block_info::{BlockInfo, BlockLocation};
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct ImportRoute {
|
||||
/// Blocks that were invalidated by new block.
|
||||
pub invalidated_blocks: Vec<H256>,
|
||||
pub retracted: Vec<H256>,
|
||||
/// Blocks that were validated by new block.
|
||||
pub validated_blocks: Vec<H256>,
|
||||
pub enacted: Vec<H256>,
|
||||
}
|
||||
|
||||
impl ImportRoute {
|
||||
pub fn none() -> Self {
|
||||
ImportRoute {
|
||||
invalidated_blocks: vec![],
|
||||
validated_blocks: vec![],
|
||||
retracted: vec![],
|
||||
enacted: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -41,15 +41,15 @@ impl From<BlockInfo> for ImportRoute {
|
||||
fn from(info: BlockInfo) -> ImportRoute {
|
||||
match info.location {
|
||||
BlockLocation::CanonChain => ImportRoute {
|
||||
invalidated_blocks: vec![],
|
||||
validated_blocks: vec![info.hash],
|
||||
retracted: vec![],
|
||||
enacted: vec![info.hash],
|
||||
},
|
||||
BlockLocation::Branch => ImportRoute::none(),
|
||||
BlockLocation::BranchBecomingCanonChain { mut route, old_route, .. } => {
|
||||
route.push(info.hash);
|
||||
BlockLocation::BranchBecomingCanonChain { mut enacted, retracted, .. } => {
|
||||
enacted.push(info.hash);
|
||||
ImportRoute {
|
||||
invalidated_blocks: old_route,
|
||||
validated_blocks: route,
|
||||
retracted: retracted,
|
||||
enacted: enacted,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -66,8 +66,8 @@ mod tests {
|
||||
#[test]
|
||||
fn import_route_none() {
|
||||
assert_eq!(ImportRoute::none(), ImportRoute {
|
||||
validated_blocks: vec![],
|
||||
invalidated_blocks: vec![],
|
||||
enacted: vec![],
|
||||
retracted: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
@ -93,8 +93,8 @@ mod tests {
|
||||
};
|
||||
|
||||
assert_eq!(ImportRoute::from(info), ImportRoute {
|
||||
invalidated_blocks: vec![],
|
||||
validated_blocks: vec![H256::from(U256::from(1))],
|
||||
retracted: vec![],
|
||||
enacted: vec![H256::from(U256::from(1))],
|
||||
});
|
||||
}
|
||||
|
||||
@ -106,14 +106,14 @@ mod tests {
|
||||
total_difficulty: U256::from(0),
|
||||
location: BlockLocation::BranchBecomingCanonChain {
|
||||
ancestor: H256::from(U256::from(0)),
|
||||
route: vec![H256::from(U256::from(1))],
|
||||
old_route: vec![H256::from(U256::from(3)), H256::from(U256::from(4))],
|
||||
enacted: vec![H256::from(U256::from(1))],
|
||||
retracted: vec![H256::from(U256::from(3)), H256::from(U256::from(4))],
|
||||
}
|
||||
};
|
||||
|
||||
assert_eq!(ImportRoute::from(info), ImportRoute {
|
||||
invalidated_blocks: vec![H256::from(U256::from(3)), H256::from(U256::from(4))],
|
||||
validated_blocks: vec![H256::from(U256::from(1)), H256::from(U256::from(2))],
|
||||
retracted: vec![H256::from(U256::from(3)), H256::from(U256::from(4))],
|
||||
enacted: vec![H256::from(U256::from(1)), H256::from(U256::from(2))],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user