Change some logs from trace to debug in the codebase.

This commit is contained in:
parazyd
2022-01-07 15:20:26 +01:00
parent 4e2c7f677f
commit dc79fe325c
7 changed files with 78 additions and 81 deletions

View File

@@ -1,6 +1,6 @@
use std::sync::Arc;
use log::trace;
use log::debug;
use super::{
rocks::{columns, IteratorMode, RocksColumn},
@@ -21,14 +21,14 @@ impl SlabStore {
}
pub fn get(&self, key: Vec<u8>) -> Result<Option<Vec<u8>>> {
trace!(target: "SLABSTORE", "get value");
debug!(target: "SLABSTORE", "get value");
let key: u64 = deserialize(&key)?;
let value = self.rocks.get(key)?;
Ok(value)
}
pub fn put(&self, slab: Slab) -> Result<Option<u64>> {
trace!(target: "SLABSTORE", "Put slab");
debug!(target: "SLABSTORE", "Put slab");
let last_index = self.get_last_index()?;
let key = last_index + 1;
@@ -45,7 +45,7 @@ impl SlabStore {
}
pub fn get_last_index(&self) -> Result<u64> {
trace!(target: "SLABSTORE", "Get last index");
debug!(target: "SLABSTORE", "Get last index");
let last_index = self.rocks.iterator(IteratorMode::End)?.next();
match last_index {
Some((index, _)) => Ok(deserialize(&index)?),
@@ -54,7 +54,7 @@ impl SlabStore {
}
pub fn get_last_index_as_bytes(&self) -> Result<Vec<u8>> {
trace!(target: "SLABSTORE", "Get last index as bytes");
debug!(target: "SLABSTORE", "Get last index as bytes");
let last_index = self.rocks.iterator(IteratorMode::End)?.next();
match last_index {
Some((index, _)) => Ok(index.to_vec()),

View File

@@ -111,9 +111,6 @@ pub struct CliGatewayd {
/// Increase verbosity
#[clap(short, parse(from_occurrences))]
pub verbose: u8,
/// Show event trace
#[clap(short, long)]
pub trace: bool,
}
/// Darkfid cli

View File

@@ -1,7 +1,7 @@
use async_std::sync::{Arc, Mutex};
use incrementalmerkletree::{bridgetree::BridgeTree, Tree};
use log::{debug, info, trace, warn};
use log::{debug, info, warn};
use smol::Executor;
use url::Url;
@@ -106,7 +106,7 @@ impl Client {
let main_keypair = wallet.get_default_keypair().await?;
info!("Main keypair: {}", Address::from(main_keypair.public).to_string());
trace!("Creating GatewayClient");
debug!("Creating GatewayClient");
let slabstore = RocksColumn::<columns::Slabs>::new(rocks);
let gateway = GatewayClient::new(gateway_addrs.0, gateway_addrs.1, slabstore)?;
@@ -132,7 +132,7 @@ impl Client {
clear_input: bool,
state: Arc<Mutex<State>>,
) -> ClientResult<Vec<Coin>> {
trace!("Begin building slab from tx");
debug!("Begin building slab from tx");
let mut clear_inputs: Vec<tx::TransactionBuilderClearInputInfo> = vec![];
let mut inputs: Vec<tx::TransactionBuilderInputInfo> = vec![];
let mut outputs: Vec<tx::TransactionBuilderOutputInfo> = vec![];
@@ -144,7 +144,7 @@ impl Client {
let input = tx::TransactionBuilderClearInputInfo { value, token_id, signature_secret };
clear_inputs.push(input);
} else {
trace!("Start building tx inputs");
debug!("Start building tx inputs");
let mut inputs_value = 0_u64;
let state_m = state.lock().await;
let own_coins = self.wallet.get_own_coins().await?;
@@ -185,7 +185,7 @@ impl Client {
});
}
trace!("Finish building inputs");
debug!("Finish building inputs");
}
outputs.push(tx::TransactionBuilderOutputInfo { value, token_id, public: pubkey });
@@ -198,15 +198,15 @@ impl Client {
tx.encode(&mut tx_data).expect("encode tx");
let slab = Slab::new(tx_data);
trace!("Finish building slab from tx");
debug!("Finish building slab from tx");
// Check if it's valid before sending to gateway
let state = &*state.lock().await;
state_transition(state, tx)?;
trace!("Sending slab to gateway");
debug!("Sending slab to gateway");
self.gateway.put_slab(slab).await?;
trace!("Slab sent to gateway successfully");
debug!("Slab sent to gateway successfully");
Ok(coins)
}
@@ -261,31 +261,31 @@ impl Client {
wallet: WalletPtr,
notify: Option<async_channel::Sender<(PublicKey, u64)>>,
) -> Result<()> {
trace!("Building tx from slab and updating the state");
debug!("Building tx from slab and updating the state");
let payload = slab.get_payload();
/*
use std::io::Write;
let mut file = std::fs::File::create("/tmp/payload.txt")?;
file.write_all(&payload)?;
*/
trace!("Decoding payload");
debug!("Decoding payload");
let tx = tx::Transaction::decode(&payload[..])?;
let update: StateUpdate;
// This is separate because otherwise the mutex is never unlocked.
{
trace!("Acquiring state lock");
debug!("Acquiring state lock");
let state = &*state.lock().await;
update = state_transition(state, tx)?;
trace!("Successfully passed state_transition");
debug!("Successfully passed state_transition");
}
trace!("Acquiring state lock");
debug!("Acquiring state lock");
let mut state = state.lock().await;
trace!("Trying to apply the new state");
debug!("Trying to apply the new state");
state.apply(update, secret_keys, notify, wallet).await?;
trace!("Successfully passed state.apply");
debug!("Successfully passed state.apply");
Ok(())
}
@@ -297,7 +297,7 @@ impl Client {
notify: async_channel::Sender<(PublicKey, u64)>,
executor: Arc<Executor<'_>>,
) -> Result<()> {
trace!("Start subscriber for cashier");
debug!("Start subscriber for cashier");
let gateway_slabs_sub = self.gateway.start_subscriber(executor.clone()).await?;
let secret_key = self.main_keypair.secret;
@@ -306,7 +306,7 @@ impl Client {
let task: smol::Task<Result<()>> = executor.spawn(async move {
loop {
let slab = gateway_slabs_sub.recv().await?;
trace!("Received new slab");
debug!("Received new slab");
let mut secret_keys = vec![secret_key];
let mut withdraw_keys = cashier_wallet.get_withdraw_private_keys().await?;
@@ -337,7 +337,7 @@ impl Client {
state: Arc<Mutex<State>>,
executor: Arc<Executor<'_>>,
) -> Result<()> {
trace!("Start subscriber for darkfid");
debug!("Start subscriber for darkfid");
let gateway_slabs_sub = self.gateway.start_subscriber(executor.clone()).await?;
let secret_key = self.main_keypair.secret;
@@ -346,7 +346,7 @@ impl Client {
let task: smol::Task<Result<()>> = executor.spawn(async move {
loop {
let slab = gateway_slabs_sub.recv().await?;
trace!("Received new slab");
debug!("Received new slab");
let update_state = Self::update_state(
vec![secret_key],

View File

@@ -4,7 +4,7 @@ use async_executor::Executor;
use async_std::sync::{Arc, Mutex};
use async_trait::async_trait;
use futures::stream::{FuturesUnordered, StreamExt};
use log::{error, trace};
use log::{debug, error};
use crate::{
crypto::keypair::PublicKey, types::*, util::NetworkName, wallet::cashierdb::TokenKey, Error,
@@ -76,7 +76,7 @@ impl Bridge {
network: NetworkName,
client: Arc<dyn NetworkClient + Send + Sync>,
) -> Result<()> {
trace!(target: "BRIDGE", "Adding new client");
debug!(target: "BRIDGE", "Adding new client");
let client2 = client.clone();
let notifier = client2.get_notifier().await?;
@@ -92,7 +92,7 @@ impl Bridge {
pub async fn listen(self: Arc<Self>) -> Option<Result<TokenNotification>> {
if !self.notifiers.is_empty() {
trace!(target: "BRIDGE", "Start listening for new notifications");
debug!(target: "BRIDGE", "Start listening for new notifications");
let notification = self
.notifiers
.iter()
@@ -102,7 +102,7 @@ impl Bridge {
.await
.map(|o| o.map_err(Error::from));
trace!(target: "BRIDGE", "Stop listening for new notifications");
debug!(target: "BRIDGE", "Stop listening for new notifications");
notification
} else {
@@ -116,7 +116,7 @@ impl Bridge {
mint: Option<String>,
executor: Arc<Executor<'_>>,
) -> BridgeSubscribtion {
trace!(target: "BRIDGE", "Start new subscription");
debug!(target: "BRIDGE", "Start new subscription");
let (sender, req) = async_channel::unbounded();
let (rep, receiver) = async_channel::unbounded();
@@ -135,7 +135,7 @@ impl Bridge {
mint: Option<String>,
executor: Arc<Executor<'_>>,
) -> Result<()> {
trace!(target: "BRIDGE", "Listen for new subscriptions");
debug!(target: "BRIDGE", "Listen for new subscriptions");
let req = req.recv().await?;
let network = req.network;

View File

@@ -5,7 +5,7 @@ use std::{
};
use async_executor::Executor;
use log::trace;
use log::debug;
use url::Url;
use super::reqrep::{PeerId, Publisher, RepProtocol, Reply, ReqProtocol, Request, Subscriber};
@@ -117,7 +117,7 @@ impl GatewayService {
let peer = msg.0;
match request.get_command() {
0 => {
trace!(target: "GATEWAY DAEMON" ,"Received putslab msg");
debug!(target: "GATEWAY DAEMON", "Received putslab msg");
// PUTSLAB
let slab = request.get_payload();
@@ -137,7 +137,7 @@ impl GatewayService {
publish_queue.send(slab).await?;
}
1 => {
trace!(target: "GATEWAY DAEMON", "Received getslab msg");
debug!(target: "GATEWAY DAEMON", "Received getslab msg");
let index = request.get_payload();
let slab = slabstore.get(index)?;
@@ -154,7 +154,7 @@ impl GatewayService {
// GETSLAB
}
2 => {
trace!(target: "GATEWAY DAEMON","Received getlastindex msg");
debug!(target: "GATEWAY DAEMON","Received getlastindex msg");
let index = slabstore.get_last_index_as_bytes()?;
let reply = Reply::from(&request, GatewayError::NoError as u32, index);
@@ -226,7 +226,7 @@ impl GatewayClient {
}
pub async fn sync(&mut self) -> Result<u64> {
trace!(target: "GATEWAY CLIENT", "Start Syncing");
debug!(target: "GATEWAY CLIENT", "Start Syncing");
let local_last_index = self.slabstore.get_last_index()?;
@@ -248,12 +248,12 @@ impl GatewayClient {
}
}
trace!(target: "GATEWAY CLIENT","End Syncing");
debug!(target: "GATEWAY CLIENT","End Syncing");
Ok(last_index)
}
pub async fn get_slab(&mut self, index: u64) -> Result<Option<Slab>> {
trace!(target: "GATEWAY CLIENT","Get slab");
debug!(target: "GATEWAY CLIENT","Get slab");
let handle_error = Arc::new(handle_error);
let rep = self
@@ -272,7 +272,7 @@ impl GatewayClient {
}
pub async fn put_slab(&mut self, mut slab: Slab) -> Result<()> {
trace!(target: "GATEWAY CLIENT","Put slab");
debug!(target: "GATEWAY CLIENT","Put slab");
loop {
let last_index = self.sync().await?;
@@ -294,7 +294,7 @@ impl GatewayClient {
}
pub async fn get_last_index(&mut self) -> Result<u64> {
trace!(target: "GATEWAY CLIENT","Get last index");
debug!(target: "GATEWAY CLIENT","Get last index");
let handle_error = Arc::new(handle_error);
@@ -314,7 +314,7 @@ impl GatewayClient {
&self,
executor: Arc<Executor<'_>>,
) -> Result<GatewaySlabsSubscriber> {
trace!(target: "GATEWAY CLIENT","Start subscriber");
debug!(target: "GATEWAY CLIENT", "Start subscriber");
let mut subscriber = Subscriber::new(self.sub_addr, String::from("GATEWAY CLIENT"));
subscriber.start().await?;
@@ -333,11 +333,11 @@ impl GatewayClient {
slabstore: Arc<SlabStore>,
gateway_slabs_sub_s: async_channel::Sender<Slab>,
) -> Result<()> {
trace!(target: "GATEWAY CLIENT","Start subscribe loop");
debug!(target: "GATEWAY CLIENT", "Start subscribe loop");
loop {
let slab = subscriber.fetch::<Slab>().await?;
trace!(target: "GATEWAY CLIENT","Received new slab");
debug!(target: "GATEWAY CLIENT", "Received new slab");
gateway_slabs_sub_s.send(slab.clone()).await?;
slabstore.put(slab)?;
}
@@ -351,10 +351,10 @@ impl GatewayClient {
fn handle_error(status_code: u32) {
match status_code {
1 => {
trace!(target: "GATEWAY SERVICE", "Reply has an Error: Index is not updated");
debug!(target: "GATEWAY SERVICE", "Reply has an Error: Index is not updated");
}
2 => {
trace!(target: "GATEWAY SERVICE", "Reply has an Error: Index Not Exist");
debug!(target: "GATEWAY SERVICE", "Reply has an Error: Index Not Exist");
}
_ => {}
}

View File

@@ -1,5 +1,5 @@
use incrementalmerkletree::{bridgetree::BridgeTree, Frontier, Tree};
use log::{debug, trace};
use log::{debug, error};
use crate::{
blockchain::{rocks::columns, RocksColumn},
@@ -66,18 +66,18 @@ impl From<error::Error> for VerifyFailed {
pub fn state_transition<S: ProgramState>(state: &S, tx: Transaction) -> VerifyResult<StateUpdate> {
// Check deposits are legit
trace!(target: "STATE TRANSITION", "iterate clear_inputs");
debug!(target: "STATE TRANSITION", "iterate clear_inputs");
for (i, input) in tx.clear_inputs.iter().enumerate() {
// Check the public key in the clear inputs
// It should be a valid public key for the cashier
if !state.is_valid_cashier_public_key(&input.signature_public) {
log::error!(target: "STATE TRANSITION", "Invalid cashier public key");
error!(target: "STATE TRANSITION", "Invalid cashier public key");
return Err(VerifyFailed::InvalidCashierKey(i))
}
}
trace!(target: "STATE TRANSITION", "iterate inputs");
debug!(target: "STATE TRANSITION", "iterate inputs");
for (i, input) in tx.inputs.iter().enumerate() {
let merkle = &input.revealed.merkle_root;
@@ -97,9 +97,9 @@ pub fn state_transition<S: ProgramState>(state: &S, tx: Transaction) -> VerifyRe
}
}
trace!(target: "STATE TRANSITION", "Check the tx verifies correctly");
debug!(target: "STATE TRANSITION", "Check the tx verifies correctly");
tx.verify(state.mint_vk(), state.spend_vk())?;
trace!(target: "STATE TRANSITION", "Verified successfully");
debug!(target: "STATE TRANSITION", "Verified successfully");
let mut nullifiers = vec![];
for input in tx.inputs {
@@ -143,12 +143,12 @@ impl State {
wallet: WalletPtr,
) -> Result<()> {
// Extend our list of nullifiers with the ones from the update.
trace!("Extend nullifiers");
debug!("Extend nullifiers");
for nullifier in update.nullifiers {
self.nullifiers.put(nullifier, vec![] as Vec<u8>)?;
}
trace!("Update Merkle tree and witness");
debug!("Update Merkle tree and witness");
for (coin, enc_note) in update.coins.into_iter().zip(update.enc_notes.iter()) {
// Add the new coins to the Merkle tree
let node = MerkleNode(coin.0);
@@ -169,7 +169,7 @@ impl State {
let pubkey = PublicKey::from_secret(*secret);
debug!("Received a coin: amount {}", note.value);
trace!("Send a notification");
debug!("Send a notification");
if let Some(ch) = notify.clone() {
ch.send((pubkey, note.value)).await?;
}
@@ -179,7 +179,7 @@ impl State {
wallet.put_tree(&self.tree).await?;
}
trace!("apply() exiting successfully");
debug!("apply() exiting successfully");
Ok(())
}
@@ -193,12 +193,12 @@ impl State {
impl ProgramState for State {
fn is_valid_cashier_public_key(&self, public: &PublicKey) -> bool {
trace!("Check if it is a valid cashier public key");
debug!("Check if it is a valid cashier public key");
self.public_keys.contains(public)
}
fn is_valid_merkle(&self, merkle_root: &MerkleNode) -> bool {
trace!("Check if it is valid merkle");
debug!("Check if it is valid merkle");
if let Ok(mr) = self.merkle_roots.key_exist(merkle_root.clone()) {
return mr
}
@@ -206,7 +206,7 @@ impl ProgramState for State {
}
fn nullifier_exists(&self, nullifier: &Nullifier) -> bool {
trace!("Check if nullifier exists");
debug!("Check if nullifier exists");
if let Ok(nl) = self.nullifiers.key_exist(nullifier.to_bytes()) {
return nl
}

View File

@@ -2,7 +2,7 @@ use std::{fs::create_dir_all, path::Path, str::FromStr, time::Duration};
use async_std::sync::Arc;
use incrementalmerkletree::bridgetree::BridgeTree;
use log::{error, info, trace, LevelFilter};
use log::{debug, error, info, LevelFilter};
use sqlx::{
sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions},
ConnectOptions, Row, SqlitePool,
@@ -50,7 +50,7 @@ impl WalletApi for CashierDb {}
impl CashierDb {
pub async fn new(path: &str, password: String) -> Result<CashierDbPtr> {
trace!("new() Constructor called");
debug!("new() Constructor called");
if password.trim().is_empty() {
error!("Password is empty. You must set a password to use the wallet.");
return Err(Error::from(ClientFailed::EmptyPassword))
@@ -85,24 +85,24 @@ impl CashierDb {
let mut conn = self.conn.acquire().await?;
trace!("Initializing main keypairs table");
debug!("Initializing main keypairs table");
sqlx::query(main_kps).execute(&mut conn).await?;
trace!("Initializing deposit keypairs table");
debug!("Initializing deposit keypairs table");
sqlx::query(deposit_kps).execute(&mut conn).await?;
trace!("Initializing withdraw keypairs table");
debug!("Initializing withdraw keypairs table");
sqlx::query(withdraw_kps).execute(&mut conn).await?;
Ok(())
}
pub async fn tree_gen(&self) -> Result<()> {
trace!("Attempting to generate merkle tree");
debug!("Attempting to generate merkle tree");
let mut conn = self.conn.acquire().await?;
match sqlx::query("SELECT * FROM tree").fetch_one(&mut conn).await {
Ok(_) => {
error!("Tree already exist");
error!("Tree already exists");
Err(Error::from(ClientFailed::TreeExists))
}
Err(_) => {
@@ -114,7 +114,7 @@ impl CashierDb {
}
pub async fn get_tree(&self) -> Result<BridgeTree<MerkleNode, 32>> {
trace!("Getting merkle tree");
debug!("Getting merkle tree");
let mut conn = self.conn.acquire().await?;
let row = sqlx::query("SELECT tree FROM tree").fetch_one(&mut conn).await?;
@@ -123,7 +123,7 @@ impl CashierDb {
}
pub async fn put_tree(&self, tree: &BridgeTree<MerkleNode, 32>) -> Result<()> {
trace!("Attempting to write merkle tree");
debug!("Attempting to write merkle tree");
let mut conn = self.conn.acquire().await?;
let tree_bytes = bincode::serialize(tree)?;
@@ -136,7 +136,7 @@ impl CashierDb {
}
pub async fn put_main_keys(&self, token_key: &TokenKey, network: &NetworkName) -> Result<()> {
trace!("Writing main keys into the database");
debug!("Writing main keys into the database");
let network = self.get_value_serialized(network)?;
let mut conn = self.conn.acquire().await?;
@@ -156,7 +156,7 @@ impl CashierDb {
}
pub async fn get_main_keys(&self, network: &NetworkName) -> Result<Vec<TokenKey>> {
trace!("Returning main keypairs");
debug!("Returning main keypairs");
let network = self.get_value_serialized(network)?;
let mut conn = self.conn.acquire().await?;
@@ -180,7 +180,7 @@ impl CashierDb {
}
pub async fn remove_withdraw_and_deposit_keys(&self) -> Result<()> {
trace!("Removing withdraw and deposit keys");
debug!("Removing withdraw and deposit keys");
let mut conn = self.conn.acquire().await?;
sqlx::query("DROP TABLE deposit_keypairs;").execute(&mut conn).await?;
sqlx::query("DROP TABLE withdraw_keypairs;").execute(&mut conn).await?;
@@ -197,7 +197,7 @@ impl CashierDb {
token_id: &DrkTokenId,
mint_address: String,
) -> Result<()> {
trace!("Writing withdraw keys to database");
debug!("Writing withdraw keys to database");
let public = self.get_value_serialized(d_key_public)?;
let secret = self.get_value_serialized(d_key_secret)?;
let network = self.get_value_serialized(network)?;
@@ -235,7 +235,7 @@ impl CashierDb {
token_id: &DrkTokenId,
mint_address: String,
) -> Result<()> {
trace!("Writing deposit keys to database");
debug!("Writing deposit keys to database");
let d_key_public = self.get_value_serialized(d_key_public)?;
let token_id = self.get_value_serialized(token_id)?;
let network = self.get_value_serialized(network)?;
@@ -264,7 +264,7 @@ impl CashierDb {
}
pub async fn get_withdraw_private_keys(&self) -> Result<Vec<SecretKey>> {
trace!("Getting withdraw private keys");
debug!("Getting withdraw private keys");
let confirm = self.get_value_serialized(&false)?;
let mut conn = self.conn.acquire().await?;
@@ -289,7 +289,7 @@ impl CashierDb {
&self,
pubkey: &PublicKey,
) -> Result<Option<WithdrawToken>> {
trace!("Get token address by pubkey");
debug!("Get token address by pubkey");
let d_key_public = self.get_value_serialized(pubkey)?;
let confirm = self.get_value_serialized(&false)?;
@@ -323,7 +323,7 @@ impl CashierDb {
d_key_public: &PublicKey,
network: &NetworkName,
) -> Result<Vec<TokenKey>> {
trace!("Checking for existing dkey");
debug!("Checking for existing dkey");
let d_key_public = self.get_value_serialized(d_key_public)?;
let network = self.get_value_serialized(network)?;
let confirm = self.get_value_serialized(&false)?;
@@ -357,7 +357,7 @@ impl CashierDb {
token_key_public: &[u8],
network: &NetworkName,
) -> Result<Option<Keypair>> {
trace!("Checking for existing token address");
debug!("Checking for existing token address");
let confirm = self.get_value_serialized(&false)?;
let network = self.get_value_serialized(network)?;
@@ -389,7 +389,7 @@ impl CashierDb {
token_address: &[u8],
network: &NetworkName,
) -> Result<()> {
trace!("Confirm withdraw keys");
debug!("Confirm withdraw keys");
let network = self.get_value_serialized(network)?;
let confirm = self.get_value_serialized(&true)?;
@@ -414,7 +414,7 @@ impl CashierDb {
d_key_public: &PublicKey,
network: &NetworkName,
) -> Result<()> {
trace!("Confirm deposit keys");
debug!("Confirm deposit keys");
let network = self.get_value_serialized(network)?;
let confirm = self.get_value_serialized(&true)?;
let d_key_public = self.get_value_serialized(d_key_public)?;
@@ -439,7 +439,7 @@ impl CashierDb {
&self,
network: &NetworkName,
) -> Result<Vec<DepositToken>> {
trace!("Checking for existing dkey");
debug!("Checking for existing dkey");
let network = self.get_value_serialized(network)?;
let confirm = self.get_value_serialized(&false)?;