From 96a1e4ec144dc17190f396f94ec25c62fb142ce3 Mon Sep 17 00:00:00 2001 From: Martin Stefcek <35243812+Cifko@users.noreply.github.com> Date: Tue, 1 Feb 2022 16:18:47 +0100 Subject: [PATCH] feat: add logging and config to collectibles (#3781) Description --- Added config and logging to tari collectibles. Motivation and Context --- Unite the behavior (configs, logging) of collectibles with other apps. How Has This Been Tested? --- Manually. --- Cargo.lock | 4 + .../tari_collectibles/src-tauri/Cargo.toml | 4 + .../src-tauri/src/app_state.rs | 31 ++-- .../src-tauri/src/clients/base_node_client.rs | 11 +- .../src/clients/validator_node_client.rs | 15 +- .../src-tauri/src/clients/wallet_client.rs | 9 +- .../src/commands/asset_wallets/mod.rs | 18 +- .../src-tauri/src/commands/assets/mod.rs | 14 +- .../src-tauri/src/commands/tip004/mod.rs | 7 +- .../src-tauri/src/commands/tip721/mod.rs | 5 +- .../tari_collectibles/src-tauri/src/main.rs | 8 +- .../src-tauri/src/settings.rs | 58 ------- common/config/presets/collectibles.toml | 15 ++ common/config/presets/validator_node.toml | 3 +- common/logging/log4rs_collectibles.yml | 154 ++++++++++++++++++ common/src/configuration/bootstrap.rs | 10 ++ .../src/configuration/collectibles_config.rs | 63 +++++++ common/src/configuration/global.rs | 5 +- common/src/configuration/mod.rs | 2 + common/src/configuration/utils.rs | 1 + common/src/lib.rs | 1 + common/src/logging.rs | 1 + config/config.toml | 150 ----------------- package-lock.json | 7 +- package.json | 1 + 25 files changed, 347 insertions(+), 250 deletions(-) delete mode 100644 applications/tari_collectibles/src-tauri/src/settings.rs create mode 100644 common/config/presets/collectibles.toml create mode 100644 common/logging/log4rs_collectibles.yml create mode 100644 common/src/configuration/collectibles_config.rs delete mode 100644 config/config.toml create mode 100644 package.json diff --git a/Cargo.lock b/Cargo.lock index 6f4f884bfc..8980b3efc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6472,6 +6472,7 @@ dependencies = [ "diesel", "diesel_migrations", "futures 0.3.19", + "log", "prost", "prost-types", "rand 0.8.4", @@ -6479,6 +6480,8 @@ dependencies = [ "serde_json", "structopt", "tari_app_grpc", + "tari_app_utilities", + "tari_common", "tari_common_types", "tari_crypto", "tari_dan_common_types", @@ -6488,6 +6491,7 @@ dependencies = [ "tauri", "tauri-build", "thiserror", + "tokio 1.15.0", "tonic", "uuid", ] diff --git a/applications/tari_collectibles/src-tauri/Cargo.toml b/applications/tari_collectibles/src-tauri/Cargo.toml index 6f1d659d3e..383ddf166f 100644 --- a/applications/tari_collectibles/src-tauri/Cargo.toml +++ b/applications/tari_collectibles/src-tauri/Cargo.toml @@ -17,12 +17,15 @@ tauri-build = { version = "1.0.0-beta.4" } [dependencies] tari_app_grpc = { path = "../../tari_app_grpc" } +tari_app_utilities = { path = "../../tari_app_utilities" } +tari_common = { path = "../../../common" } tari_common_types = { path = "../../../base_layer/common_types" } tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" } tari_key_manager = { path = "../../../base_layer/key_manager" } tari_mmr = { path = "../../../base_layer/mmr"} tari_utilities = "*" tari_dan_common_types = { path = "../../../dan_layer/common_types"} +log = { version = "0.4.8", features = ["std"] } blake2 = "^0.9.0" futures = "0.3.17" @@ -38,6 +41,7 @@ uuid = { version = "0.8.2", features = ["serde"] } prost = "0.9" prost-types = "0.9" structopt = "0.3.25" +tokio = { version = "1.11", features = ["signal"] } [features] default = [ "custom-protocol" ] diff --git a/applications/tari_collectibles/src-tauri/src/app_state.rs b/applications/tari_collectibles/src-tauri/src/app_state.rs index f2f81edef4..8f2fa32163 100644 --- a/applications/tari_collectibles/src-tauri/src/app_state.rs +++ b/applications/tari_collectibles/src-tauri/src/app_state.rs @@ -24,19 +24,19 @@ use crate::{ clients::{BaseNodeClient, GrpcValidatorNodeClient, WalletClient}, error::CollectiblesError, providers::ConcreteKeyManagerProvider, - settings::Settings, storage::{ sqlite::{SqliteCollectiblesStorage, SqliteDbFactory}, StorageError, }, }; -use std::sync::Arc; +use std::{path::PathBuf, sync::Arc}; +use tari_common::configuration::CollectiblesConfig; use tauri::async_runtime::RwLock; use uuid::Uuid; pub struct AppState { - config: Settings, + config: CollectiblesConfig, db_factory: SqliteDbFactory, current_wallet_id: Option, } @@ -47,27 +47,38 @@ pub struct ConcurrentAppState { } impl ConcurrentAppState { - pub fn new() -> Self { - let settings = Settings::new(); - let db_factory = SqliteDbFactory::new(settings.data_dir.as_path()); + pub fn new(base_path: PathBuf, config: CollectiblesConfig) -> Self { + let db_factory = SqliteDbFactory::new(base_path.as_path()); Self { inner: Arc::new(RwLock::new(AppState { + config, db_factory, - config: settings, current_wallet_id: None, })), } } pub async fn create_wallet_client(&self) -> WalletClient { - WalletClient::new(self.inner.read().await.config.wallet_grpc_address.clone()) + WalletClient::new( + self + .inner + .read() + .await + .config + .wallet_grpc_address + .clone() + .to_string(), + ) } pub async fn connect_base_node_client(&self) -> Result { let lock = self.inner.read().await; - let client = - BaseNodeClient::connect(format!("http://{}", lock.config.base_node_grpc_address)).await?; + let client = BaseNodeClient::connect(format!( + "http://{}", + lock.config.base_node_grpc_address.to_string() + )) + .await?; Ok(client) } diff --git a/applications/tari_collectibles/src-tauri/src/clients/base_node_client.rs b/applications/tari_collectibles/src-tauri/src/clients/base_node_client.rs index 19147a1748..f620a27fef 100644 --- a/applications/tari_collectibles/src-tauri/src/clients/base_node_client.rs +++ b/applications/tari_collectibles/src-tauri/src/clients/base_node_client.rs @@ -22,10 +22,13 @@ use crate::error::CollectiblesError; use futures::StreamExt; +use log::debug; use tari_app_grpc::tari_rpc as grpc; use tari_common_types::types::PublicKey; use tari_utilities::ByteArray; +const LOG_TARGET: &str = "collectibles::base"; + pub struct BaseNodeClient { client: grpc::base_node_client::BaseNodeClient, } @@ -79,7 +82,7 @@ impl BaseNodeClient { let request = grpc::GetAssetMetadataRequest { asset_public_key: Vec::from(asset_public_key.as_bytes()), }; - dbg!(&request); + debug!(target: LOG_TARGET, "request {:?}", request); let response = client .get_asset_metadata(request) .await @@ -88,7 +91,7 @@ impl BaseNodeClient { request: "get_asset_metadata".to_string(), source: s, })?; - dbg!(&response); + debug!(target: LOG_TARGET, "response {:?}", response); Ok(response) } @@ -103,7 +106,7 @@ impl BaseNodeClient { unique_ids: vec![vec![3u8; 32]], }; - dbg!(&request); + debug!(target: LOG_TARGET, "request {:?}", request); let mut stream = client .get_tokens(request) .await @@ -117,7 +120,7 @@ impl BaseNodeClient { if i > 10 { break; } - dbg!(&response); + debug!(target: LOG_TARGET, "response {:?}", response); let features = response .map_err(|status| format!("Got an error status from GRPC:{}", status))? .features; diff --git a/applications/tari_collectibles/src-tauri/src/clients/validator_node_client.rs b/applications/tari_collectibles/src-tauri/src/clients/validator_node_client.rs index c55deefc2f..7f91653cc4 100644 --- a/applications/tari_collectibles/src-tauri/src/clients/validator_node_client.rs +++ b/applications/tari_collectibles/src-tauri/src/clients/validator_node_client.rs @@ -20,10 +20,13 @@ // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use crate::error::CollectiblesError; +use log::{debug, error}; use tari_app_grpc::tari_rpc as grpc; use tari_common_types::types::PublicKey; use tari_utilities::ByteArray; +const LOG_TARGET: &str = "collectibles::validator_node"; + pub trait ValidatorNodeClient {} pub struct GrpcValidatorNodeClient { @@ -57,21 +60,21 @@ impl GrpcValidatorNodeClient { method, args, }; - dbg!(&req); + debug!(target: LOG_TARGET, "req {:?}", req); let response = self .client .invoke_read_method(req) .await .map(|resp| resp.into_inner()) .map_err(|e| { - dbg!(&e); + error!(target: LOG_TARGET, "{}", e); CollectiblesError::ClientRequestError { source: e, request: "invoke_read_method".to_string(), } })?; - dbg!(&response); + debug!(target: LOG_TARGET, "response {:?}", response); Ok(response.result) } @@ -88,21 +91,21 @@ impl GrpcValidatorNodeClient { method, args, }; - dbg!(&req); + debug!(target: LOG_TARGET, "req {:?}", req); let response = self .client .invoke_method(req) .await .map(|resp| resp.into_inner()) .map_err(|e| { - dbg!(&e); + error!(target: LOG_TARGET, "{}", e); CollectiblesError::ClientRequestError { source: e, request: "invoke_method".to_string(), } })?; - dbg!(&response); + debug!(target: LOG_TARGET, "response {:?}", response); Ok(response.result) } } diff --git a/applications/tari_collectibles/src-tauri/src/clients/wallet_client.rs b/applications/tari_collectibles/src-tauri/src/clients/wallet_client.rs index ca4ffc16cf..4b416c67ed 100644 --- a/applications/tari_collectibles/src-tauri/src/clients/wallet_client.rs +++ b/applications/tari_collectibles/src-tauri/src/clients/wallet_client.rs @@ -21,10 +21,13 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use crate::error::CollectiblesError; +use log::debug; use tari_app_grpc::{tari_rpc as grpc, tari_rpc::RegisterAssetRequest}; use tari_common_types::types::PublicKey; use tari_utilities::{hex::Hex, ByteArray}; +const LOG_TARGET: &str = "collectibles::wallet"; + pub struct WalletClient { endpoint: String, inner: Option>, @@ -76,7 +79,7 @@ impl WalletClient { source: error, } })?; - dbg!(&result); + debug!(target: LOG_TARGET, "result {:?}", result); Ok(result.into_inner().public_key.to_hex()) } @@ -91,7 +94,7 @@ impl WalletClient { source, } })?; - dbg!(&result); + debug!(target: LOG_TARGET, "result {:?}", result); Ok(result.into_inner()) } @@ -117,7 +120,7 @@ impl WalletClient { request: "create_initial_asset_checkpoint".to_string(), source, })?; - dbg!(&result); + debug!(target: LOG_TARGET, "result {:?}", result); Ok(result.into_inner()) } } diff --git a/applications/tari_collectibles/src-tauri/src/commands/asset_wallets/mod.rs b/applications/tari_collectibles/src-tauri/src/commands/asset_wallets/mod.rs index 72afc38481..a9537bb58a 100644 --- a/applications/tari_collectibles/src-tauri/src/commands/asset_wallets/mod.rs +++ b/applications/tari_collectibles/src-tauri/src/commands/asset_wallets/mod.rs @@ -30,6 +30,7 @@ use crate::{ StorageTransaction, }, }; +use log::{debug, error}; use prost::Message; use tari_common_types::types::PublicKey; use tari_dan_common_types::proto::tips::tip002; @@ -37,6 +38,8 @@ use tari_utilities::{hex::Hex, ByteArray}; use tauri::Manager; use uuid::Uuid; +const LOG_TARGET: &str = "collectibles::asset_wallets"; + #[tauri::command] pub(crate) async fn asset_wallets_create( asset_public_key: String, @@ -84,7 +87,7 @@ pub(crate) async fn asset_wallets_create( } } Err(e) => { - dbg!(e); + error!(target: LOG_TARGET, "{}", e); None } }; @@ -121,7 +124,10 @@ pub(crate) async fn asset_wallets_get_balance( asset_public_key: String, state: tauri::State<'_, ConcurrentAppState>, ) -> Result { - dbg!(&asset_public_key); + debug!( + target: LOG_TARGET, + "asset_public_key {:?}", asset_public_key + ); let asset_public_key = PublicKey::from_hex(&asset_public_key)?; let wallet_id = state @@ -143,7 +149,7 @@ pub(crate) async fn asset_wallets_get_balance( let args = tip002::BalanceOfRequest { owner: Vec::from(owner.public_key.as_bytes()), }; - dbg!(&args); + debug!(target: LOG_TARGET, "args {:?}", args); let mut args_bytes = vec![]; args.encode(&mut args_bytes)?; // let req = grpc::InvokeReadMethodRequest{ @@ -162,7 +168,7 @@ pub(crate) async fn asset_wallets_get_balance( ) .await?; - dbg!(&resp); + debug!(target: LOG_TARGET, "resp {:?}", resp); let proto_resp: tip002::BalanceOfResponse = Message::decode(&*resp)?; total += proto_resp.balance; } @@ -219,7 +225,7 @@ pub(crate) async fn asset_wallets_create_address( public_key: address_public_key, key_manager_path, }; - dbg!(&address); + debug!(target: LOG_TARGET, "address {:?}", address); db.addresses().insert(&address, &transaction)?; transaction.commit()?; Ok(address) @@ -295,6 +301,6 @@ pub(crate) async fn asset_wallets_send_to( .invoke_method(asset_public_key, 2, "transfer".to_string(), args_bytes) .await?; - dbg!(&resp); + debug!(target: LOG_TARGET, "resp {:?}", resp); Ok(()) } diff --git a/applications/tari_collectibles/src-tauri/src/commands/assets/mod.rs b/applications/tari_collectibles/src-tauri/src/commands/assets/mod.rs index d40d94c056..0871aec587 100644 --- a/applications/tari_collectibles/src-tauri/src/commands/assets/mod.rs +++ b/applications/tari_collectibles/src-tauri/src/commands/assets/mod.rs @@ -35,6 +35,7 @@ use crate::{ }, }; +use log::debug; use tari_app_grpc::tari_rpc::{self}; use tari_common_types::types::{Commitment, PublicKey}; use tari_crypto::{hash::blake2::Blake256, ristretto::RistrettoPublicKey}; @@ -42,6 +43,8 @@ use tari_mmr::{MemBackendVec, MerkleMountainRange}; use tari_utilities::{hex::Hex, ByteArray}; use uuid::Uuid; +const LOG_TARGET: &str = "collectibles::assets"; + #[tauri::command] pub(crate) async fn assets_create( name: String, @@ -96,14 +99,17 @@ pub(crate) async fn assets_create( image: Some(image), committee: None, }; - dbg!(&asset_row); + debug!(target: LOG_TARGET, "asset_row {:?}", asset_row); db.assets().insert(&asset_row, &transaction)?; let asset_wallet_row = AssetWalletRow { id: Uuid::new_v4(), asset_id, wallet_id, }; - dbg!(&asset_wallet_row); + debug!( + target: LOG_TARGET, + "asset_wallet_row {:?}", asset_wallet_row + ); db.asset_wallets().insert(&asset_wallet_row, &transaction)?; let address = AddressRow { id: Uuid::new_v4(), @@ -112,7 +118,7 @@ pub(crate) async fn assets_create( public_key: asset_public_key, key_manager_path: key_manager_path.clone(), }; - dbg!(&address); + debug!(target: LOG_TARGET, "address {:?}", address); db.addresses().insert(&address, &transaction)?; if template_ids.contains(&2) { let row = Tip002AddressRow { @@ -259,7 +265,7 @@ pub(crate) async fn assets_get_registration( let asset_pub_key = PublicKey::from_hex(&asset_pub_key)?; let asset = client.get_asset_metadata(&asset_pub_key).await?; - dbg!(&asset); + debug!(target: LOG_TARGET, "asset {:?}", asset); let features = asset.features.unwrap(); let serializer = V1AssetMetadataSerializer {}; let metadata = serializer.deserialize(&features.metadata[1..]); diff --git a/applications/tari_collectibles/src-tauri/src/commands/tip004/mod.rs b/applications/tari_collectibles/src-tauri/src/commands/tip004/mod.rs index 3a8e603985..4f36ed68b9 100644 --- a/applications/tari_collectibles/src-tauri/src/commands/tip004/mod.rs +++ b/applications/tari_collectibles/src-tauri/src/commands/tip004/mod.rs @@ -29,12 +29,15 @@ use crate::{ Tip721TokensTableGateway, }, }; +use log::debug; use prost::Message; use tari_common_types::types::PublicKey; use tari_dan_common_types::proto::tips::tip004; use tari_utilities::{hex::Hex, ByteArray}; use uuid::Uuid; +const LOG_TARGET: &str = "collectibles::tip004"; + #[tauri::command] pub(crate) async fn tip004_mint_token( asset_public_key: String, @@ -62,7 +65,7 @@ pub(crate) async fn tip004_mint_token( let result = client .invoke_method(asset_public_key, 4, "mint".to_string(), bytes) .await?; - dbg!(&result); + debug!(target: LOG_TARGET, "result {:?}", result); Ok(()) } @@ -96,7 +99,7 @@ pub(crate) async fn tip004_list_tokens( args.encode_to_vec(), ) .await?; - dbg!(&result); + debug!(target: LOG_TARGET, "result {:?}", result); db.tip721_tokens().delete_all_for_address(address.id, &tx)?; if !result.is_empty() { let balance_of: tip004::BalanceOfResponse = Message::decode(&*result)?; diff --git a/applications/tari_collectibles/src-tauri/src/commands/tip721/mod.rs b/applications/tari_collectibles/src-tauri/src/commands/tip721/mod.rs index 856ae6a7b1..927fa900bf 100644 --- a/applications/tari_collectibles/src-tauri/src/commands/tip721/mod.rs +++ b/applications/tari_collectibles/src-tauri/src/commands/tip721/mod.rs @@ -25,12 +25,15 @@ use crate::{ status::Status, storage::{AddressesTableGateway, AssetsTableGateway, CollectiblesStorage}, }; +use log::debug; use prost::Message; use tari_common_types::types::PublicKey; use tari_dan_common_types::proto::tips::tip721; use tari_utilities::{hex::Hex, ByteArray}; use uuid::Uuid; +const LOG_TARGET: &str = "collectibles::tip721"; + #[tauri::command] pub(crate) async fn tip721_transfer_from( asset_public_key: String, @@ -72,6 +75,6 @@ pub(crate) async fn tip721_transfer_from( transfer_request, ) .await?; - dbg!(&res); + debug!(target: LOG_TARGET, "res {:?}", res); Ok(()) } diff --git a/applications/tari_collectibles/src-tauri/src/main.rs b/applications/tari_collectibles/src-tauri/src/main.rs index 974a325e0e..85c77fb3b4 100644 --- a/applications/tari_collectibles/src-tauri/src/main.rs +++ b/applications/tari_collectibles/src-tauri/src/main.rs @@ -4,6 +4,9 @@ windows_subsystem = "windows" )] +use tari_app_utilities::initialization::init_configuration; +use tari_common::configuration::bootstrap::ApplicationType; + use crate::app_state::ConcurrentAppState; #[macro_use] @@ -19,12 +22,13 @@ mod error; mod models; mod providers; mod schema; -mod settings; mod status; mod storage; fn main() { - let state = ConcurrentAppState::new(); + #[allow(unused_mut)] // config isn't mutated on windows + let (bootstrap, mut config, _) = init_configuration(ApplicationType::Collectibles).unwrap(); + let state = ConcurrentAppState::new(bootstrap.base_path, config.collectibles_config.unwrap()); tauri::Builder::default() .manage(state) diff --git a/applications/tari_collectibles/src-tauri/src/settings.rs b/applications/tari_collectibles/src-tauri/src/settings.rs deleted file mode 100644 index f5dab2a675..0000000000 --- a/applications/tari_collectibles/src-tauri/src/settings.rs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2021. The Tari Project -// -// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the -// following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following -// disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the -// following disclaimer in the documentation and/or other materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote -// products derived from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, -// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -use std::path::PathBuf; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -pub struct Settings { - #[structopt(short, long, aliases = &["base_path", "base_dir", "base-dir"], env="DATA_DIR", default_value = "data")] - pub(crate) data_dir: PathBuf, - #[structopt( - short, - long, - env = "WALLET_GRPC_ADDRESS", - default_value = "localhost:18143" - )] - pub(crate) wallet_grpc_address: String, - #[structopt( - short, - long, - env = "BASE_NODE_GRPC_ADDRESS", - default_value = "localhost:18142" - )] - pub(crate) base_node_grpc_address: String, - #[structopt( - short, - long, - env = "VALIDATOR_NODE_GRPC_ADDRESS", - default_value = "localhost:18144" - )] - pub(crate) validator_node_grpc_address: String, -} - -impl Settings { - pub fn new() -> Self { - Self::from_args() - } -} diff --git a/common/config/presets/collectibles.toml b/common/config/presets/collectibles.toml new file mode 100644 index 0000000000..8d4910cc96 --- /dev/null +++ b/common/config/presets/collectibles.toml @@ -0,0 +1,15 @@ +######################################################################################################################## +# # +# Collectibles Configuration Options # +# # +######################################################################################################################## + +[collectibles] +# GRPC address of validator node +#validator_node_grpc_address = 127.0.0.1:18144 + +# GRPC address of base node +#base_node_grpc_address = 127.0.0.1:18142 + +# GRPC address of wallet +#wallet_grpc_address = 127.0.0.1:18143 diff --git a/common/config/presets/validator_node.toml b/common/config/presets/validator_node.toml index 68dc1b424e..f6af4517a9 100644 --- a/common/config/presets/validator_node.toml +++ b/common/config/presets/validator_node.toml @@ -1,10 +1,11 @@ -[validator_node] ######################################################################################################################## # # # Validator Node Configuration Options # # # ######################################################################################################################## +[validator_node] + committee = ["2ea0df3059caf4411624d6bf5b9c02238d607d2798c586b3e6c2a054da3f205a"] # cannot be of zero size phase_timeout = 30 template_id = "EditableMetadata" diff --git a/common/logging/log4rs_collectibles.yml b/common/logging/log4rs_collectibles.yml new file mode 100644 index 0000000000..eb71151aca --- /dev/null +++ b/common/logging/log4rs_collectibles.yml @@ -0,0 +1,154 @@ +# A sample log configuration file for running in release mode. By default, this configuration splits up log messages to +# three destinations: +# * Console: For log messages with level INFO and higher +# * log/collectibles/network.log: INFO-level logs related to the comms crate. This file will be quite busy since there +# are lots of P2P debug messages, and so this traffic is segregated from the application log messages +# * log/collectibles/base_layer.log: Non-comms related INFO-level messages and higher are logged into this file +# * log/collectibles/other.log: Third-party crates' messages will be logged here at an ERROR level +# +# See https://docs.rs/log4rs/0.8.3/log4rs/encode/pattern/index.html for deciphering the log pattern. The log format +# used in this sample configuration prints messages as: +# timestamp [target] LEVEL message +refresh_rate: 30 seconds +appenders: + # An appender named "stdout" that writes to stdout + stdout: + kind: console + + encoder: + pattern: "{d(%H:%M)} {h({l}):5} {m}{n}" + filters: + - kind: threshold + level: warn + + # An appender named "network" that writes to a file with a custom pattern encoder + network: + kind: rolling_file + path: "log/collectibles/network.log" + policy: + kind: compound + trigger: + kind: size + limit: 10mb + roller: + kind: fixed_window + base: 1 + count: 5 + pattern: "log/collectibles/network.{}.log" + encoder: + pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} [{t}] [Thread:{I}] {l:5} {m}{n}" + + # An appender named "base_layer" that writes to a file with a custom pattern encoder + base_layer: + kind: rolling_file + path: "log/collectibles/base_layer.log" + policy: + kind: compound + trigger: + kind: size + limit: 10mb + roller: + kind: fixed_window + base: 1 + count: 5 + pattern: "log/collectibles/base_layer.{}.log" + encoder: + pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} [{t}] [Thread:{I}] [{X(node-public-key)},{X(node-id)}] {l:5} {m}{n}" + + # An appender named "other" that writes to a file with a custom pattern encoder + other: + kind: rolling_file + path: "log/collectibles/other.log" + policy: + kind: compound + trigger: + kind: size + limit: 10mb + roller: + kind: fixed_window + base: 1 + count: 5 + pattern: "log/collectibles/other.{}.log" + encoder: + pattern: "{d(%Y-%m-%d %H:%M:%S.%f)} [{t}] [Thread:{I}] {l:5} {m}{n}" + +# Set the default logging level to "info" +root: + level: warn + appenders: + - stdout + +loggers: + # Route log events common to every application to all appenders + tari::application: + level: info + appenders: + - base_layer + - network + - other + additive: false + + # Route log events sent to the "core" logger to the "base_layer" appender + c: + level: info + appenders: + - base_layer + tari: + level: info + appenders: + - base_layer + + # Route log events sent to the "wallet" logger to the "base_layer" appender + wallet: + level: info + appenders: + - base_layer + # Route log events sent to the "comms" logger to the "network" appender + comms: + level: info + appenders: + - network + # Route log events sent to the "p2p" logger to the "network" appender + p2p: + level: info + appenders: + - network + + # Route log events sent to the "yamux" logger to the "network" appender + yamux: + level: info + appenders: + - network + # Route log events sent to the "mio" logger to the "network" appender + mio: + level: error + appenders: + - network + # Route log events sent to the "rustyline" logger to the "other" appender + rustyline: + level: error + appenders: + - other + additive: false + + # Route log events sent to the "tokio_util" logger to the "other" appender + tokio_util: + level: error + appenders: + - other + # Route PGP log events + pgp: + level: warn + appenders: + - other + # Route log events sent to the "tari_mm_proxy" logger to the "base_layer" appender + tari_mm_proxy: + level: info + appenders: + - base_layer + # Route R2D2 log events + r2d2: + level: warn + appenders: + - other + additive: false diff --git a/common/src/configuration/bootstrap.rs b/common/src/configuration/bootstrap.rs index 1c105db748..f1e1b7e3e2 100644 --- a/common/src/configuration/bootstrap.rs +++ b/common/src/configuration/bootstrap.rs @@ -67,6 +67,7 @@ use crate::{ initialize_logging, logging, DEFAULT_BASE_NODE_LOG_CONFIG, + DEFAULT_COLLECTIBLES_LOG_CONFIG, DEFAULT_CONFIG, DEFAULT_MERGE_MINING_PROXY_LOG_CONFIG, DEFAULT_MINING_NODE_LOG_CONFIG, @@ -275,6 +276,12 @@ impl ConfigBootstrap { Some(&self.base_path), )) }, + ApplicationType::Collectibles => { + self.log_config = normalize_path(dir_utils::default_path( + DEFAULT_COLLECTIBLES_LOG_CONFIG, + Some(&self.base_path), + )) + }, } } @@ -356,6 +363,7 @@ pub enum ApplicationType { MiningNode, StratumTranscoder, ValidatorNode, + Collectibles, } impl ApplicationType { @@ -368,6 +376,7 @@ impl ApplicationType { MiningNode => "Tari Mining Node", ValidatorNode => "Digital Assets Network Validator Node", StratumTranscoder => "Tari Stratum Transcoder", + Collectibles => "Tari Collectibles", } } @@ -380,6 +389,7 @@ impl ApplicationType { MiningNode => "miner", StratumTranscoder => "stratum-transcoder", ValidatorNode => "validator-node", + Collectibles => "collectibles", } } } diff --git a/common/src/configuration/collectibles_config.rs b/common/src/configuration/collectibles_config.rs new file mode 100644 index 0000000000..3851cc1a74 --- /dev/null +++ b/common/src/configuration/collectibles_config.rs @@ -0,0 +1,63 @@ +// Copyright 2021. The Tari Project +// +// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +// following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following +// disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the +// following disclaimer in the documentation and/or other materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote +// products derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +use std::net::{IpAddr, Ipv4Addr, SocketAddr}; + +use config::Config; +use serde::Deserialize; + +use crate::ConfigurationError; + +#[derive(Debug, Clone, Deserialize)] +pub struct CollectiblesConfig { + #[serde(default = "default_validator_node_grpc_address")] + pub validator_node_grpc_address: SocketAddr, + #[serde(default = "default_base_node_grpc_address")] + pub base_node_grpc_address: SocketAddr, + #[serde(default = "default_wallet_grpc_address")] + pub wallet_grpc_address: SocketAddr, +} + +fn default_validator_node_grpc_address() -> SocketAddr { + SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 18144) +} + +fn default_base_node_grpc_address() -> SocketAddr { + SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 18142) +} + +fn default_wallet_grpc_address() -> SocketAddr { + SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 18143) +} + +impl CollectiblesConfig { + pub fn convert_if_present(cfg: Config) -> Result, ConfigurationError> { + let section: Self = match cfg.get("collectibles") { + Ok(s) => s, + Err(_e) => { + // dbg!(e); + return Ok(None); + }, + }; + Ok(Some(section)) + } +} diff --git a/common/src/configuration/global.rs b/common/src/configuration/global.rs index c2dbc1e2e7..545ceb83e6 100644 --- a/common/src/configuration/global.rs +++ b/common/src/configuration/global.rs @@ -43,6 +43,7 @@ use crate::{ bootstrap::ApplicationType, name_server::DnsNameServer, BaseNodeConfig, + CollectiblesConfig, MergeMiningConfig, Network, ValidatorNodeConfig, @@ -148,6 +149,7 @@ pub struct GlobalConfig { pub console_wallet_use_libtor: bool, pub merge_mining_config: Option, pub blockchain_track_reorgs: bool, + pub collectibles_config: Option, } impl GlobalConfig { @@ -870,7 +872,7 @@ fn convert_node_config( flood_ban_max_msg_count, mine_on_tip_only, validate_tip_timeout_sec, - validator_node: ValidatorNodeConfig::convert_if_present(cfg)?, + validator_node: ValidatorNodeConfig::convert_if_present(cfg.clone())?, mining_pool_address, mining_wallet_address, mining_worker_name, @@ -880,6 +882,7 @@ fn convert_node_config( console_wallet_use_libtor, merge_mining_config, blockchain_track_reorgs, + collectibles_config: CollectiblesConfig::convert_if_present(cfg)?, }) } diff --git a/common/src/configuration/mod.rs b/common/src/configuration/mod.rs index a8139c09e7..b9530707a1 100644 --- a/common/src/configuration/mod.rs +++ b/common/src/configuration/mod.rs @@ -41,6 +41,7 @@ pub mod loader; mod network; pub use network::Network; mod base_node_config; +mod collectibles_config; mod merge_mining_config; pub mod name_server; pub mod seconds; @@ -50,6 +51,7 @@ mod wallet_config; pub mod writer; pub use base_node_config::BaseNodeConfig; +pub use collectibles_config::CollectiblesConfig; pub use merge_mining_config::MergeMiningConfig; pub use validator_node_config::ValidatorNodeConfig; pub use wallet_config::WalletConfig; diff --git a/common/src/configuration/utils.rs b/common/src/configuration/utils.rs index 4d40de1cb2..c3ba451f18 100644 --- a/common/src/configuration/utils.rs +++ b/common/src/configuration/utils.rs @@ -49,6 +49,7 @@ pub fn config_installer(_app_type: ApplicationType, path: &Path) -> Result<(), s include_str!("../../config/presets/merge_mining_proxy.toml"), include_str!("../../config/presets/stratum_transcoder.toml"), include_str!("../../config/presets/validator_node.toml"), + include_str!("../../config/presets/collectibles.toml"), ] .join("\n"); diff --git a/common/src/lib.rs b/common/src/lib.rs index 03adac789d..10ed3efad0 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -102,5 +102,6 @@ pub const DEFAULT_WALLET_LOG_CONFIG: &str = "config/log4rs_console_wallet.yml"; pub const DEFAULT_MERGE_MINING_PROXY_LOG_CONFIG: &str = "config/log4rs_merge_mining_proxy.yml"; pub const DEFAULT_STRATUM_TRANSCODER_LOG_CONFIG: &str = "config/log4rs_miningcore_transcoder.yml"; pub const DEFAULT_MINING_NODE_LOG_CONFIG: &str = "config/log4rs_mining_node.yml"; +pub const DEFAULT_COLLECTIBLES_LOG_CONFIG: &str = "config/log4rs_collectibles.yml"; pub(crate) const LOG_TARGET: &str = "common::config"; diff --git a/common/src/logging.rs b/common/src/logging.rs index e08e20551a..e87cc95538 100644 --- a/common/src/logging.rs +++ b/common/src/logging.rs @@ -69,6 +69,7 @@ pub fn log_config_installer(application_type: ApplicationType, path: &Path) -> R MergeMiningProxy => include_str!("../logging/log4rs_sample_proxy.yml"), StratumTranscoder => include_str!("../logging/log4rs_sample_transcoder.yml"), ValidatorNode => include_str!("../logging/log4rs_sample_validator_node.yml"), + Collectibles => include_str!("../logging/log4rs_collectibles.yml"), }; if let Some(d) = path.parent() { diff --git a/config/config.toml b/config/config.toml deleted file mode 100644 index 7cf031df49..0000000000 --- a/config/config.toml +++ /dev/null @@ -1,150 +0,0 @@ -######################################################################################################################## -# # -# Common Configuration Options # -# # -######################################################################################################################## - -[common] -# Select the network to connect to. Valid options are: -# mainnet - the "real" Tari network (default) -# weatherwax - the Tari testnet -network = "dibbler" - -# Tari is a 100% peer-to-peer network, so there are no servers to hold messages for you while you're offline. -# Instead, we rely on our peers to hold messages for us while we're offline. This settings sets maximum size of the -# message cache that for holding our peers' messages, in MB. -#message_cache_size = 10 - -# When storing messages for peers, hold onto them for at most this long before discarding them. The default is 1440 -# minutes = or 24 hrs. -#message_cache_ttl = 1440 - -# If peer nodes spam you with messages, or are otherwise badly behaved, they will be added to your denylist and banned -# You can set a time limit to release that ban (in minutes), or otherwise ban them for life (-1). The default is to -# ban them for 10 days. -#denylist_ban_period = 1440 - -# The number of liveness sessions to allow. Liveness sessions can be established by liveness monitors over TCP by -# sending a 0x50 (P) as the first byte. Any messages sent must be followed by newline message no longer than -# 50 characters. That message will be echoed back. -#liveness_max_sessions = 0 -#liveness_allowlist_cidrs = ["127.0.0.1/32"] - -# The buffer size constants for the publish/subscribe connector channel, connecting comms messages to the domain layer: -# - Buffer size for the base node (min value = 30, default value = 1500). -#buffer_size_base_node = 1500 -# - Buffer size for the console wallet (min value = 300, default value = 50000). -#buffer_size_console_wallet = 50000 -# The rate limit constants for the publish/subscribe connector channel, i.e. maximum amount of inbound messages to -# accept - any rate attemting to exceed this limit will be throttled. -# - Rate limit for the base node (min value = 5, default value = 1000). -#buffer_rate_limit_base_node = 1000 -# - Rate limit for the console wallet (min value = 5, default value = 1000). -buffer_rate_limit_console_wallet = 1000 -# The message deduplication persistent cache size - messages with these hashes in the cache will only be processed once. -# The cache will also be trimmed down to size periodically (min value = 0, default value = 2500). -dedup_cache_capacity = 25000 - -# The timeout (s) for requesting blocks from a peer during blockchain sync (min value = 10 s, default value = 150 s). -#fetch_blocks_timeout = 150 - -# The timeout (s) for requesting UTXOs from a base node (min value = 10 s, default value = 600 s). -#fetch_utxos_timeout = 600 - -# The timeout (s) for requesting other base node services (min value = 10 s, default value = 180 s). -#service_request_timeout = 180 - -# The maximum simultaneous comms RPC sessions allowed (default value = 1000). Setting this to -1 will allow unlimited -# sessions. -rpc_max_simultaneous_sessions = 10000 - -[common.weatherwax] -# When first logging onto the Tari network, you need to find a few peers to bootstrap the process. In the absence of -# any servers, this is a little more challenging than usual. Our best strategy is just to try and connect to the peers -# you knew about last time you ran the software. But what about when you run the software for the first time? That's -# where this allowlist comes in. It's a list of known Tari nodes that are likely to be around for a long time and that -# new nodes can use to introduce themselves to the network. -# peer_seeds = ["public_key1::address1", "public_key2::address2",... ] -peer_seeds = [ - # weatherwax - "98bc76afc1c35ad4651bdc9ef57bbe0655a2ea3cd86c0e19b5fd5890546eb040::/onion3/33izgtjkrlxhxybj6luqowkpiy2wvte43osejnbqyieqtdfhovzghxad:18141", #jozi - "9a26e910288213d649b26f9a7a7ee51fe2b2a67ff7d42334523463bf4be94312::/onion3/56kq54ylttnbl5ikotqex3oqvtzlxdpn7zlx4v56rvzf4kq7eezlclid:18141", #london - "6afd5b3c7772ad7d4bb26e0c19668fe04f2d68f99de9e132bee50a6c1846946d::/onion3/may4ajbmcn4dlnzf6fanvqlklxzqiw6qwu6ywqwkjc3bb354rc2i5wid:18141", #ncal - "8e7beec9becdc44fe6015a00d97a77fa3dbafe65127dcc988df6326bd9fd040d::/onion3/3pise36l4imoopsbjic5rtw67adx7rms6w5pgjmccpdwiqx66j7oqcqd:18141", #nvir - "80bb590d943a46e63ae79af5dc2c7d35a3dcd7922c182b28f619dc4cfc366f44::/onion3/oaxwahri7r3h5qjlcdbveyjmg4jsttausik66bicmhixft73nmvecdad:18141", #oregon - "981cc8cd1e4fe2f99ea1bd3e0ab1e7821ca0bfab336a4967cfec053fee86254c::/onion3/7hxpnxrxycdfevirddau7ybofwedaamjrg2ijm57k2kevh5q46ixamid:18141", #seoul - "f2ce179fb733725961a5f7e1e45dacdd443dd43ba6237438d6abe344fb717058::/onion3/nvgdmjf4wucgatz7vemzvi2u4sw5o4gyzwuikagpepoj4w7mkii47zid:18141", #stockholm - "909c0160f4d8e815aba5c2bbccfcceb448877e7b38759fb160f3e9494484d515::/onion3/qw5uxv533sqdn2qoncfyqo35dgecy4rt4x27rexi2her6q6pcpxbm4qd:18141", #sydney -] - -# DNS seeds -# The DNS records in these hostnames should provide TXT records as per https://github.com/tari-project/tari/pull/2319 -# Enter a domain name for the TXT records: -dns_seeds =["seeds.weatherwax.tari.com"] -# The name server used to resolve DNS seeds format: {socket address}/{tls sni dns name} (Default: cloudflare) -# dns_seeds_name_server = "1.1.1.1:853/cloudfare-dns.com" -# Servers addresses, majority of them have to agree. -# autoupdate_dns_hosts = [#server1, #server2, ...] -# Set to true to only accept DNS records that pass DNSSEC validation (Default: true) -dns_seeds_use_dnssec = false - -# Auto Update -# -# This interval in seconds to check for software updates. Setting this to 0 disables checking. -# auto_update.check_interval = 300 -# Customize the hosts that are used to check for updates. These hosts must contain update information in DNS TXT records. -# "auto_update.dns_hosts" = ["updates.weatherwax.taripulse.com"] -# Customize the location of the update SHA hashes and maintainer-signed signature. -# "auto_update.hashes_url" = "https://
/hashes.txt" -# "auto_update.hashes_sig_url" = "https://
/hashes.txt.sig" - -[common.igor] -peer_seeds = [ - # igor - "8e7eb81e512f3d6347bf9b1ca9cd67d2c8e29f2836fc5bd608206505cc72af34::/onion3/l4wouomx42nezhzexjdzfh7pcou5l7df24ggmwgekuih7tkv2rsaokqd:18141", - "00b35047a341401bcd336b2a3d564280a72f6dc72ec4c739d30c502acce4e803::/onion3/ojhxd7z6ga7qrvjlr3px66u7eiwasmffnuklscbh5o7g6wrbysj45vid:18141", - "40a9d8573745072534bce7d0ecafe882b1c79570375a69841c08a98dee9ecb5f::/onion3/io37fylc2pupg4cte4siqlsmuszkeythgjsxs2i3prm6jyz2dtophaad:18141", - "126c7ee64f71aca36398b977dd31fbbe9f9dad615df96473fb655bef5709c540::/onion3/6ilmgndocop7ybgmcvivbdsetzr5ggj4hhsivievoa2dx2b43wqlrlid:18141", -] - -dns_seeds =["seeds.igor.tari.com"] -# dns_seeds_name_server = "1.1.1.1:853/cloudfare-dns.com" -dns_seeds_use_dnssec = false - -# auto_update.check_interval = 300 -# "auto_update.dns_hosts" = ["updates.igor.taripulse.com"] -# "auto_update.hashes_url" = "https://
/hashes.txt" -# "auto_update.hashes_sig_url" = "https://
/hashes.txt.sig" - -[common.dibbler] -dns_seeds =["seeds.dibbler.tari.com"] -peer_seeds = [ - "721e9da488302e69523bca1a9cdcbd2419dddda11698a1e8c6c7bd619659ff21::/onion3/qw4ymrzbanbcr3wwlesxbot72iayd7xdjcrtnacbwgk637vfon47hqad:18141", - # 333388d1cbe3e2bd17453d052f - "c2eca9cf32261a1343e21ed718e79f25bfc74386e9305350b06f62047f519347::/onion3/6yxqk2ybo43u73ukfhyc42qn25echn4zegjpod2ccxzr2jd5atipwzqd:18141", - # 555575715a49fc242d756e52ca - "42fcde82b44af1de95a505d858cb31a422c56c4ac4747fbf3da47d648d4fc346::/onion3/2l3e7ysmihc23zybapdrsbcfg6omtjtfkvwj65dstnfxkwtai2fawtyd:18141", - # 77771f53be07fab4be5f1e1ff7 - "50e6aa8f6c50f1b9d9b3d438dfd2a29cfe1f3e3a650bd9e6b1e10f96b6c38f4d::/onion3/7s6y3cz5bnewlj5ypm7sekhgvqjyrq4bpaj5dyvvo7vxydj7hsmyf5ad:18141", - # 9999016f1f3a6162dddf5a45aa - "36a9df45e1423b5315ffa7a91521924210c8e1d1537ad0968450f20f21e5200d::/onion3/v24qfheti2rztlwzgk6v4kdbes3ra7mo3i2fobacqkbfrk656e3uvnid:18141", - # bbbb8358387d81c388fadb4649 - "be128d570e8ec7b15c101ee1a56d6c56dd7d109199f0bd02f182b71142b8675f::/onion3/ha422qsy743ayblgolui5pg226u42wfcklhc5p7nbhiytlsp4ir2syqd:18141", - # eeeeb0a943ed143e613a135392 - "3e0321c0928ca559ab3c0a396272dfaea705efce88440611a38ff3898b097217::/onion3/sl5ledjoaisst6d4fh7kde746dwweuge4m4mf5nkzdhmy57uwgtb7qqd:18141" -] -[validator_node] -######################################################################################################################## -# # -# Validator Node Configuration Options # -# # -######################################################################################################################## - -# If you are not , you can simply leave everything in this section commented out. Base nodes -# help maintain the security of the Tari token and are the surest way to preserve your privacy and be 100% sure that -# no-one is cheating you out of your money.o - -committee = ["2ea0df3059caf4411624d6bf5b9c02238d607d2798c586b3e6c2a054da3f205a"] # cannot be of zero size -phase_timeout = 30 -template_id = "EditableMetadata" - diff --git a/package-lock.json b/package-lock.json index 7abb96a64d..d3287a6b0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,4 +1,7 @@ { - "lockfileVersion": 1, - "version": "0.27.2" + "name": "tari", + "version": "0.27.2", + "lockfileVersion": 2, + "requires": true, + "packages": {} } diff --git a/package.json b/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/package.json @@ -0,0 +1 @@ +{}