Skip to content

Commit

Permalink
Merge branch 'development' into core-template-registration
Browse files Browse the repository at this point in the history
* development:
  feat!: add hashing API use to base layer (see issue tari-project#4394) (tari-project#4447)
  feat(wallet): adds --stealth-one-sided flag to make-it-rain (tari-project#4508)
  fix!: change monero consensus encoding an update for hardfork v15 (tari-project#4492)
  fix(core/covenants)!: update covenants to support OutputType enum (tari-project#4472)
  feat(core)!: restrict output types to only those permitted by consensus (tari-project#4467)
  • Loading branch information
sdbondi committed Aug 22, 2022
2 parents c9ae047 + f9af875 commit 6ec71d7
Show file tree
Hide file tree
Showing 48 changed files with 591 additions and 280 deletions.
35 changes: 28 additions & 7 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl CommandContext {
if let LivenessEvent::ReceivedPong(pong) = &*event {
if pong.node_id == dest_node_id {
println!(
"🏓️ Pong received, latency in is {:.2?}!",
"🏓️ Pong received, round-trip-time is {:.2?}!",
pong.latency.unwrap_or_default()
);
break;
Expand Down
29 changes: 18 additions & 11 deletions applications/tari_console_wallet/src/automation/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use std::{
fs,
fs::File,
io,
io::{LineWriter, Write},
path::{Path, PathBuf},
time::{Duration, Instant},
Expand Down Expand Up @@ -68,7 +69,7 @@ use tokio::{

use super::error::CommandError;
use crate::{
cli::CliCommands,
cli::{CliCommands, MakeItRainTransactionType},
utils::db::{CUSTOM_BASE_NODE_ADDRESS_KEY, CUSTOM_BASE_NODE_PUBLIC_KEY_KEY},
};

Expand Down Expand Up @@ -299,7 +300,7 @@ pub async fn make_it_rain(
increase_amount: MicroTari,
start_time: DateTime<Utc>,
destination: PublicKey,
negotiated: bool,
transaction_type: MakeItRainTransactionType,
message: String,
) -> Result<(), CommandError> {
// We are spawning this command in parallel, thus not collecting transaction IDs
Expand Down Expand Up @@ -331,7 +332,6 @@ pub async fn make_it_rain(
delayed_for: Duration,
submit_time: Duration,
}
let transaction_type = if negotiated { "negotiated" } else { "one-sided" };
println!(
"\n`make-it-rain` starting {} {} transactions \"{}\"\n",
num_txs, transaction_type, message
Expand Down Expand Up @@ -367,15 +367,19 @@ pub async fn make_it_rain(
tokio::task::spawn(async move {
let spawn_start = Instant::now();
// Send transaction
let tx_id = if negotiated {
send_tari(tx_service, fee, amount, pk.clone(), msg.clone()).await
} else {
send_one_sided(tx_service, fee, amount, pk.clone(), msg.clone()).await
let tx_id = match transaction_type {
MakeItRainTransactionType::Interactive => {
send_tari(tx_service, fee, amount, pk.clone(), msg.clone()).await
},
MakeItRainTransactionType::OneSided => {
send_one_sided(tx_service, fee, amount, pk.clone(), msg.clone()).await
},
MakeItRainTransactionType::StealthOneSided => {
send_one_sided_to_stealth_address(tx_service, fee, amount, pk.clone(), msg.clone()).await
},
};
let submit_time = Instant::now();
tokio::task::spawn(async move {
print!("{} ", i + 1);
});

if let Err(e) = sender_clone
.send(TransactionSendStats {
i: i + 1,
Expand All @@ -397,6 +401,8 @@ pub async fn make_it_rain(
while let Some(send_stats) = receiver.recv().await {
match send_stats.tx_id {
Ok(tx_id) => {
print!("{} ", send_stats.i);
io::stdout().flush().unwrap();
debug!(
target: LOG_TARGET,
"make-it-rain transaction {} ({}) submitted to queue, tx_id: {}, delayed for ({}ms), submit \
Expand Down Expand Up @@ -606,6 +612,7 @@ pub async fn command_runner(
tx_ids.push(tx_id);
},
MakeItRain(args) => {
let transaction_type = args.transaction_type();
make_it_rain(
transaction_service.clone(),
config.fee_per_gram,
Expand All @@ -615,7 +622,7 @@ pub async fn command_runner(
args.increase_amount,
args.start_time.unwrap_or_else(Utc::now),
args.destination.into(),
!args.one_sided,
transaction_type,
args.message,
)
.await?;
Expand Down
33 changes: 32 additions & 1 deletion applications/tari_console_wallet/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
// 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, time::Duration};
use std::{
fmt::{Display, Formatter},
path::PathBuf,
time::Duration,
};

use chrono::{DateTime, Utc};
use clap::{Args, Parser, Subcommand};
Expand Down Expand Up @@ -144,10 +148,37 @@ pub struct MakeItRainArgs {
pub start_time: Option<DateTime<Utc>>,
#[clap(short, long)]
pub one_sided: bool,
#[clap(short, long, alias = "stealth-one-sided")]
pub stealth: bool,
#[clap(short, long, default_value = "Make it rain")]
pub message: String,
}

impl MakeItRainArgs {
pub fn transaction_type(&self) -> MakeItRainTransactionType {
if self.stealth {
MakeItRainTransactionType::StealthOneSided
} else if self.one_sided {
MakeItRainTransactionType::OneSided
} else {
MakeItRainTransactionType::Interactive
}
}
}

#[derive(Debug, Clone, Copy)]
pub enum MakeItRainTransactionType {
Interactive,
OneSided,
StealthOneSided,
}

impl Display for MakeItRainTransactionType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}

fn parse_start_time(arg: &str) -> Result<DateTime<Utc>, chrono::ParseError> {
let mut start_time = Utc::now();
if !arg.is_empty() && arg.to_uppercase() != "NOW" {
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_merge_mining_proxy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async fn main() -> Result<(), anyhow::Error> {

let config = MergeMiningProxyConfig::load_from(&cfg)?;

error!(target: LOG_TARGET, "Configuration: {:?}", config);
info!(target: LOG_TARGET, "Configuration: {:?}", config);
let client = reqwest::Client::builder()
.connect_timeout(Duration::from_secs(5))
.timeout(Duration::from_secs(10))
Expand Down
11 changes: 4 additions & 7 deletions applications/tari_merge_mining_proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ use jsonrpc::error::StandardError;
use reqwest::{ResponseBuilderExt, Url};
use serde_json as json;
use tari_app_grpc::tari_rpc as grpc;
use tari_core::proof_of_work::{
monero_difficulty,
monero_rx,
monero_rx::FixedByteArray,
randomx_factory::RandomXFactory,
use tari_core::{
consensus::ConsensusEncoding,
proof_of_work::{monero_difficulty, monero_rx, monero_rx::FixedByteArray, randomx_factory::RandomXFactory},
};
use tari_utilities::hex::Hex;
use tracing::{debug, error, info, instrument, trace, warn};
Expand Down Expand Up @@ -269,8 +267,7 @@ impl InnerService {

let header_mut = block_data.tari_block.header.as_mut().unwrap();
let height = header_mut.height;
header_mut.pow.as_mut().unwrap().pow_data = monero_rx::serialize(&monero_data);

monero_data.consensus_encode(&mut header_mut.pow.as_mut().unwrap().pow_data)?;
let tari_header = header_mut.clone().try_into().map_err(MmProxyError::ConversionError)?;
let mut base_node_client = self.base_node_client.clone();
let start = Instant::now();
Expand Down
9 changes: 6 additions & 3 deletions base_layer/common_types/src/types/bullet_rangeproofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

use std::fmt;

use digest::Digest;
use serde::{
de::{self, Visitor},
Deserialize,
Expand All @@ -32,14 +31,18 @@ use serde::{
};
use tari_utilities::{hex::*, ByteArray, ByteArrayError, Hashable};

use crate::types::Blake256;
use super::BulletRangeProofHasherBlake256;

#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct BulletRangeProof(pub Vec<u8>);
/// Implement the hashing function for RangeProof for use in the MMR
impl Hashable for BulletRangeProof {
fn hash(&self) -> Vec<u8> {
Blake256::new().chain(&self.0).finalize().to_vec()
BulletRangeProofHasherBlake256::new()
.chain(&self.0)
.finalize()
.as_ref()
.to_vec()
}
}

Expand Down
9 changes: 9 additions & 0 deletions base_layer/common_types/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,12 @@ pub type RangeProofService = BulletproofsPlusService;

/// Specify the range proof
pub type RangeProof = BulletRangeProof;

use tari_crypto::{hash_domain, hashing::DomainSeparatedHasher};

hash_domain!(
BulletRangeProofHashDomain,
"com.tari.tari-project.base_layer.common_types.bullet_rangeproofs"
);

pub type BulletRangeProofHasherBlake256 = DomainSeparatedHasher<Blake256, BulletRangeProofHashDomain>;
2 changes: 1 addition & 1 deletion base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ integer-encoding = "3.0.2"
lmdb-zero = "0.4.4"
log = "0.4"
log-mdc = "0.1.0"
monero = { version = "^0.13.0", features = ["serde_support"], optional = true }
monero = { git = "https://github.com/tari-project/monero-rs.git", branch = "main" , features = ["serde"], optional = true }
newtype-ops = "0.1.4"
num-traits = "0.2.15"
num-derive = "0.3.3"
Expand Down
7 changes: 7 additions & 0 deletions base_layer/core/src/chain_storage/lmdb_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
pub use lmdb_db::{create_lmdb_database, create_recovery_lmdb_database, LMDBDatabase};
use serde::{Deserialize, Serialize};
use tari_common_types::types::HashOutput;
use tari_crypto::hash_domain;

use crate::transactions::transaction_components::{TransactionInput, TransactionKernel, TransactionOutput};

Expand Down Expand Up @@ -71,3 +72,9 @@ pub(crate) struct TransactionKernelRowData {
pub mmr_position: u32,
pub hash: HashOutput,
}

hash_domain!(
CoreChainStorageHashDomain,
"com.tari.tari-project.base_layer.core.lmdb_db",
1
);
Loading

0 comments on commit 6ec71d7

Please sign in to comment.