Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #994 from ethcore/ommited
Browse files Browse the repository at this point in the history
import route contains ommited blocks
  • Loading branch information
NikVolf committed Apr 24, 2016
2 parents 80a28b9 + 242b986 commit a73323e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 6 additions & 2 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl BlockProvider for BlockChain {
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 }

/// Get raw block data
Expand Down Expand Up @@ -541,7 +541,7 @@ impl BlockChain {
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 {
let block = BlockView::new(block_bytes);
let header = block.header_view();
Expand Down Expand Up @@ -950,21 +950,25 @@ mod tests {
assert_eq!(ir1, ImportRoute {
enacted: vec![b1_hash],
retracted: vec![],
omitted: vec![],
});

assert_eq!(ir2, ImportRoute {
enacted: vec![b2_hash],
retracted: vec![],
omitted: vec![],
});

assert_eq!(ir3b, ImportRoute {
enacted: vec![b3b_hash],
retracted: vec![],
omitted: vec![],
});

assert_eq!(ir3a, ImportRoute {
enacted: vec![b3a_hash],
retracted: vec![b3b_hash],
omitted: vec![],
});

assert_eq!(bc.best_block_hash(), best_block_hash);
Expand Down
20 changes: 18 additions & 2 deletions ethcore/src/blockchain/import_route.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ pub struct ImportRoute {
pub retracted: Vec<H256>,
/// Blocks that were validated by new block.
pub enacted: Vec<H256>,
/// Blocks which are neither retracted nor enacted.
pub omitted: Vec<H256>,
}

impl ImportRoute {
pub fn none() -> Self {
ImportRoute {
retracted: vec![],
enacted: vec![],
omitted: vec![],
}
}
}
Expand All @@ -43,13 +46,19 @@ impl From<BlockInfo> for ImportRoute {
BlockLocation::CanonChain => ImportRoute {
retracted: vec![],
enacted: vec![info.hash],
omitted: vec![],
},
BlockLocation::Branch => ImportRoute {
retracted: vec![],
enacted: vec![],
omitted: vec![info.hash],
},
BlockLocation::Branch => ImportRoute::none(),
BlockLocation::BranchBecomingCanonChain(mut data) => {
data.enacted.push(info.hash);
ImportRoute {
retracted: data.retracted,
enacted: data.enacted,
omitted: vec![],
}
}
}
Expand All @@ -68,6 +77,7 @@ mod tests {
assert_eq!(ImportRoute::none(), ImportRoute {
enacted: vec![],
retracted: vec![],
omitted: vec![],
});
}

Expand All @@ -80,7 +90,11 @@ mod tests {
location: BlockLocation::Branch,
};

assert_eq!(ImportRoute::from(info), ImportRoute::none());
assert_eq!(ImportRoute::from(info), ImportRoute {
retracted: vec![],
enacted: vec![],
omitted: vec![H256::from(U256::from(1))],
});
}

#[test]
Expand All @@ -95,6 +109,7 @@ mod tests {
assert_eq!(ImportRoute::from(info), ImportRoute {
retracted: vec![],
enacted: vec![H256::from(U256::from(1))],
omitted: vec![],
});
}

Expand All @@ -114,6 +129,7 @@ mod tests {
assert_eq!(ImportRoute::from(info), ImportRoute {
retracted: vec![H256::from(U256::from(3)), H256::from(U256::from(4))],
enacted: vec![H256::from(U256::from(1)), H256::from(U256::from(2))],
omitted: vec![],
});
}
}

0 comments on commit a73323e

Please sign in to comment.