mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
warning cleanup (#3759)
This commit is contained in:
parent
a9f45dee2b
commit
d1b7ae5352
7 changed files with 45 additions and 16 deletions
|
@ -231,7 +231,10 @@ impl Default for BlockHeader {
|
||||||
BlockHeader {
|
BlockHeader {
|
||||||
version: HeaderVersion(1),
|
version: HeaderVersion(1),
|
||||||
height: 0,
|
height: 0,
|
||||||
timestamp: DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(0, 0), Utc),
|
timestamp: DateTime::<Utc>::from_utc(
|
||||||
|
NaiveDateTime::from_timestamp_opt(0, 0).unwrap(),
|
||||||
|
Utc,
|
||||||
|
),
|
||||||
prev_hash: ZERO_HASH,
|
prev_hash: ZERO_HASH,
|
||||||
prev_root: ZERO_HASH,
|
prev_root: ZERO_HASH,
|
||||||
output_root: ZERO_HASH,
|
output_root: ZERO_HASH,
|
||||||
|
@ -288,16 +291,29 @@ fn read_block_header<R: Reader>(reader: &mut R) -> Result<BlockHeader, ser::Erro
|
||||||
let (output_mmr_size, kernel_mmr_size) = ser_multiread!(reader, read_u64, read_u64);
|
let (output_mmr_size, kernel_mmr_size) = ser_multiread!(reader, read_u64, read_u64);
|
||||||
let pow = ProofOfWork::read(reader)?;
|
let pow = ProofOfWork::read(reader)?;
|
||||||
|
|
||||||
if timestamp > chrono::NaiveDate::MAX.and_hms(0, 0, 0).timestamp()
|
if timestamp
|
||||||
|| timestamp < chrono::NaiveDate::MIN.and_hms(0, 0, 0).timestamp()
|
> chrono::NaiveDate::MAX
|
||||||
|
.and_hms_opt(0, 0, 0)
|
||||||
|
.unwrap()
|
||||||
|
.timestamp()
|
||||||
|
|| timestamp
|
||||||
|
< chrono::NaiveDate::MIN
|
||||||
|
.and_hms_opt(0, 0, 0)
|
||||||
|
.unwrap()
|
||||||
|
.timestamp()
|
||||||
{
|
{
|
||||||
return Err(ser::Error::CorruptedData);
|
return Err(ser::Error::CorruptedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ts = NaiveDateTime::from_timestamp_opt(timestamp, 0);
|
||||||
|
if ts.is_none() {
|
||||||
|
return Err(ser::Error::CorruptedData);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(BlockHeader {
|
Ok(BlockHeader {
|
||||||
version,
|
version,
|
||||||
height,
|
height,
|
||||||
timestamp: DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(timestamp, 0), Utc),
|
timestamp: DateTime::<Utc>::from_utc(ts.unwrap(), Utc),
|
||||||
prev_hash,
|
prev_hash,
|
||||||
prev_root,
|
prev_root,
|
||||||
output_root,
|
output_root,
|
||||||
|
@ -645,8 +661,13 @@ impl Block {
|
||||||
let version = consensus::header_version(height);
|
let version = consensus::header_version(height);
|
||||||
|
|
||||||
let now = Utc::now().timestamp();
|
let now = Utc::now().timestamp();
|
||||||
let timestamp = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(now, 0), Utc);
|
|
||||||
|
|
||||||
|
let ts = NaiveDateTime::from_timestamp_opt(now, 0);
|
||||||
|
if ts.is_none() {
|
||||||
|
return Err(Error::Other("Converting Utc::now() into timestamp".into()));
|
||||||
|
}
|
||||||
|
|
||||||
|
let timestamp = DateTime::<Utc>::from_utc(ts.unwrap(), Utc);
|
||||||
// Now build the block with all the above information.
|
// Now build the block with all the above information.
|
||||||
// Note: We have not validated the block here.
|
// Note: We have not validated the block here.
|
||||||
// Caller must validate the block as necessary.
|
// Caller must validate the block as necessary.
|
||||||
|
|
|
@ -34,7 +34,7 @@ use util::secp::Signature;
|
||||||
pub fn genesis_dev() -> core::Block {
|
pub fn genesis_dev() -> core::Block {
|
||||||
core::Block::with_header(core::BlockHeader {
|
core::Block::with_header(core::BlockHeader {
|
||||||
height: 0,
|
height: 0,
|
||||||
timestamp: Utc.ymd(1997, 8, 4).and_hms(0, 0, 0),
|
timestamp: Utc.with_ymd_and_hms(1997, 8, 4, 0, 0, 0).unwrap(),
|
||||||
pow: ProofOfWork {
|
pow: ProofOfWork {
|
||||||
nonce: 0,
|
nonce: 0,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -48,7 +48,7 @@ pub fn genesis_dev() -> core::Block {
|
||||||
pub fn genesis_test() -> core::Block {
|
pub fn genesis_test() -> core::Block {
|
||||||
let gen = core::Block::with_header(core::BlockHeader {
|
let gen = core::Block::with_header(core::BlockHeader {
|
||||||
height: 0,
|
height: 0,
|
||||||
timestamp: Utc.ymd(2018, 12, 28).and_hms(20, 48, 4),
|
timestamp: Utc.with_ymd_and_hms(2018, 12, 28, 20, 48, 4).unwrap(),
|
||||||
prev_root: Hash::from_hex(
|
prev_root: Hash::from_hex(
|
||||||
"00000000000000000017ff4903ef366c8f62e3151ba74e41b8332a126542f538",
|
"00000000000000000017ff4903ef366c8f62e3151ba74e41b8332a126542f538",
|
||||||
)
|
)
|
||||||
|
@ -161,7 +161,7 @@ pub fn genesis_test() -> core::Block {
|
||||||
pub fn genesis_main() -> core::Block {
|
pub fn genesis_main() -> core::Block {
|
||||||
let gen = core::Block::with_header(core::BlockHeader {
|
let gen = core::Block::with_header(core::BlockHeader {
|
||||||
height: 0,
|
height: 0,
|
||||||
timestamp: Utc.ymd(2019, 1, 15).and_hms(16, 1, 26),
|
timestamp: Utc.with_ymd_and_hms(2019, 1, 15, 16, 1, 26).unwrap(),
|
||||||
prev_root: Hash::from_hex(
|
prev_root: Hash::from_hex(
|
||||||
"0000000000000000002a8bc32f43277fe9c063b9c99ea252b483941dcd06e217",
|
"0000000000000000002a8bc32f43277fe9c063b9c99ea252b483941dcd06e217",
|
||||||
)
|
)
|
||||||
|
|
|
@ -115,7 +115,8 @@ pub fn pow_size(
|
||||||
// and if we're back where we started, update the time (changes the hash as
|
// and if we're back where we started, update the time (changes the hash as
|
||||||
// well)
|
// well)
|
||||||
if bh.pow.nonce == start_nonce {
|
if bh.pow.nonce == start_nonce {
|
||||||
bh.timestamp = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(0, 0), Utc);
|
bh.timestamp =
|
||||||
|
DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp_opt(0, 0).unwrap(), Utc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,7 +437,7 @@ impl Peers {
|
||||||
|
|
||||||
// Delete defunct peers from storage
|
// Delete defunct peers from storage
|
||||||
let _ = self.store.delete_peers(|peer| {
|
let _ = self.store.delete_peers(|peer| {
|
||||||
let diff = now - Utc.timestamp(peer.last_connected, 0);
|
let diff = now - Utc.timestamp_opt(peer.last_connected, 0).unwrap();
|
||||||
|
|
||||||
let should_remove = peer.flags == State::Defunct
|
let should_remove = peer.flags == State::Defunct
|
||||||
&& diff > Duration::seconds(global::PEER_EXPIRATION_REMOVE_TIME);
|
&& diff > Duration::seconds(global::PEER_EXPIRATION_REMOVE_TIME);
|
||||||
|
|
|
@ -69,8 +69,9 @@ pub fn connect_and_monitor(
|
||||||
// check seeds first
|
// check seeds first
|
||||||
connect_to_seeds_and_peers(peers.clone(), tx.clone(), seed_list, config);
|
connect_to_seeds_and_peers(peers.clone(), tx.clone(), seed_list, config);
|
||||||
|
|
||||||
let mut prev = chrono::Date::<Utc>::MIN_UTC.and_hms(0, 0, 0);
|
let mut prev = DateTime::<Utc>::MIN_UTC;
|
||||||
let mut prev_expire_check = chrono::Date::<Utc>::MIN_UTC.and_hms(0, 0, 0);
|
let mut prev_expire_check = DateTime::<Utc>::MIN_UTC;
|
||||||
|
|
||||||
let mut prev_ping = Utc::now();
|
let mut prev_ping = Utc::now();
|
||||||
let mut start_attempt = 0;
|
let mut start_attempt = 0;
|
||||||
let mut connecting_history: HashMap<PeerAddr, DateTime<Utc>> = HashMap::new();
|
let mut connecting_history: HashMap<PeerAddr, DateTime<Utc>> = HashMap::new();
|
||||||
|
|
|
@ -168,7 +168,11 @@ fn build_block(
|
||||||
|
|
||||||
b.header.pow.nonce = thread_rng().gen();
|
b.header.pow.nonce = thread_rng().gen();
|
||||||
b.header.pow.secondary_scaling = difficulty.secondary_scaling;
|
b.header.pow.secondary_scaling = difficulty.secondary_scaling;
|
||||||
b.header.timestamp = DateTime::<Utc>::from_utc(NaiveDateTime::from_timestamp(now_sec, 0), Utc);
|
let ts = NaiveDateTime::from_timestamp_opt(now_sec, 0);
|
||||||
|
if ts.is_none() {
|
||||||
|
return Err(Error::General("Utc::now into timestamp".into()));
|
||||||
|
}
|
||||||
|
b.header.timestamp = DateTime::<Utc>::from_utc(ts.unwrap(), Utc);
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Built new block with {} inputs and {} outputs, block difficulty: {}, cumulative difficulty {}",
|
"Built new block with {} inputs and {} outputs, block difficulty: {}, cumulative difficulty {}",
|
||||||
|
|
|
@ -64,13 +64,14 @@ impl StratumWorkerColumn {
|
||||||
|
|
||||||
impl TableViewItem<StratumWorkerColumn> for WorkerStats {
|
impl TableViewItem<StratumWorkerColumn> for WorkerStats {
|
||||||
fn to_column(&self, column: StratumWorkerColumn) -> String {
|
fn to_column(&self, column: StratumWorkerColumn) -> String {
|
||||||
let naive_datetime = NaiveDateTime::from_timestamp(
|
let naive_datetime = NaiveDateTime::from_timestamp_opt(
|
||||||
self.last_seen
|
self.last_seen
|
||||||
.duration_since(time::UNIX_EPOCH)
|
.duration_since(time::UNIX_EPOCH)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_secs() as i64,
|
.as_secs() as i64,
|
||||||
0,
|
0,
|
||||||
);
|
)
|
||||||
|
.unwrap_or_default();
|
||||||
let datetime: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);
|
let datetime: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);
|
||||||
|
|
||||||
match column {
|
match column {
|
||||||
|
@ -126,7 +127,8 @@ impl DiffColumn {
|
||||||
|
|
||||||
impl TableViewItem<DiffColumn> for DiffBlock {
|
impl TableViewItem<DiffColumn> for DiffBlock {
|
||||||
fn to_column(&self, column: DiffColumn) -> String {
|
fn to_column(&self, column: DiffColumn) -> String {
|
||||||
let naive_datetime = NaiveDateTime::from_timestamp(self.time as i64, 0);
|
let naive_datetime =
|
||||||
|
NaiveDateTime::from_timestamp_opt(self.time as i64, 0).unwrap_or_default();
|
||||||
let datetime: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);
|
let datetime: DateTime<Utc> = DateTime::from_utc(naive_datetime, Utc);
|
||||||
|
|
||||||
match column {
|
match column {
|
||||||
|
|
Loading…
Reference in a new issue