Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade pgp and chrono #6721

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,705 changes: 1,620 additions & 1,085 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion applications/minotari_app_grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tari_utilities = { version = "0.8" }
argon2 = { version = "0.4.1", features = ["std", "password-hash"] }
base64 = "0.13.0"
borsh = "1.5"
chrono = { version = "0.4.19", default-features = false }
chrono = { version = "0.4.39", default-features = false }
log = "0.4"
prost = "0.13.3"
prost-types = "0.13.3"
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_app_grpc/src/conversions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use crate::{tari_rpc as grpc, tari_rpc::BlockGroupRequest};
/// Utility function that converts a `chrono::NaiveDateTime` to a `prost::Timestamp`
pub fn naive_datetime_to_timestamp(datetime: chrono::NaiveDateTime) -> Timestamp {
Timestamp {
seconds: datetime.timestamp(),
seconds: datetime.and_utc().timestamp(),
nanos: 0,
}
}
Expand Down
12 changes: 9 additions & 3 deletions applications/minotari_app_grpc/src/conversions/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,21 @@ impl From<Peer> for grpc::Peer {
let last_connection = peer
.addresses
.last_seen()
.map(|f| f.timestamp() as u64)
.map(|f| f.and_utc().timestamp() as u64)
.unwrap_or_default();
for address in peer.addresses.addresses() {
addresses.push(address.clone().into())
}
let flags = u32::from(peer.flags.bits());
let banned_until = peer.banned_until.map(|f| f.timestamp() as u64).unwrap_or_default();
let banned_until = peer
.banned_until
.map(|f| f.and_utc().timestamp() as u64)
.unwrap_or_default();
let banned_reason = peer.banned_reason.to_string();
let offline_at = peer.offline_at().map(|f| f.timestamp() as u64).unwrap_or_default();
let offline_at = peer
.offline_at()
.map(|f| f.and_utc().timestamp() as u64)
.unwrap_or_default();
let features = peer.features.bits();

let supported_protocols = peer.supported_protocols.into_iter().map(|p| p.to_vec()).collect();
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ console-subscriber = "0.1.8"
tokio = { version = "1.36", features = ["signal"] }

blake2 = "0.10"
chrono = { version = "0.4.19", default-features = false }
chrono = { version = "0.4.39", default-features = false }
clap = { version = "3.2", features = ["derive", "env"] }
config = "0.14.0"
crossterm = { version = "0.25.0" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<B: Backend> Component<B> for BaseNode {
)
};

let updated = base_node_state.updated.unwrap_or(Utc::now().naive_utc());
let updated = base_node_state.updated.unwrap_or(Utc::now());

let latency = base_node_state.latency.unwrap_or_default().as_millis();
let latency_color = match latency {
Expand All @@ -112,7 +112,7 @@ impl<B: Backend> Component<B> for BaseNode {
Span::raw(" "),
];

let mut latency_span = if Utc::now().naive_utc().timestamp() - updated.timestamp() > 15 * 60 {
let mut latency_span = if Utc::now().timestamp() - updated.timestamp() > 15 * 60 {
vec![
Span::styled("Last updated", Style::default().fg(Color::Red)),
Span::raw(" "),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1234,8 +1234,8 @@ impl CompletedTransactionInfo {
.unwrap_or(0),
status: tx.status,
message: tx.message,
timestamp: tx.timestamp,
mined_timestamp: tx.mined_timestamp,
timestamp: tx.timestamp.naive_utc(),
mined_timestamp: tx.mined_timestamp.map(|t| t.naive_utc()),
cancelled: tx.cancelled,
direction: tx.direction,
mined_height: tx.mined_height,
Expand Down
4 changes: 1 addition & 3 deletions applications/minotari_console_wallet/src/ui/ui_contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ impl From<Contact> for UiContact {
address: c.address.to_base58(),
emoji_id: c.address.to_emoji_string(),
last_seen: match c.last_seen {
Some(val) => DateTime::<Local>::from_naive_utc_and_offset(val, Local::now().offset().to_owned())
.format("%m-%dT%H:%M")
.to_string(),
Some(val) => DateTime::<Local>::from(val).format("%m-%dT%H:%M").to_string(),
None => "".to_string(),
},
online_status: "".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions applications/minotari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ anyhow = "1.0.53"
bincode = "1.3.1"
borsh = "1.5"
bytes = "1.1"
chrono = { version = "0.4.19", default-features = false }
chrono = { version = "0.4.39", default-features = false }
clap = { version = "3.2", features = ["derive", "env"] }
config = { version = "0.14.0" }
crossterm = { version = "0.25.0" }
Expand All @@ -42,7 +42,7 @@ hex = "0.4.2"
hyper = { version ="0.14.12", features = ["default"] }
jsonrpc = "0.12.0"
log = { version = "0.4.8", features = ["std"] }
markup5ever = "0.11.0"
markup5ever = "0.12.1"
monero = { version = "0.21.0" }
reqwest = { version = "0.11.4", features = ["json"] }
serde = { version = "1.0.136", features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions applications/minotari_miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tari_utilities = { version = "0.8" }
base64 = "0.13.0"
borsh = "1.5"
bufstream = "0.1"
chrono = { version = "0.4.19", default-features = false }
chrono = { version = "0.4.39", default-features = false }
clap = { version = "3.2", features = ["derive"] }
crossbeam = "0.8"
crossterm = { version = "0.25.0" }
Expand Down Expand Up @@ -54,7 +54,7 @@ tonic = { version = "0.12.3", features = ["tls", "tls-roots"] }

[dev-dependencies]
prost-types = "0.13.3"
chrono = { version = "0.4.19", default-features = false }
chrono = { version = "0.4.39", default-features = false }
config = "0.14.0"

[package.metadata.cargo-machete]
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ anyhow = "1.0.53"
async-trait = "0.1.52"
bincode = "1.3.1"
borsh = "1.5"
chrono = { version = "0.4.19", default-features = false }
chrono = { version = "0.4.39", default-features = false }
clap = { version = "3.2", features = ["derive", "env"] }
console-subscriber = "0.1.8"
config = { version = "0.14.0" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::{cmp, convert::TryFrom, io::Write};

use anyhow::Error;
use async_trait::async_trait;
use chrono::{NaiveDateTime, Utc};
use chrono::Utc;
use clap::Parser;
use tari_core::proof_of_work::{lwma_diff::LinearWeightedMovingAverage, PowAlgorithm};
use tari_utilities::hex::Hex;
Expand Down Expand Up @@ -140,10 +140,8 @@ impl CommandContext {
solve_time,
normalized_solve_time,
pow_algo,
chrono::DateTime::<Utc>::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(header.header().timestamp.as_u64() as i64, 0).unwrap_or_default(),
Utc
),
chrono::DateTime::<Utc>::from_timestamp(header.header().timestamp.as_u64() as i64, 0)
.unwrap_or_default(),
target_diff.get(pow_algo).len(),
acc_monero,
acc_sha3,
Expand Down
8 changes: 3 additions & 5 deletions applications/minotari_node/src/commands/command/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::time::{Duration, Instant};

use anyhow::{anyhow, Error};
use async_trait::async_trait;
use chrono::{DateTime, NaiveDateTime, Utc};
use chrono::{DateTime, Utc};
use clap::Parser;
use minotari_app_utilities::consts;
use tari_comms::connection_manager::SelfLivenessStatus;
Expand Down Expand Up @@ -70,10 +70,8 @@ impl CommandContext {
.get_header(height)
.await?
.ok_or_else(|| anyhow!("No last header"))?;
let last_block_time = DateTime::<Utc>::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(last_header.header().timestamp.as_u64() as i64, 0).unwrap_or_default(),
Utc,
);
let last_block_time =
DateTime::<Utc>::from_timestamp(last_header.header().timestamp.as_u64() as i64, 0).unwrap_or_default();
status_line.add_field(
"Tip",
format!("{} ({})", metadata.best_block_height(), last_block_time.to_rfc2822()),
Expand Down
2 changes: 1 addition & 1 deletion base_layer/chat_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ openssl = { version = "0.10.66", features = ["vendored"] }
crate-type = ["staticlib", "cdylib"]

[dev-dependencies]
chrono = { version = "0.4.19", default-features = false }
chrono = { version = "0.4.39", default-features = false }
rand = "0.8"
tari_crypto = { version = "0.21.0" }

Expand Down
4 changes: 2 additions & 2 deletions base_layer/chat_ffi/src/contacts_liveness_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub unsafe extern "C" fn destroy_contacts_liveness_data(ptr: *mut ContactsLivene

#[cfg(test)]
mod test {
use chrono::NaiveDateTime;
use chrono::DateTime;
use tari_contacts::contacts_service::service::{ContactMessageType, ContactOnlineStatus};
use tari_utilities::epoch_time::EpochTime;

Expand Down Expand Up @@ -242,7 +242,7 @@ mod test {
Default::default(),
Default::default(),
None,
NaiveDateTime::from_timestamp_opt(i64::try_from(timestamp).unwrap(), 0),
DateTime::from_timestamp(i64::try_from(timestamp).unwrap(), 0),
ContactMessageType::Ping,
ContactOnlineStatus::Online,
);
Expand Down
2 changes: 1 addition & 1 deletion base_layer/contacts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tari_service_framework = { path = "../service_framework", version = "1.9.1-pre.0
tari_shutdown = { path = "../../infrastructure/shutdown", version = "1.9.1-pre.0" }
tari_utilities = { version = "0.8" }

chrono = { version = "0.4.19", default-features = false, features = ["serde"] }
chrono = { version = "0.4.39", default-features = false, features = ["serde"] }
diesel = { version = "2.2.4", features = [
"sqlite",
"serde_json",
Expand Down
12 changes: 5 additions & 7 deletions base_layer/contacts/src/contacts_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{
sync::Arc,
};

use chrono::{DateTime, Local, NaiveDateTime};
use chrono::{DateTime, Local, Utc};
use tari_common_types::tari_address::TariAddress;
use tari_comms::peer_manager::NodeId;
use tari_service_framework::reply_channel::SenderService;
Expand All @@ -49,7 +49,7 @@ pub struct ContactsLivenessData {
address: TariAddress,
node_id: NodeId,
latency: Option<u32>,
last_seen: Option<NaiveDateTime>,
last_seen: Option<DateTime<Utc>>,
message_type: ContactMessageType,
online_status: ContactOnlineStatus,
}
Expand All @@ -59,7 +59,7 @@ impl ContactsLivenessData {
address: TariAddress,
node_id: NodeId,
latency: Option<u32>,
last_seen: Option<NaiveDateTime>,
last_seen: Option<DateTime<Utc>>,
message_type: ContactMessageType,
online_status: ContactOnlineStatus,
) -> Self {
Expand All @@ -85,7 +85,7 @@ impl ContactsLivenessData {
self.latency
}

pub fn last_ping_pong_received(&self) -> Option<NaiveDateTime> {
pub fn last_ping_pong_received(&self) -> Option<DateTime<Utc>> {
self.last_seen
}

Expand All @@ -111,9 +111,7 @@ impl Display for ContactsLivenessData {
self.address,
self.node_id,
if let Some(time) = self.last_seen {
let local_time = DateTime::<Local>::from_naive_utc_and_offset(time, Local::now().offset().to_owned())
.format("%FT%T")
.to_string();
let local_time = DateTime::<Local>::from(time).format("%FT%T").to_string();
format!("last seen {} is '{}'", local_time, self.online_status)
} else {
" - contact was never seen".to_string()
Expand Down
16 changes: 7 additions & 9 deletions base_layer/contacts/src/contacts_service/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use std::{
time::Duration,
};

use chrono::{NaiveDateTime, Utc};
use chrono::{DateTime, Utc};
use futures::{pin_mut, StreamExt};
use log::*;
use tari_common_types::tari_address::TariAddress;
Expand Down Expand Up @@ -298,10 +298,10 @@ where T: ContactsBackend + 'static
Ok(result.map(ContactsServiceResponse::Messages)?)
},
ContactsServiceRequest::SendMessage(address, mut message) => {
message.sent_at = Utc::now().naive_utc().timestamp() as u64;
message.sent_at = Utc::now().timestamp() as u64;
let ob_message = OutboundDomainMessage::from(MessageDispatch::Message(message.clone()));

message.stored_at = Utc::now().naive_utc().timestamp() as u64;
message.stored_at = Utc::now().timestamp() as u64;
match self.db.save_message(message) {
Ok(_) => {
if let Err(e) = self.deliver_message(address.clone(), ob_message).await {
Expand Down Expand Up @@ -481,12 +481,12 @@ where T: ContactsBackend + 'static
Ok(online_status)
}

fn is_online(&self, last_seen: NaiveDateTime) -> bool {
fn is_online(&self, last_seen: DateTime<Utc>) -> bool {
#[allow(clippy::cast_possible_wrap)]
let ping_window = chrono::Duration::seconds(
(self.contacts_online_ping_window as u64 * self.contacts_auto_ping_interval.as_secs()) as i64,
);
Utc::now().naive_utc().sub(last_seen) <= ping_window
Utc::now().sub(last_seen) <= ping_window
}

fn update_with_ping_pong(
Expand All @@ -513,15 +513,13 @@ where T: ContactsBackend + 'static
.latency
.map(|val| u32::try_from(val.as_millis()).unwrap_or(u32::MAX));
}
let this_public_key = self
.db
.update_contact_last_seen(&event.node_id, last_seen.naive_utc(), latency)?;
let this_public_key = self.db.update_contact_last_seen(&event.node_id, last_seen, latency)?;

let data = ContactsLivenessData::new(
this_public_key,
event.node_id.clone(),
latency,
Some(last_seen.naive_utc()),
Some(last_seen),
message_type,
ContactOnlineStatus::Online,
);
Expand Down
14 changes: 6 additions & 8 deletions base_layer/contacts/src/contacts_service/storage/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{
sync::Arc,
};

use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use log::*;
use tari_common_types::tari_address::TariAddress;
use tari_comms::peer_manager::NodeId;
Expand Down Expand Up @@ -69,8 +69,8 @@ pub enum DbValue {
#[allow(clippy::large_enum_variant)]
pub enum DbKeyValuePair {
Contact(TariAddress, Contact),
MessageConfirmations(Vec<u8>, Option<NaiveDateTime>, Option<NaiveDateTime>),
LastSeen(NodeId, NaiveDateTime, Option<i32>),
MessageConfirmations(Vec<u8>, Option<DateTime<Utc>>, Option<DateTime<Utc>>),
LastSeen(NodeId, DateTime<Utc>, Option<i32>),
}

pub enum WriteOperation {
Expand Down Expand Up @@ -137,7 +137,7 @@ where T: ContactsBackend + 'static
pub fn update_contact_last_seen(
&self,
node_id: &NodeId,
last_seen: NaiveDateTime,
last_seen: DateTime<Utc>,
latency: Option<u32>,
) -> Result<TariAddress, ContactsServiceStorageError> {
let result = self
Expand Down Expand Up @@ -210,17 +210,15 @@ where T: ContactsBackend + 'static
if let Some(timestamp) = delivery_confirmation {
let secs = i64::try_from(timestamp).map_err(|_e| ContactsServiceStorageError::ConversionError)?;
delivery = Some(
NaiveDateTime::from_timestamp_opt(secs, 0)
.ok_or_else(|| ContactsServiceStorageError::ConversionError)?,
DateTime::<Utc>::from_timestamp(secs, 0).ok_or_else(|| ContactsServiceStorageError::ConversionError)?,
)
};

let mut read = None;
if let Some(timestamp) = read_confirmation {
let secs = i64::try_from(timestamp).map_err(|_e| ContactsServiceStorageError::ConversionError)?;
read = Some(
NaiveDateTime::from_timestamp_opt(secs, 0)
.ok_or_else(|| ContactsServiceStorageError::ConversionError)?,
DateTime::<Utc>::from_timestamp(secs, 0).ok_or_else(|| ContactsServiceStorageError::ConversionError)?,
)
};

Expand Down
6 changes: 3 additions & 3 deletions base_layer/contacts/src/contacts_service/storage/sqlite_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ where TContactServiceDbConnection: PooledDbConnection<Error = SqliteStorageError
WriteOperation::Upsert(kvp) => match *kvp {
DbKeyValuePair::MessageConfirmations(k, d, r) => {
if MessagesSql::find_by_message_id_and_update(&mut conn, &k, MessageUpdate {
delivery_confirmation_at: d,
read_confirmation_at: r,
delivery_confirmation_at: d.map(|d| d.naive_utc()),
read_confirmation_at: r.map(|r| r.naive_utc()),
})
.is_err()
{
Expand Down Expand Up @@ -181,7 +181,7 @@ where TContactServiceDbConnection: PooledDbConnection<Error = SqliteStorageError
let contact =
ContactSql::find_by_node_id_and_update(&mut conn, &node_id.to_vec(), UpdateContact {
alias: None,
last_seen: Some(Some(date_time)),
last_seen: Some(Some(date_time.naive_utc())),
latency: Some(latency),
favourite: None,
})?;
Expand Down
Loading
Loading