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