From a1034cf62344fd6f86d28fa12c0832487444b9e4 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Tue, 22 Aug 2017 13:36:35 +0300 Subject: [PATCH] fixed median_timestamp calculation --- verification/src/timestamp.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/verification/src/timestamp.rs b/verification/src/timestamp.rs index 3aef250e..5c1487ad 100644 --- a/verification/src/timestamp.rs +++ b/verification/src/timestamp.rs @@ -1,4 +1,3 @@ -use std::collections::BTreeSet; use chain::BlockHeader; use db::{BlockHeaderProvider, BlockAncestors}; use primitives::hash::H256; @@ -14,7 +13,7 @@ pub fn median_timestamp(header: &BlockHeader, store: &BlockHeaderProvider) -> u3 /// The header should be later expected to have higher timestamp /// than this median timestamp pub fn median_timestamp_inclusive(previous_header_hash: H256, store: &BlockHeaderProvider) -> u32 { - let timestamps: BTreeSet<_> = BlockAncestors::new(previous_header_hash.clone().into(), store) + let mut timestamps: Vec<_> = BlockAncestors::new(previous_header_hash.clone().into(), store) .take(11) .map(|header| header.time) .collect(); @@ -23,6 +22,6 @@ pub fn median_timestamp_inclusive(previous_header_hash: H256, store: &BlockHeade return 0; } - let timestamps = timestamps.into_iter().collect::>(); + timestamps.sort(); timestamps[timestamps.len() / 2] }