Skip to content

Commit

Permalink
fixing cucumber tests..(3)
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Nov 21, 2023
1 parent 9bdbbc0 commit 6a56f69
Show file tree
Hide file tree
Showing 18 changed files with 133 additions and 123 deletions.
12 changes: 6 additions & 6 deletions applications/minotari_app_grpc/proto/wallet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,16 @@ enum TransactionStatus {
TRANSACTION_STATUS_COINBASE = 5;
// This transaction is mined and confirmed at the current base node's height
TRANSACTION_STATUS_MINED_CONFIRMED = 6;
// The transaction was not found by the wallet its in transaction database
TRANSACTION_STATUS_NOT_FOUND = 7;
// The transaction was rejected by the mempool
TRANSACTION_STATUS_REJECTED = 8;
TRANSACTION_STATUS_REJECTED = 7;
// This is faux transaction mainly for one-sided transaction outputs or wallet recovery outputs have been found
TRANSACTION_STATUS_FAUX_UNCONFIRMED = 9;
TRANSACTION_STATUS_FAUX_UNCONFIRMED = 8;
// All Imported and FauxUnconfirmed transactions will end up with this status when the outputs have been confirmed
TRANSACTION_STATUS_FAUX_CONFIRMED = 10;
TRANSACTION_STATUS_FAUX_CONFIRMED = 9;
// This transaction is still being queued for sending
TRANSACTION_STATUS_QUEUED = 11;
TRANSACTION_STATUS_QUEUED = 10;
// The transaction was not found by the wallet its in transaction database
TRANSACTION_STATUS_NOT_FOUND = 11;
}

message GetCompletedTransactionsRequest { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ impl From<TransactionStatus> for grpc::TransactionStatus {
Completed => grpc::TransactionStatus::Completed,
Broadcast => grpc::TransactionStatus::Broadcast,
MinedUnconfirmed => grpc::TransactionStatus::MinedUnconfirmed,
MinedConfirmed => grpc::TransactionStatus::MinedConfirmed,
Imported => grpc::TransactionStatus::Imported,
Pending => grpc::TransactionStatus::Pending,
Coinbase => grpc::TransactionStatus::Coinbase,
MinedConfirmed => grpc::TransactionStatus::MinedConfirmed,
Rejected => grpc::TransactionStatus::Rejected,
FauxUnconfirmed => grpc::TransactionStatus::FauxUnconfirmed,
FauxConfirmed => grpc::TransactionStatus::FauxConfirmed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ impl<'a> BlockTemplateProtocol<'a> {
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::ConversionError(err.to_string()))?;
.map_err(|err| MmProxyError::WalletPaymentAddress(err.to_string()))?;
if wallet_payment_address == TariAddress::default() {
return Err(MmProxyError::PaymentWalletAddressMissing(
"Has default value".to_string(),
return Err(MmProxyError::WalletPaymentAddress(
"May not have the default value".to_string(),
));
}
if wallet_payment_address.network() != config.network {
return Err(MmProxyError::WalletPaymentAddress(
"Wallet address network does not match miner network".to_string(),
));
}
let consensus_manager = ConsensusManager::builder(config.network).build()?;
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_merge_mining_proxy/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct MergeMiningProxyConfig {
pub coinbase_extra: String,
/// Selected network
pub network: Network,
/// The Tari wallet address where the mining funds will be sent to
/// The Tari wallet address (valid address in hex) where the mining funds will be sent to - must be assigned
pub wallet_payment_address: String,
/// Stealth payment yes or no
pub stealth_payment: bool,
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_merge_mining_proxy/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub enum MmProxyError {
#[error("Consensus build error: {0}")]
ConsensusBuilderError(#[from] ConsensusBuilderError),
#[error("Could not convert data:{0}")]
PaymentWalletAddressMissing(String),
WalletPaymentAddress(String),
}

impl From<tonic::Status> for MmProxyError {
Expand Down
10 changes: 5 additions & 5 deletions applications/minotari_miner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ pub struct MinerConfig {
/// `mine_on_tip_only` is set to true
pub validate_tip_timeout_sec: u64,
/// Stratum Mode configuration - mining pool address
pub mining_pool_address: String,
pub stratum_mining_pool_address: String,
/// Stratum Mode configuration - mining wallet address/public key
pub mining_wallet_address: String,
pub stratum_mining_wallet_address: String,
/// Stratum Mode configuration - mining worker name
pub mining_worker_name: String,
/// The extra data to store in the coinbase, usually some data about the mining pool.
Expand All @@ -73,7 +73,7 @@ pub struct MinerConfig {
pub network: Network,
/// Base node reconnect timeout after any gRPC or miner error
pub wait_timeout_on_error: u64,
/// The Tari wallet address where the mining funds will be sent to
/// The Tari wallet address (valid address in hex) where the mining funds will be sent to - must be assigned
pub wallet_payment_address: String,
/// Stealth payment yes or no
pub stealth_payment: bool,
Expand Down Expand Up @@ -102,8 +102,8 @@ impl Default for MinerConfig {
mine_on_tip_only: true,
proof_of_work_algo: ProofOfWork::Sha3x,
validate_tip_timeout_sec: 30,
mining_pool_address: String::new(),
mining_wallet_address: String::new(),
stratum_mining_pool_address: String::new(),
stratum_mining_wallet_address: String::new(),
mining_worker_name: String::new(),
coinbase_extra: "minotari_miner".to_string(),
network: Default::default(),
Expand Down
18 changes: 12 additions & 6 deletions applications/minotari_miner/src/run_miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,27 @@ pub async fn start_miner(cli: Cli) -> Result<(), ExitError> {
.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::ConversionError, err.to_string()))?;
.map_err(|err| ExitError::new(ExitCode::WalletPaymentAddress, err.to_string()))?;
debug!(target: LOG_TARGET_FILE, "wallet_payment_address: {}", wallet_payment_address);
if wallet_payment_address == TariAddress::default() {
return Err(ExitError::new(
ExitCode::PaymentWalletAddressMissing,
"Has default value".to_string(),
ExitCode::WalletPaymentAddress,
"May not have the default value".to_string(),
));
}
if wallet_payment_address.network() != config.network {
return Err(ExitError::new(
ExitCode::WalletPaymentAddress,
"Wallet address network does not match miner network".to_string(),
));
}
let consensus_manager = ConsensusManager::builder(config.network)
.build()
.map_err(|err| ExitError::new(ExitCode::ConsensusManagerBuilderError, err.to_string()))?;

if !config.mining_wallet_address.is_empty() && !config.mining_pool_address.is_empty() {
let url = config.mining_pool_address.clone();
let mut miner_address = config.mining_wallet_address.clone();
if !config.stratum_mining_wallet_address.is_empty() && !config.stratum_mining_pool_address.is_empty() {
let url = config.stratum_mining_pool_address.clone();
let mut miner_address = config.stratum_mining_wallet_address.clone();
let _ = RistrettoPublicKey::from_hex(&miner_address).map_err(|_| {
ExitError::new(
ExitCode::ConfigError,
Expand Down
14 changes: 1 addition & 13 deletions base_layer/core/src/transactions/coinbase_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use tari_common_types::{
use tari_crypto::keys::PublicKey as PK;
use tari_key_manager::key_manager_service::{KeyManagerInterface, KeyManagerServiceError};
use tari_script::{one_sided_payment_script, stealth_payment_script, ExecutionStack, TariScript};
use tari_utilities::{hex::Hex, ByteArrayError};
use tari_utilities::ByteArrayError;
use thiserror::Error;

use crate::{
Expand Down Expand Up @@ -258,12 +258,6 @@ where TKeyManagerInterface: TransactionKeyManagerInterface
let covenant = self.covenant;
let script = self.script.ok_or(CoinbaseBuildError::MissingScript)?;

debug!(target: LOG_TARGET,
"Getting coinbase - height: {}, reward: {}, spending_key_id: {}, script_key_id: {}, encryption_key_id: {}, \
sender_offset_key_id: {}, script: {}",
height, total_reward, spending_key_id, script_key_id, encryption_key_id, sender_offset_key_id, script
);

let kernel_features = KernelFeatures::create_coinbase();
let metadata = TransactionMetadata::new_with_features(0.into(), 0, kernel_features);
// generate kernel signature
Expand Down Expand Up @@ -398,12 +392,7 @@ pub async fn generate_coinbase(
let encryption_private_key = shared_secret_to_output_encryption_key(&shared_secret)?;
let encryption_key_id = key_manager.import_key(encryption_private_key).await?;

let spending_key_hex = spending_key.to_hex();
let spending_key_id = key_manager.import_key(spending_key).await?;
debug!(target: LOG_TARGET,
"generate coinbase - height: {}, spending_key: {}, spending_key_id: {}, sender_offset_key_id: {}, shared_secret: {}",
height, spending_key_hex, spending_key_id, sender_offset_key_id, shared_secret.as_bytes().to_vec().to_hex()
);

let script = if stealth_payment {
let (nonce_private_key, nonce_public_key) = PublicKey::random_keypair(&mut OsRng);
Expand Down Expand Up @@ -439,7 +428,6 @@ pub async fn generate_coinbase(

debug!(target: LOG_TARGET, "Coinbase kernel: {}", kernel.clone());
debug!(target: LOG_TARGET, "Coinbase output: {}", output.clone());
debug!(target: LOG_TARGET, "Coinbase wallet output: {:?}", wallet_output);
Ok((transaction.clone(), output.clone(), kernel.clone(), wallet_output))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ fn validate_input_not_pruned<B: BlockchainBackend>(

fn validate_input_maturity(body: &AggregateBody, height: u64) -> Result<(), ValidationError> {
for input in body.inputs() {
println!("input: {:?}", input);
if !input.is_mature_at(height)? {
return Err(TransactionError::InputMaturity.into());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Any old 'outputs' will not be valid due to the removal of 'coinbase_block_height' and 'coinbase_extra',
-- Any old 'outputs' will not be valid due to the removal of 'coinbase_block_height',
-- so we drop and recreate the table.

DROP TABLE outputs;
Expand Down
2 changes: 1 addition & 1 deletion base_layer/wallet/src/output_manager_service/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ impl OutputManagerHandle {
}
}

pub async fn get_output_statuses_by_tx_id(
pub async fn get_output_statuses_for_tx_id(
&mut self,
tx_id: TxId,
) -> Result<OutputStatusesByTxId, OutputManagerError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,83 +97,82 @@ pub async fn check_faux_transactions<TBackend: 'static + TransactionBackend>(
all_faux_transactions.len()
);
for tx in all_faux_transactions {
let output_statuses_by_tx_id = match output_manager.get_output_statuses_by_tx_id(tx.tx_id).await {
let output_statuses_for_tx_id = match output_manager.get_output_statuses_for_tx_id(tx.tx_id).await {
Ok(s) => s,
Err(e) => {
error!(target: LOG_TARGET, "Problem retrieving output statuses: {}", e);
return;
},
};
if !output_statuses_by_tx_id
let some_outputs_spent = !output_statuses_for_tx_id
.statuses
.iter()
.any(|s| s != &OutputStatus::Unspent)
{
let mined_height = if let Some(height) = output_statuses_by_tx_id.mined_height {
height
} else {
tip_height
};
let mined_in_block: BlockHash = if let Some(hash) = output_statuses_by_tx_id.block_hash {
hash
} else {
FixedHash::zero()
};
let is_valid = tip_height >= mined_height;
let was_confirmed = tx.status == TransactionStatus::FauxConfirmed;
let is_confirmed = tip_height.saturating_sub(mined_height) >=
TransactionServiceConfig::default().num_confirmations_required;
let num_confirmations = tip_height - mined_height;
debug!(
.any(|s| s != &OutputStatus::Unspent);
let mined_height = if let Some(height) = output_statuses_for_tx_id.mined_height {
height
} else {
tip_height
};
let mined_in_block: BlockHash = if let Some(hash) = output_statuses_for_tx_id.block_hash {
hash
} else {
FixedHash::zero()
};
let is_valid = tip_height >= mined_height;
let was_confirmed = tx.status == TransactionStatus::FauxConfirmed;
let is_confirmed =
tip_height.saturating_sub(mined_height) >= TransactionServiceConfig::default().num_confirmations_required;
let num_confirmations = tip_height - mined_height;
debug!(
target: LOG_TARGET,
"Updating faux transaction: TxId({}), mined_height({}), is_confirmed({}), num_confirmations({}), \
no_outputs_spent({}), is_valid({})",
tx.tx_id,
mined_height,
is_confirmed,
num_confirmations,
some_outputs_spent,
is_valid,
);
let result = db.set_transaction_mined_height(
tx.tx_id,
mined_height,
mined_in_block,
tx.mined_timestamp
.map_or(0, |mined_timestamp| mined_timestamp.timestamp() as u64),
num_confirmations,
is_confirmed,
true,
);
if let Err(e) = result {
error!(
target: LOG_TARGET,
"Updating faux transaction: TxId({}), mined_height({}), is_confirmed({}), num_confirmations({}), \
is_valid({})",
tx.tx_id,
mined_height,
is_confirmed,
num_confirmations,
is_valid,
);
let result = db.set_transaction_mined_height(
tx.tx_id,
mined_height,
mined_in_block,
tx.mined_timestamp
.map_or(0, |mined_timestamp| mined_timestamp.timestamp() as u64),
num_confirmations,
is_confirmed,
true,
"Error setting faux transaction to mined confirmed: {}", e
);
if let Err(e) = result {
error!(
target: LOG_TARGET,
"Error setting faux transaction to mined confirmed: {}", e
);
} else {
// Only send an event if the transaction was not previously confirmed OR was previously confirmed and is
// now not confirmed (i.e. confirmation changed)
if !(was_confirmed && is_confirmed) {
let transaction_event = if is_confirmed {
TransactionEvent::FauxTransactionConfirmed {
tx_id: tx.tx_id,
is_valid,
}
} else {
TransactionEvent::FauxTransactionUnconfirmed {
tx_id: tx.tx_id,
num_confirmations: 0,
is_valid,
}
};
let _size = event_publisher.send(Arc::new(transaction_event)).map_err(|e| {
trace!(
target: LOG_TARGET,
"Error sending event, usually because there are no subscribers: {:?}",
e
);
} else {
// Only send an event if the transaction was not previously confirmed OR was previously confirmed and is
// now not confirmed (i.e. confirmation changed)
if !(was_confirmed && is_confirmed) {
let transaction_event = if is_confirmed {
TransactionEvent::FauxTransactionConfirmed {
tx_id: tx.tx_id,
is_valid,
}
} else {
TransactionEvent::FauxTransactionUnconfirmed {
tx_id: tx.tx_id,
num_confirmations: 0,
is_valid,
}
};
let _size = event_publisher.send(Arc::new(transaction_event)).map_err(|e| {
trace!(
target: LOG_TARGET,
"Error sending event, usually because there are no subscribers: {:?}",
e
});
}
);
e
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,7 @@ async fn test_get_status_by_tx_id() {

let output_statuses_by_tx_id = oms
.output_manager_handle
.get_output_statuses_by_tx_id(TxId::from(1u64))
.get_output_statuses_for_tx_id(TxId::from(1u64))
.await
.unwrap();

Expand Down
6 changes: 6 additions & 0 deletions common/config/presets/f_merge_mining_proxy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,9 @@ monerod_url = [# stagenet

# The maximum amount of VMs that RandomX will be use (default = 5)
#max_randomx_vms = 5

# The Tari wallet address (valid address in hex) where the mining funds will be sent to - must be assigned
# e.g. "78e724f466d202abdee0f23c261289074e4a2fc9eb61e83e0179eead76ce2d3f17"
#wallet_payment_address = "xxx"
# Stealth payment yes or no (default: true)
#stealth_payment = true
Loading

0 comments on commit 6a56f69

Please sign in to comment.