mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
Use UTC in timestamps and fix broken header test (#105)
* Fix block header timestamp UTC and fix test * Always use UTC for timestamp as time::Tm
This commit is contained in:
parent
3bf06ecd6a
commit
9c649edfbf
4 changed files with 5 additions and 9 deletions
|
@ -130,7 +130,7 @@ fn validate_header(header: &BlockHeader, ctx: &mut BlockContext) -> Result<(), E
|
|||
return Err(Error::InvalidBlockTime);
|
||||
}
|
||||
if header.timestamp >
|
||||
time::now() + time::Duration::seconds(12 * (consensus::BLOCK_TIME_SEC as i64))
|
||||
time::now_utc() + time::Duration::seconds(12 * (consensus::BLOCK_TIME_SEC as i64))
|
||||
{
|
||||
// refuse blocks more than 12 blocks intervals in future (as in bitcoin)
|
||||
// TODO add warning in p2p code if local time is too different from peers
|
||||
|
|
|
@ -281,7 +281,7 @@ impl Block {
|
|||
Ok(Block {
|
||||
header: BlockHeader {
|
||||
height: prev.height + 1,
|
||||
timestamp: time::now(),
|
||||
timestamp: time::Tm { tm_nsec: 0, ..time::now_utc() },
|
||||
previous: prev.hash(),
|
||||
total_difficulty: prev.pow.clone().to_difficulty() + prev.total_difficulty.clone(),
|
||||
..Default::default()
|
||||
|
@ -632,10 +632,6 @@ mod test {
|
|||
assert_eq!(b.inputs, b2.inputs);
|
||||
assert_eq!(b.outputs, b2.outputs);
|
||||
assert_eq!(b.kernels, b2.kernels);
|
||||
|
||||
// TODO - timestamps are not coming back equal here (UTC related?) -
|
||||
// assert_eq!(b.header, b2.header);
|
||||
// timestamp: Tm { tm_sec: 51, tm_min: 7, tm_hour: 23, tm_mday: 20, tm_mon: 7, tm_year: 117, tm_wday: 0, tm_yday: 231, tm_isdst: 1, tm_utcoff: -14400, tm_nsec: 780878000 },
|
||||
// timestamp: Tm { tm_sec: 51, tm_min: 7, tm_hour: 3, tm_mday: 21, tm_mon: 7, tm_year: 117, tm_wday: 1, tm_yday: 232, tm_isdst: 0, tm_utcoff: 0, tm_nsec: 0 },
|
||||
assert_eq!(b.header, b2.header);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -398,7 +398,7 @@ impl Miner {
|
|||
let mut rng = rand::OsRng::new().unwrap();
|
||||
b.header.nonce = rng.gen();
|
||||
b.header.difficulty = difficulty;
|
||||
b.header.timestamp = time::at(time::Timespec::new(now_sec, 0));
|
||||
b.header.timestamp = time::at_utc(time::Timespec::new(now_sec, 0));
|
||||
b
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ impl PoolEntry {
|
|||
PoolEntry{
|
||||
transaction_hash: transaction_identifier(tx),
|
||||
size_estimate : estimate_transaction_size(tx),
|
||||
receive_ts: time::now()}
|
||||
receive_ts: time::now_utc()}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue