Skip to content

Commit

Permalink
review comments 4
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Nov 22, 2023
1 parent 32f9d00 commit 1bdcb49
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 124 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions applications/minotari_console_wallet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ Total value of UTXOs: 36105.165440 T
example output - `--csv-file` (contents of `utxos.csv`)

```
"#","Value (uT)","Spending Key","Commitment","Maturity"
"1","121999250","0b0ce2add569845ec8bb84256b731e644e2224580b568e75666399e868ea5701","22514e279bd7e7e0a6e45905e07323b16f6114e300bcc02f36b2baf44a17b43d","0"
"2","124000000","8829254b5267de26fe926f30518604abeec156740abe64b435ac6081269f2f0d","88f4e7216353032b90bee1c8b4243c3f25b357902a5cb145fda1c98316525214","0"
"3","125000000","295853fad02d56313920130c3a5fa3aa8be54297ee5375aa2d788f4e49f08309","72a42d2db4f8eebbc4d0074fcb04338b8caa22312ce6a68e8798c2452b52e465","0"
"#","Value (uT)","Spending Key","Commitment","Flags","Maturity"
"1","121999250","0b0ce2add569845ec8bb84256b731e644e2224580b568e75666399e868ea5701","22514e279bd7e7e0a6e45905e07323b16f6114e300bcc02f36b2baf44a17b43d","(empty)","0"
"2","124000000","8829254b5267de26fe926f30518604abeec156740abe64b435ac6081269f2f0d","88f4e7216353032b90bee1c8b4243c3f25b357902a5cb145fda1c98316525214","(empty)","0"
"3","125000000","295853fad02d56313920130c3a5fa3aa8be54297ee5375aa2d788f4e49f08309","72a42d2db4f8eebbc4d0074fcb04338b8caa22312ce6a68e8798c2452b52e465","(empty)","0"
...
"10","5513131148","a6323f62ef21c45f03c73b424d9823b1a0f44a4408be688e5f6fde6419a11407","dcec835619474a62b5cef8227481cebd5831aec515e85286f3932c8093e9d06b","10655"
"11","5513145680","5af45bff0f533999c94ec799aa4789260a1b989207363c33ec6ec388899ec906","7ec353f1f005637192d50104b3c5b4621d1ebdafb5c5cc078cf3f86754669352","10649"
"10","5513131148","a6323f62ef21c45f03c73b424d9823b1a0f44a4408be688e5f6fde6419a11407","dcec835619474a62b5cef8227481cebd5831aec515e85286f3932c8093e9d06b","COINBASE_OUTPUT","10655"
"11","5513145680","5af45bff0f533999c94ec799aa4789260a1b989207363c33ec6ec388899ec906","7ec353f1f005637192d50104b3c5b4621d1ebdafb5c5cc078cf3f86754669352","COINBASE_OUTPUT","10649"
```

- **count-utxos**
Expand Down
1 change: 1 addition & 0 deletions applications/minotari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ fn display_password_feedback(passphrase: &SafePassword) -> bool {
"The password you chose is weak; a determined attacker with access to your device may be able to guess it."
);
println!("You may want to consider changing it to a stronger one.");
println!("Here are some suggestions:");
for suggestion in feedback {
println!("- {}", suggestion);
}
Expand Down
2 changes: 0 additions & 2 deletions applications/minotari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ minotari_node_grpc_client = { path = "../../clients/rust/base_node_grpc_client"
minotari_wallet_grpc_client = { path = "../../clients/rust/wallet_grpc_client" }
minotari_app_grpc = { path = "../minotari_app_grpc" }
tari_key_manager = { path = "../../base_layer/key_manager", features = ["key_manager_service"] }
tari_crypto = { version = "0.19", features = ["borsh"] }

anyhow = "1.0.53"
crossterm = { version = "0.25.0" }
Expand All @@ -44,7 +43,6 @@ tokio = { version = "1.23", features = ["macros"] }
tonic = "0.6.2"
tracing = "0.1"
url = "2.1.1"
rand = "0.8"

[build-dependencies]
tari_features = { path = "../../common/tari_features"}
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,16 @@ use std::{cmp, str::FromStr, sync::Arc};
use log::*;
use minotari_app_grpc::{authentication::ClientAuthenticationInterceptor, tari_rpc::base_node_client::BaseNodeClient};
use minotari_node_grpc_client::grpc;
use rand::rngs::OsRng;
use tari_common_types::{tari_address::TariAddress, types::PrivateKey};
use tari_common_types::tari_address::TariAddress;
use tari_core::{
consensus::ConsensusManager,
proof_of_work::{monero_rx, monero_rx::FixedByteArray, Difficulty},
transactions::{
generate_coinbase,
key_manager::{create_memory_db_key_manager, MemoryDbKeyManager, TariKeyId},
key_manager::{create_memory_db_key_manager, MemoryDbKeyManager},
transaction_components::{TransactionKernel, TransactionOutput},
},
};
use tari_crypto::keys::SecretKey;
use tari_key_manager::key_manager_service::KeyManagerInterface;
use tonic::{codegen::InterceptedService, transport::Channel};

use crate::{
Expand All @@ -56,7 +53,6 @@ pub struct BlockTemplateProtocol<'a> {
config: Arc<MergeMiningProxyConfig>,
base_node_client: &'a mut BaseNodeClient<InterceptedService<Channel, ClientAuthenticationInterceptor>>,
key_manager: MemoryDbKeyManager,
miner_node_script_key_id: TariKeyId,
wallet_payment_address: TariAddress,
consensus_manager: ConsensusManager,
}
Expand All @@ -67,16 +63,13 @@ impl<'a> BlockTemplateProtocol<'a> {
config: Arc<MergeMiningProxyConfig>,
) -> Result<BlockTemplateProtocol<'a>, MmProxyError> {
let key_manager = create_memory_db_key_manager();
let wallet_private_key = PrivateKey::random(&mut OsRng);
let miner_node_script_key_id = key_manager.import_key(wallet_private_key).await?;
let wallet_payment_address = TariAddress::from_str(&config.wallet_payment_address)
.map_err(|err| MmProxyError::WalletPaymentAddress(err.to_string()))?;
let consensus_manager = ConsensusManager::builder(config.network).build()?;
Ok(Self {
config,
base_node_client,
key_manager,
miner_node_script_key_id,
wallet_payment_address,
consensus_manager,
})
Expand Down Expand Up @@ -213,13 +206,12 @@ impl BlockTemplateProtocol<'_> {
let block_reward = miner_data.reward;
let total_fees = miner_data.total_fees;

let (_, coinbase_output, coinbase_kernel, _) = generate_coinbase(
let (coinbase_output, coinbase_kernel) = generate_coinbase(
total_fees.into(),
block_reward.into(),
tari_height,
self.config.coinbase_extra.as_bytes(),
&self.key_manager,
&self.miner_node_script_key_id,
&self.wallet_payment_address,
self.config.stealth_payment,
self.consensus_manager.consensus_constants(tari_height),
Expand Down
1 change: 0 additions & 1 deletion applications/minotari_miner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ minotari_app_utilities = { path = "../minotari_app_utilities" }
minotari_app_grpc = { path = "../minotari_app_grpc" }
tari_crypto = { version = "0.19" }
tari_utilities = { version = "0.6" }
tari_key_manager = { path = "../../base_layer/key_manager", features = ["key_manager_service"] }

borsh = "0.10"
crossterm = { version = "0.25.0" }
Expand Down
26 changes: 8 additions & 18 deletions applications/minotari_miner/src/run_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,24 @@ use minotari_app_grpc::{
authentication::ClientAuthenticationInterceptor,
tari_rpc::{base_node_client::BaseNodeClient, TransactionOutput as GrpcTransactionOutput},
};
use rand::rngs::OsRng;
use tari_common::{
configuration::bootstrap::{grpc_default_port, ApplicationType},
exit_codes::{ExitCode, ExitError},
load_configuration,
DefaultConfigLoader,
};
use tari_common_types::{tari_address::TariAddress, types::PrivateKey};
use tari_common_types::tari_address::TariAddress;
use tari_comms::utils::multiaddr::multiaddr_to_socketaddr;
use tari_core::{
blocks::BlockHeader,
consensus::ConsensusManager,
transactions::{
generate_coinbase,
key_manager::{create_memory_db_key_manager, MemoryDbKeyManager, TariKeyId},
key_manager::{create_memory_db_key_manager, MemoryDbKeyManager},
tari_amount::MicroMinotari,
},
};
use tari_crypto::{keys::SecretKey, ristretto::RistrettoPublicKey};
use tari_key_manager::key_manager_service::KeyManagerInterface;
use tari_crypto::ristretto::RistrettoPublicKey;
use tari_utilities::hex::Hex;
use tokio::time::sleep;
use tonic::{
Expand Down Expand Up @@ -76,11 +74,6 @@ pub async fn start_miner(cli: Cli) -> Result<(), ExitError> {
debug!(target: LOG_TARGET_FILE, "{:?}", config);
setup_grpc_config(&mut config);
let key_manager = create_memory_db_key_manager();
let wallet_private_key = PrivateKey::random(&mut OsRng);
let miner_node_script_key_id = key_manager
.import_key(wallet_private_key)
.await
.map_err(|err| ExitError::new(ExitCode::KeyManagerServiceError, err.to_string()))?;
let wallet_payment_address = TariAddress::from_str(&config.wallet_payment_address).map_err(|err| {
ExitError::new(
ExitCode::WalletPaymentAddress,
Expand Down Expand Up @@ -157,7 +150,6 @@ pub async fn start_miner(cli: Cli) -> Result<(), ExitError> {
&config,
&cli,
&key_manager,
&miner_node_script_key_id,
&wallet_payment_address,
&consensus_manager,
)
Expand Down Expand Up @@ -256,7 +248,6 @@ async fn mining_cycle(
config: &MinerConfig,
cli: &Cli,
key_manager: &MemoryDbKeyManager,
miner_node_script_key_id: &TariKeyId,
wallet_payment_address: &TariAddress,
consensus_manager: &ConsensusManager,
) -> Result<bool, MinerError> {
Expand Down Expand Up @@ -287,29 +278,28 @@ async fn mining_cycle(
let miner_data = template_response.miner_data.ok_or_else(|| err_empty("miner_data"))?;
let fee = MicroMinotari::from(miner_data.total_fees);
let reward = MicroMinotari::from(miner_data.reward);
let (_, output, kernel, _) = generate_coinbase(
let (coinbase_output, coinbase_kernel) = generate_coinbase(
fee,
reward,
height,
config.coinbase_extra.as_bytes(),
key_manager,
miner_node_script_key_id,
wallet_payment_address,
config.stealth_payment,
consensus_manager.consensus_constants(height),
)
.await
.map_err(|e| MinerError::CoinbaseError(e.to_string()))?;
debug!(target: LOG_TARGET, "Coinbase kernel: {}", kernel);
debug!(target: LOG_TARGET, "Coinbase output: {}", output);
debug!(target: LOG_TARGET, "Coinbase kernel: {}", coinbase_kernel);
debug!(target: LOG_TARGET, "Coinbase output: {}", coinbase_output);

let body = block_template
.body
.as_mut()
.ok_or_else(|| err_empty("new_block_template.body"))?;
let grpc_output = GrpcTransactionOutput::try_from(output.clone()).map_err(MinerError::Conversion)?;
let grpc_output = GrpcTransactionOutput::try_from(coinbase_output.clone()).map_err(MinerError::Conversion)?;
body.outputs.push(grpc_output);
body.kernels.push(kernel.into());
body.kernels.push(coinbase_kernel.into());
let target_difficulty = miner_data.target_difficulty;

debug!(target: LOG_TARGET, "Asking base node to assemble the MMR roots");
Expand Down
16 changes: 8 additions & 8 deletions base_layer/core/src/chain_storage/tests/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn create_next_block(
prev_block: &Block,
transactions: Vec<Arc<Transaction>>,
key_manager: &MemoryDbKeyManager,
miner_node_script_key_id: &TariKeyId,
script_key_id: &TariKeyId,
wallet_payment_address: &TariAddress,
) -> (Arc<Block>, WalletOutput) {
let rules = db.rules();
Expand All @@ -63,7 +63,7 @@ async fn create_next_block(
.with_transactions(transactions.into_iter().map(|t| (*t).clone()).collect())
.finish(),
key_manager,
miner_node_script_key_id,
script_key_id,
wallet_payment_address,
)
.await;
Expand Down Expand Up @@ -92,14 +92,14 @@ async fn add_many_chained_blocks(
let mut prev_block = Arc::new(db.fetch_block(last_header.height, true).unwrap().into_block());
let mut blocks = Vec::with_capacity(size);
let mut outputs = Vec::with_capacity(size);
let (miner_node_script_key_id, wallet_payment_address) = default_coinbase_entities(key_manager).await;
let (script_key_id, wallet_payment_address) = default_coinbase_entities(key_manager).await;
for _ in 1..=size {
let (block, coinbase_utxo) = create_next_block(
db,
&prev_block,
vec![],
key_manager,
&miner_node_script_key_id,
&script_key_id,
&wallet_payment_address,
)
.await;
Expand Down Expand Up @@ -506,13 +506,13 @@ mod fetch_header_containing_kernel_mmr {
)
.await;

let (miner_node_script_key_id, wallet_payment_address) = default_coinbase_entities(&key_manager).await;
let (script_key_id, wallet_payment_address) = default_coinbase_entities(&key_manager).await;
let (block, _) = create_next_block(
&db,
&blocks[0],
txns,
&key_manager,
&miner_node_script_key_id,
&script_key_id,
&wallet_payment_address,
)
.await;
Expand Down Expand Up @@ -644,13 +644,13 @@ mod validator_node_merkle_root {
&key_manager,
)
.await;
let (miner_node_script_key_id, wallet_payment_address) = default_coinbase_entities(&key_manager).await;
let (script_key_id, wallet_payment_address) = default_coinbase_entities(&key_manager).await;
let (block, _) = create_next_block(
&db,
&blocks[0],
tx,
&key_manager,
&miner_node_script_key_id,
&script_key_id,
&wallet_payment_address,
)
.await;
Expand Down
14 changes: 7 additions & 7 deletions base_layer/core/src/test_helpers/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ pub async fn create_chained_blocks<T: Into<BlockSpecs>>(
let km = create_memory_db_key_manager();
let blocks: BlockSpecs = blocks.into();
let mut block_names = Vec::with_capacity(blocks.len());
let (miner_node_script_key_id, wallet_payment_address) = default_coinbase_entities(&km).await;
let (script_key_id, wallet_payment_address) = default_coinbase_entities(&km).await;
for block_spec in blocks {
let prev_block = block_hashes
.get(block_spec.parent)
Expand All @@ -438,7 +438,7 @@ pub async fn create_chained_blocks<T: Into<BlockSpecs>>(
prev_block.block(),
block_spec,
&km,
&miner_node_script_key_id,
&script_key_id,
&wallet_payment_address,
)
.await;
Expand Down Expand Up @@ -502,7 +502,7 @@ pub struct TestBlockchain {
chain: Vec<(&'static str, Arc<ChainBlock>)>,
rules: ConsensusManager,
pub km: MemoryDbKeyManager,
miner_node_script_key_id: TariKeyId,
script_key_id: TariKeyId,
wallet_payment_address: TariAddress,
}

Expand All @@ -515,13 +515,13 @@ impl TestBlockchain {
.map(Arc::new)
.unwrap();
let km = create_memory_db_key_manager();
let (miner_node_script_key_id, wallet_payment_address) = default_coinbase_entities(&km).await;
let (script_key_id, wallet_payment_address) = default_coinbase_entities(&km).await;
let mut blockchain = Self {
db,
chain: Default::default(),
rules,
km,
miner_node_script_key_id,
script_key_id,
wallet_payment_address,
};

Expand Down Expand Up @@ -625,7 +625,7 @@ impl TestBlockchain {
parent.block(),
block_spec,
&self.km,
&self.miner_node_script_key_id,
&self.script_key_id,
&self.wallet_payment_address,
)
.await;
Expand All @@ -643,7 +643,7 @@ impl TestBlockchain {
parent.block(),
block_spec,
&self.km,
&self.miner_node_script_key_id,
&self.script_key_id,
&self.wallet_payment_address,
)
.await;
Expand Down
Loading

0 comments on commit 1bdcb49

Please sign in to comment.