Merge pull request #34 from vacp2p/logging

logging added to UTXO, Account, Transaction
This commit is contained in:
tyshko-rostyslav 2024-12-30 01:47:50 -05:00 committed by GitHub
commit bd092fec81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 74 additions and 3 deletions

2
Cargo.lock generated
View File

@ -4349,6 +4349,7 @@ dependencies = [
"anyhow",
"elliptic-curve",
"env_logger",
"hex",
"log",
"lru",
"monotree",
@ -4817,6 +4818,7 @@ version = "0.1.0"
dependencies = [
"anyhow",
"env_logger",
"hex",
"log",
"monotree",
"serde",

View File

@ -2,6 +2,7 @@ use std::collections::HashMap;
use anyhow::Result;
use k256::AffinePoint;
use log::info;
use serde::Serialize;
use storage::{merkle_tree_public::TreeHashType, nullifier::UTXONullifier};
use utxo::{
@ -115,6 +116,12 @@ impl Account {
Ok(())
}
pub fn log(&self) {
self.key_holder.log();
info!("Account address is {:?}", hex::encode(self.address));
info!("Account balance is {:?}", self.balance);
}
}
impl Default for Account {

View File

@ -3,6 +3,7 @@ use constants_types::{CipherText, Nonce};
use elliptic_curve::group::GroupEncoding;
use ephemeral_key_holder::EphemeralKeyHolder;
use k256::AffinePoint;
use log::info;
use secret_holders::{SeedHolder, TopSecretKeyHolder, UTXOSecretKeyHolder};
use storage::merkle_tree_public::TreeHashType;
@ -74,6 +75,14 @@ impl AddressKeyHolder {
cipher.decrypt(&nonce, ciphertext.as_slice()).unwrap()
}
pub fn log(&self) {
info!("AddressKeyHolder top_secret_key_holder is {:?}", self.top_secret_key_holder);
info!("AddressKeyHolder utxo_secret_key_holder is {:?}", self.utxo_secret_key_holder);
info!("AddressKeyHolder address is {:?}", self.address);
info!("AddressKeyHolder nullifer_public_key is {:?}", self.nullifer_public_key);
info!("AddressKeyHolder viewing_public_key is {:?}", self.viewing_public_key);
}
}
#[cfg(test)]

View File

@ -140,6 +140,7 @@ impl NodeCore {
pub async fn create_new_account(&mut self) -> AccountAddress {
let account = Account::new();
account.log();
let addr = account.address;
@ -163,6 +164,7 @@ impl NodeCore {
let acc_map_read_guard = self.storage.read().await;
let accout = acc_map_read_guard.acc_map.get(&acc).unwrap();
accout.log();
let ephm_key_holder = &accout.produce_ephemeral_key_holder();
@ -223,6 +225,7 @@ impl NodeCore {
let acc_map_read_guard = self.storage.read().await;
let accout = acc_map_read_guard.acc_map.get(&utxo.owner).unwrap();
accout.log();
let nullifier = generate_nullifiers(
&utxo,
@ -295,6 +298,7 @@ impl NodeCore {
let acc_map_read_guard = self.storage.read().await;
let accout = acc_map_read_guard.acc_map.get(&acc).unwrap();
accout.log();
let commitment_secrets = CommitmentSecrets {
value: balance,
@ -392,6 +396,7 @@ impl NodeCore {
let commitment_in = acc_map_read_guard.utxo_commitments_store.get_tx(comm_gen_hash).unwrap().hash;
let accout = acc_map_read_guard.acc_map.get(&utxo.owner).unwrap();
accout.log();
let nullifier = generate_nullifiers(
&utxo,
@ -431,6 +436,7 @@ impl NodeCore {
) -> Result<(SendTxResponse, [u8; 32], [u8; 32])> {
let point_before_prove = std::time::Instant::now();
let (tx, utxo_hash) = self.mint_utxo_private(acc, amount).await;
tx.log();
let point_after_prove = std::time::Instant::now();
let commitment_generated_hash = tx.utxo_commitments_created_hashes[0];
@ -460,6 +466,7 @@ impl NodeCore {
) -> Result<(SendTxResponse, Vec<([u8; 32], [u8; 32])>)> {
let point_before_prove = std::time::Instant::now();
let (tx, utxo_hashes) = self.transfer_utxo_private(utxo, comm_hash, receivers).await;
tx.log();
let point_after_prove = std::time::Instant::now();
let timedelta = (point_after_prove - point_before_prove).as_millis();
@ -476,6 +483,7 @@ impl NodeCore {
) -> Result<(SendTxResponse, Vec<([u8; 32], [u8; 32])>)> {
let point_before_prove = std::time::Instant::now();
let (tx, utxo_hashes) = self.transfer_balance_shielded(acc, amount, receivers).await;
tx.log();
let point_after_prove = std::time::Instant::now();
let timedelta = (point_after_prove - point_before_prove).as_millis();
@ -492,6 +500,7 @@ impl NodeCore {
) -> Result<SendTxResponse> {
let point_before_prove = std::time::Instant::now();
let tx = self.transfer_utxo_deshielded(utxo, comm_gen_hash, receivers).await;
tx.log();
let point_after_prove = std::time::Instant::now();
let timedelta = (point_after_prove - point_before_prove).as_millis();
@ -515,6 +524,7 @@ impl NodeCore {
let mut write_guard = self.storage.write().await;
let acc = write_guard.acc_map.get_mut(&acc_addr).unwrap();
acc.log();
acc.utxo_tree
.get_item(new_utxo_hash)
@ -522,6 +532,8 @@ impl NodeCore {
.unwrap()
.clone()
};
new_utxo.log();
let resp = self
.send_deshielded_send_tx(new_utxo, comm_gen_hash, vec![(100, acc_addr)])
@ -536,6 +548,7 @@ impl NodeCore {
let acc_map_read_guard = self.storage.read().await;
let acc = acc_map_read_guard.acc_map.get(&acc_addr).unwrap();
acc.log();
acc.balance
};
@ -556,7 +569,8 @@ impl NodeCore {
{
let acc_map_read_guard = self.storage.read().await;
let acc = acc_map_read_guard.acc_map.get(&acc_addr).unwrap();
let acc = acc_map_read_guard.acc_map.get(&acc_addr).unwrap();;
acc.log();
info!("New acconut public balance is {:?}", acc.balance);
};
@ -576,6 +590,7 @@ impl NodeCore {
let mut write_guard = self.storage.write().await;
let acc = write_guard.acc_map.get_mut(&acc_addr).unwrap();
acc.log();
acc.utxo_tree
.get_item(new_utxo_hash)
@ -583,6 +598,8 @@ impl NodeCore {
.unwrap()
.clone()
};
new_utxo.log();
info!("User received new utxo {new_utxo:?}");
}
@ -600,6 +617,7 @@ impl NodeCore {
let mut write_guard = self.storage.write().await;
let acc = write_guard.acc_map.get_mut(&acc_addr).unwrap();
acc.log();
acc.utxo_tree
.get_item(new_utxo_hash)
@ -607,6 +625,7 @@ impl NodeCore {
.unwrap()
.clone()
};
new_utxo.log();
let acc_addr_rec = self.create_new_account().await;
@ -625,6 +644,7 @@ impl NodeCore {
let mut write_guard = self.storage.write().await;
let acc = write_guard.acc_map.get_mut(&acc_addr_rec).unwrap();
acc.log();
acc.utxo_tree
.get_item(new_utxo_hash)
@ -650,7 +670,8 @@ impl NodeCore {
{
let acc_map_read_guard = self.storage.read().await;
let acc = acc_map_read_guard.acc_map.get(&acc_addr).unwrap();
acc.log();
info!("New acconut public balance is {:?}", acc.balance);
}
@ -669,6 +690,7 @@ impl NodeCore {
let mut write_guard = self.storage.write().await;
let acc = write_guard.acc_map.get_mut(&acc_addr_rec).unwrap();
acc.log();
acc.utxo_tree
.get_item(new_utxo_hash)
@ -695,6 +717,7 @@ impl NodeCore {
let mut write_guard = self.storage.write().await;
let acc = write_guard.acc_map.get_mut(&acc_addr).unwrap();
acc.log();
acc.utxo_tree
.get_item(new_utxo_hash)
@ -702,6 +725,7 @@ impl NodeCore {
.unwrap()
.clone()
};
new_utxo.log();
let resp = self
.send_deshielded_send_tx(new_utxo, comm_gen_hash, vec![(100, acc_addr_rec)])
@ -715,7 +739,8 @@ impl NodeCore {
{
let read_guard = self.storage.read().await;
let acc_rec = read_guard.acc_map.get(&acc_addr_rec).unwrap();
acc_rec.log();
info!("New account public balance is {:?}", acc_rec.balance);
}
}

View File

@ -12,6 +12,7 @@ serde.workspace = true
lru.workspace = true
thiserror.workspace = true
elliptic-curve.workspace = true
hex.workspace = true
rocksdb.workspace = true
rs_merkle.workspace = true

View File

@ -1,3 +1,4 @@
use log::info;
use serde::{Deserialize, Serialize};
use sha2::{digest::FixedOutput, Digest};
@ -89,3 +90,18 @@ impl From<TransactionPayload> for Transaction {
}
}
}
impl Transaction {
pub fn log(&self) {
info!("Transaction hash is {:?}", hex::encode(self.hash));
info!("Transaction tx_kind is {:?}", self.tx_kind);
info!("Transaction execution_input is {:?}", hex::encode(self.execution_input.clone()));
info!("Transaction execution_output is {:?}", hex::encode(self.execution_output.clone()));
info!("Transaction utxo_commitments_spent_hashes is {:?}", self.utxo_commitments_spent_hashes.iter().map(|val| hex::encode(val.clone())));
info!("Transaction utxo_commitments_created_hashes is {:?}", self.utxo_commitments_created_hashes.iter().map(|val| hex::encode(val.clone())));
info!("Transaction nullifier_created_hashes is {:?}", self.nullifier_created_hashes.iter().map(|val| hex::encode(val.clone())));
info!("Transaction execution_proof_private is {:?}", self.execution_proof_private);
info!("Transaction encoded_data is {:?}", self.encoded_data.iter().map(|val| (hex::encode(val.0.clone()), hex::encode(val.1.clone()))));
info!("Transaction ephemeral_pub_key is {:?}", hex::encode(self.ephemeral_pub_key.clone()));
}
}

View File

@ -11,6 +11,7 @@ log.workspace = true
serde.workspace = true
monotree.workspace = true
sha2.workspace = true
hex.workspace = true
[dependencies.storage]
path = "../storage"

View File

@ -1,4 +1,5 @@
use anyhow::Result;
use log::info;
use serde::{Deserialize, Serialize};
use sha2::{digest::FixedOutput, Digest};
use storage::{merkle_tree_public::TreeHashType, nullifier::UTXONullifier, AccountId};
@ -69,6 +70,15 @@ impl UTXO {
privacy_flag: self.privacy_flag,
}
}
pub fn log(&self) {
info!("UTXO hash is {:?}", hex::encode(self.hash));
info!("UTXO owner is {:?}", self.owner);
info!("UTXO nullifier is {:?}", self.nullifier.clone().map(|val| hex::encode(val.utxo_hash)));
info!("UTXO asset is {:?}", hex::encode(self.asset.clone()));
info!("UTXO amount is {:?}", self.amount);
info!("UTXO privacy_flag is {:?}", self.privacy_flag);
}
}
#[cfg(test)]