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

Commit

Permalink
Fixing expect calls
Browse files Browse the repository at this point in the history
  • Loading branch information
arkpar committed Sep 20, 2016
1 parent c130ba4 commit d9e232b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
10 changes: 7 additions & 3 deletions ethcore/src/blockchain/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ pub trait BlockProvider {

/// Get the number of the first block.
fn first_block_number(&self) -> Option<BlockNumber> {
self.first_block().map(|b| self.block_number(&b).expect("First block always stored; qed"))
self.first_block().map(|b| self.block_number(&b).expect("First block is always set to an existing block or `None`. Existing block always has a number; qed"))
}

/// Get the best block of an first block sequence if there is a gap.
fn best_ancient_block(&self) -> Option<H256>;

/// Get the number of the first block.
fn best_ancient_number(&self) -> Option<BlockNumber> {
self.best_ancient_block().map(|h| self.block_number(&h).expect("Best ancient block always stored; qed"))
self.best_ancient_block().map(|h| self.block_number(&h).expect("Ancient block is always set to an existing block or `None`. Existing block always has a number; qed"))
}
/// Get raw block data
fn block(&self, hash: &H256) -> Option<Bytes>;
Expand Down Expand Up @@ -169,10 +169,14 @@ impl bc::group::BloomGroupDatabase for BlockChain {
pub struct BlockChain {
// All locks must be captured in the order declared here.
blooms_config: bc::Config,
first_block: Option<H256>,

best_block: RwLock<BestBlock>,
// Stores best block of the first uninterrupted sequence of blocks. `None` if there are no gaps.
// Only updated with `insert_unordered_block`.
best_ancient_block: RwLock<Option<BestAncientBlock>>,
// Stores the last block of the last sequence of blocks. `None` if there are no gaps.
// This is calculated on start and does not get updated.
first_block: Option<H256>,

// block cache
block_headers: RwLock<HashMap<H256, Bytes>>,
Expand Down
28 changes: 15 additions & 13 deletions sync/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,14 @@ impl ChainSync {
let mut downloader = match block_set {
BlockSet::NewBlocks => &mut self.new_blocks,
BlockSet::OldBlocks => {
if self.old_blocks.is_none() {
trace!(target: "sync", "Ignored block headers while block download is inactive");
self.continue_sync(io);
return Ok(());
match self.old_blocks {
None => {
trace!(target: "sync", "Ignored block headers while block download is inactive");
self.continue_sync(io);
return Ok(());
},
Some(ref mut blocks) => blocks,
}
self.old_blocks.as_mut().expect("Checked with condition above; qed")
}
};
downloader.import_headers(io, r, expected_hash)
Expand Down Expand Up @@ -625,13 +627,13 @@ impl ChainSync {
let result = {
let mut downloader = match block_set {
BlockSet::NewBlocks => &mut self.new_blocks,
BlockSet::OldBlocks => {
if self.old_blocks.is_none() {
BlockSet::OldBlocks => match self.old_blocks {
None => {
trace!(target: "sync", "Ignored block headers while block download is inactive");
self.continue_sync(io);
return Ok(());
}
self.old_blocks.as_mut().expect("Checked with condition above; qed")
},
Some(ref mut blocks) => blocks,
}
};
downloader.import_bodies(io, r)
Expand Down Expand Up @@ -679,13 +681,13 @@ impl ChainSync {
let result = {
let mut downloader = match block_set {
BlockSet::NewBlocks => &mut self.new_blocks,
BlockSet::OldBlocks => {
if self.old_blocks.is_none() {
BlockSet::OldBlocks => match self.old_blocks {
None => {
trace!(target: "sync", "Ignored block headers while block download is inactive");
self.continue_sync(io);
return Ok(());
}
self.old_blocks.as_mut().expect("Checked with condition above; qed")
},
Some(ref mut blocks) => blocks,
}
};
downloader.import_receipts(io, r)
Expand Down

0 comments on commit d9e232b

Please sign in to comment.