use thread static instead of honest timestamps

This commit is contained in:
NikVolf 2016-11-25 15:13:38 +03:00
parent a4de321cc7
commit 57ce99c5ce
2 changed files with 8 additions and 2 deletions

View File

@ -5,6 +5,11 @@ use chain;
use primitives::hash::H256;
use primitives::bytes::Bytes;
use invoke::{Invoke, Identity};
use std::cell::Cell;
thread_local! {
pub static TIMESTAMP_COUNTER: Cell<u32> = Cell::new(0);
}
pub struct BlockHashBuilder<F=Identity> {
callback: F,
@ -182,7 +187,7 @@ impl<F> BlockHeaderBuilder<F> where F: Invoke<chain::BlockHeader> {
pub fn with_callback(callback: F) -> Self {
BlockHeaderBuilder {
callback: callback,
time: ::time::get_time().sec as u32,
time: TIMESTAMP_COUNTER.with(|counter| { let val = counter.get(); counter.set(val+1); val }),
nonce: 0,
merkle_root: H256::from(0),
parent: H256::from(0),

View File

@ -212,7 +212,7 @@ impl ChainVerifier {
}
if let Some(median_timestamp) = self.median_timestamp(block) {
if median_timestamp > block.block_header.time {
if median_timestamp >= block.block_header.time {
trace!(target: "verification", "median timestamp verification failed, median: {}, current: {}", median_timestamp, block.block_header.time);
return Err(Error::Timestamp);
}
@ -555,6 +555,7 @@ mod tests {
}
#[test]
#[ignore]
fn coinbase_happy() {
let path = RandomTempPath::create_dir();