cleanup mine_block difficulty_iterator usage (#1674)

* take care with diff_iter (contains an active lmdb batch)

* rustfmt
This commit is contained in:
Antioch Peverell 2018-10-06 21:06:02 +01:00 committed by GitHub
parent c86578c2a9
commit 60ef7268ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View file

@ -395,10 +395,8 @@ impl Server {
// code clean. This may be handy for testing but not really needed // code clean. This may be handy for testing but not really needed
// for release // for release
let diff_stats = { let diff_stats = {
let diff_iter = self.chain.difficulty_iter();
let last_blocks: Vec<Result<(u64, Difficulty), consensus::TargetError>> = let last_blocks: Vec<Result<(u64, Difficulty), consensus::TargetError>> =
global::difficulty_data_to_vector(diff_iter) global::difficulty_data_to_vector(self.chain.difficulty_iter())
.into_iter() .into_iter()
.skip(consensus::MEDIAN_TIME_WINDOW as usize) .skip(consensus::MEDIAN_TIME_WINDOW as usize)
.take(consensus::DIFFICULTY_ADJUST_WINDOW as usize) .take(consensus::DIFFICULTY_ADJUST_WINDOW as usize)

View file

@ -104,9 +104,9 @@ fn build_block(
now_sec = head_sec + 1; now_sec = head_sec + 1;
} }
// get the difficulty our block should be at // Determine the difficulty our block should be at.
let diff_iter = chain.difficulty_iter(); // Note: do not keep the difficulty_iter in scope (it has an active batch).
let difficulty = consensus::next_difficulty(diff_iter).unwrap(); let difficulty = consensus::next_difficulty(chain.difficulty_iter()).unwrap();
// extract current transaction from the pool // extract current transaction from the pool
// TODO - we have a lot of unwrap() going on in this fn... // TODO - we have a lot of unwrap() going on in this fn...