Skip to content

Commit

Permalink
Improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
scx1332 authored Nov 30, 2023
1 parent 241da5a commit 13be5e0
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 21 deletions.
19 changes: 13 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ futures = "0.3"
lazy_static = "1.4"
log = "0.4"
metrics = "0.12"
num_cpus = "1"
openssl = "0.10"
openssl-probe = { version = "0.1", optional = true }
serde = "1.0"
Expand Down Expand Up @@ -229,9 +230,9 @@ members = [
# diesel 1.4.* supports up to 0.23.0, but sqlx 0.5.9 requires 0.22.0
# sqlx 0.5.10 need 0.23.2, so 0.5.9 is last version possible
libsqlite3-sys = { version = "0.26.0", features = ["bundled"] }
erc20_payment_lib = { version = "0.3.2", git = "https://github.com/golemfactory/erc20_payment_lib", rev = "968a45e8852f065db0b4c27d7314d171da6ebcb2" }
#erc20_payment_lib = { version = "0.3.2", git = "https://github.com/golemfactory/erc20_payment_lib", rev = "2fb9949b43ccedf0dfad61926d567debd2d6086f" }
#erc20_payment_lib = { path = "../../payments/erc20_payment_lib/crates/erc20_payment_lib" }
#erc20_payment_lib = { version = "=0.3.11" }
erc20_payment_lib = { version = "=0.3.13" }
rand = "0.8.5"
url = "2.3.1"
trust-dns-resolver = "0.22"
Expand Down
13 changes: 13 additions & 0 deletions core/model/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ pub struct PaymentDetails {
pub date: Option<DateTime<Utc>>,
}

impl Display for PaymentDetails {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"({{recipient: {}, sender: {}, amount: {}, date: {}}})",
self.recipient,
self.sender,
self.amount,
self.date.unwrap_or_default()
)
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PaymentConfirmation {
pub confirmation: Vec<u8>,
Expand Down
14 changes: 7 additions & 7 deletions core/payment-driver/erc20next/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl Erc20NextDriver {
token_transfer: &TokenTransferDao,
tx: &TxDao,
) -> Result<(), GenericError> {
log::info!("Received event TransferFinished: {:#?}", token_transfer);
log::debug!("Received event TransferFinished: {:#?}", token_transfer);

let chain_id = token_transfer.chain_id;
let network_name = &self
Expand Down Expand Up @@ -312,11 +312,11 @@ impl Erc20NextDriver {
GenericError::new(format!("Malformed tx.tx_hash: {:?} {err}", tx_hash))
})?;

log::info!("name = {}", &self.get_name());
log::info!("platform = {}", platform);
log::info!("order_id = {}", token_transfer.payment_id.as_ref().unwrap());
log::info!("payment_details = {:#?}", payment_details);
log::info!("confirmation = {:x?}", transaction_hash);
log::info!("name: {}", &self.get_name());
log::info!("platform: {}", platform);
log::info!("order_id: {}", token_transfer.payment_id.as_ref().unwrap());
log::info!("payment_details: {}", payment_details);
log::info!("confirmation: 0x{}", hex::encode(&transaction_hash));

let Some(payment_id) = &token_transfer.payment_id else {
return Err(GenericError::new("token_transfer.payment_id is null"));
Expand Down Expand Up @@ -850,7 +850,7 @@ impl PaymentDriver for Erc20NextDriver {
caller: String,
msg: ValidateAllocation,
) -> Result<bool, GenericError> {
log::info!("Validate_allocation: {:?}", msg);
log::debug!("Validate_allocation: {:?}", msg);
let account_balance = self
.get_account_balance(
db,
Expand Down
6 changes: 4 additions & 2 deletions core/payment-driver/erc20next/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,17 @@ impl Erc20NextService {
chain.rpc_endpoints = addr
.split(',')
.map(|s| RpcSettings {
name: s.to_string(),
endpoint: s.to_string(),
names: Some(s.to_string()),
endpoints: Some(s.to_string()),
skip_validation: None,
backup_level: None,
verify_interval_secs: None,
min_interval_ms: None,
max_timeout_ms: None,
allowed_head_behind_secs: None,
max_consecutive_errors: None,
dns_source: None,
json_source: None,
})
.collect();
log::info!(
Expand Down
6 changes: 5 additions & 1 deletion core/payment-driver/erc20next/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,11 @@ impl web3::signing::Key for DummyKey {
s: Default::default(),
})
} else {
eprintln!("({}) {:?}", state.signed.len(), &state.signed);
log::debug!(
"Signed message: ({}) {:?}",
state.signed.len(),
&state.signed
);
Ok(Signature {
v: state.signed[0] as u64,
r: H256::from_slice(&state.signed[1..33]),
Expand Down
4 changes: 3 additions & 1 deletion core/payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ impl PaymentService {
}

pub async fn shut_down() {
log::info!("Stopping payment service... It may take up to 10 seconds to send out all transactions. Hit Ctrl+C again to interrupt and shut down immediately.");
log::info!(
"Stopping payment service... Hit Ctrl+C again to interrupt and shut down immediately."
);

let timeout = tokio::time::timeout(
*PAYMENT_SHUTDOWN_TIMEOUT,
Expand Down
1 change: 0 additions & 1 deletion core/payment/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ impl PaymentProcessor {
.send(driver::SignPayment(payment.clone()))
.await??;

log::warn!("####### payment: {:?}, signature {:?}", payment, signature);
counter!("payment.amount.sent", ya_metrics::utils::cryptocurrency_to_u64(&msg.amount), "platform" => payment_platform);
// This is unconditional because at this point the invoice *has been paid*.
// Whether the provider was correctly notified of this fact is another matter.
Expand Down
18 changes: 17 additions & 1 deletion core/serv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use metrics::gauge;
#[cfg(feature = "static-openssl")]
extern crate openssl_probe;

use std::sync::Arc;
use std::{
any::TypeId,
collections::HashMap,
Expand Down Expand Up @@ -566,6 +567,12 @@ impl ServiceCommand {
ya_net::hybrid::send_bcast_new_neighbour().await
});

let number_of_workers = env::var("YAGNA_HTTP_WORKERS")
.ok()
.and_then(|x| x.parse().ok())
.unwrap_or_else(num_cpus::get)
.clamp(1, 256);
let count_started = Arc::new(std::sync::atomic::AtomicUsize::new(0));
let server = HttpServer::new(move || {
let app = App::new()
.wrap(middleware::Logger::default())
Expand All @@ -574,9 +581,18 @@ impl ServiceCommand {
.route("/me", web::get().to(me))
.service(forward_gsb);
let rest = Services::rest(app, &context);
log::info!("Http server thread started on: {}", rest_address);
if count_started.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
== number_of_workers - 1
{
log::info!(
"All {} http workers started - listening on {}",
number_of_workers,
rest_address
);
}
rest
})
.workers(number_of_workers)
// this is maximum supported timeout for our REST API
.keep_alive(std::time::Duration::from_secs(*max_rest_timeout))
.bind(api_host_port.clone())
Expand Down

0 comments on commit 13be5e0

Please sign in to comment.