Skip to content

Commit

Permalink
Merge branch 'development' into sw_fix_kernel_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler authored Aug 4, 2022
2 parents d1ff8cf + 954efea commit 317c0c1
Show file tree
Hide file tree
Showing 54 changed files with 1,316 additions and 4,513 deletions.
45 changes: 41 additions & 4 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ members = [
"comms/dht",
"comms/rpc_macros",
"dan_layer/core",
"dan_layer/template_abi",
"dan_layer/storage_lmdb",
"dan_layer/storage_sqlite",
"dan_layer/template_abi",
"dan_layer/template_lib",
"dan_layer/template_macros",
"common_sqlite",
"infrastructure/libtor",
"infrastructure/metrics",
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_base_node/src/commands/cli_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl CliLoop {
async fn watch_loop(&mut self) {
if let Some(command) = self.watch_task.take() {
let mut interrupt = signal::ctrl_c().fuse().boxed();
let mut software_update_notif = self.context.software_updater.new_update_notifier().clone();
let mut software_update_notif = self.context.software_updater.update_notifier().clone();
let config = self.context.config.clone();
let line = command.line();
let interval = command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl CommandContext {
println!("Author: {}", consts::APP_AUTHOR);
println!("Avx2: {}", if cfg!(feature = "avx2") { "enabled" } else { "disabled" });

if let Some(ref update) = *self.software_updater.new_update_notifier().borrow() {
if let Some(ref update) = *self.software_updater.update_notifier().borrow() {
println!(
"Version {} of the {} is available: {} (sha: {})",
update.version(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ impl tari_rpc::base_node_server::BaseNode for BaseNodeGrpcServer {
) -> Result<Response<tari_rpc::SoftwareUpdate>, Status> {
let mut resp = tari_rpc::SoftwareUpdate::default();

if let Some(ref update) = *self.software_updater.new_update_notifier().borrow() {
if let Some(ref update) = *self.software_updater.update_notifier().borrow() {
resp.has_update = true;
resp.version = update.version().to_string();
resp.sha = update.to_hash_hex();
Expand Down
27 changes: 12 additions & 15 deletions applications/tari_console_wallet/src/grpc/wallet_grpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,18 @@ impl wallet_server::Wallet for WalletGrpcServer {
&self,
_: Request<tari_rpc::Empty>,
) -> Result<Response<tari_rpc::SoftwareUpdate>, Status> {
todo!("reimplement updates")
// let mut resp = tari_rpc::SoftwareUpdate::default();
//
// if let Some(ref update) = *self
// .wallet
// .get_software_updater()
// .map(|su| su.new_update_notifier().borrow())
// {
// resp.has_update = true;
// resp.version = update.version().to_string();
// resp.sha = update.to_hash_hex();
// resp.download_url = update.download_url().to_string();
// }
//
// Ok(Response::new(resp))
let mut resp = tari_rpc::SoftwareUpdate::default();

if let Some(ref updater) = self.wallet.get_software_updater() {
if let Some(ref update) = *updater.latest_update() {
resp.has_update = true;
resp.version = update.version().to_string();
resp.sha = update.to_hash_hex();
resp.download_url = update.download_url().to_string();
}
}

Ok(Response::new(resp))
}

async fn identify(&self, _: Request<GetIdentityRequest>) -> Result<Response<GetIdentityResponse>, Status> {
Expand Down
4 changes: 2 additions & 2 deletions base_layer/common_types/src/types/bullet_rangeproofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ use serde::{
};
use tari_utilities::{hex::*, ByteArray, ByteArrayError, Hashable};

use crate::types::HashDigest;
use crate::types::Blake256;

#[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> {
HashDigest::new().chain(&self.0).finalize().to_vec()
Blake256::new().chain(&self.0).finalize().to_vec()
}
}

Expand Down
4 changes: 2 additions & 2 deletions base_layer/common_types/src/types/fixed_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use digest::{consts::U32, generic_array, Digest};
use serde::{Deserialize, Serialize};
use tari_utilities::hex::{Hex, HexError};

use crate::types::HashDigest;
use crate::types::Blake256;

const ZERO_HASH: [u8; FixedHash::byte_size()] = [0u8; FixedHash::byte_size()];

Expand All @@ -57,7 +57,7 @@ impl FixedHash {
/// Hashes the bytes and returns the resulting `FixedHash`. Generally only be used as a convenience function for
/// tests.
pub fn hash_bytes<T: AsRef<[u8]>>(bytes: T) -> Self {
HashDigest::default().chain(bytes).finalize().into()
Blake256::default().chain(bytes).finalize().into()
}
}

Expand Down
5 changes: 1 addition & 4 deletions base_layer/common_types/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,13 @@ pub type BlindingFactor = RistrettoSecretKey;
/// Define the hash function that will be used to produce a signature challenge
pub type SignatureHasher = Blake256;

/// Specify the Hash function for general hashing
pub type HashDigest = Blake256;

/// Specify the digest type for signature challenges
pub type Challenge = Blake256;

/// The type of output that `Challenge` produces
pub type MessageHash = Vec<u8>;

/// Define the data type that is used to store results of `HashDigest`
/// Define the data type that is used to store results of a hash output
pub type HashOutput = Vec<u8>;

pub const RANGE_PROOF_BIT_LENGTH: usize = 64; // 2^64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ use std::{
use croaring::Bitmap;
use futures::{stream::FuturesUnordered, StreamExt};
use log::*;
use tari_common_types::types::{Commitment, HashDigest, RangeProofService};
use tari_common_types::types::{Commitment, RangeProofService};
use tari_comms::{connectivity::ConnectivityRequester, peer_manager::NodeId};
use tari_crypto::{
commitment::HomomorphicCommitment,
hash::blake2::Blake256,
tari_utilities::{hex::Hex, Hashable},
};
use tari_mmr::{MerkleMountainRange, MutableMmr};
Expand Down Expand Up @@ -325,7 +326,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {
.fetch_block_accumulated_data(current_header.header().prev_hash.clone())
.await?;
let kernel_pruned_set = block_data.dissolve().0;
let mut kernel_mmr = MerkleMountainRange::<HashDigest, _>::new(kernel_pruned_set);
let mut kernel_mmr = MerkleMountainRange::<Blake256, _>::new(kernel_pruned_set);

for hash in kernel_hashes.drain(..) {
kernel_mmr.push(hash)?;
Expand Down Expand Up @@ -486,8 +487,8 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {
.await?;
let (_, output_pruned_set, witness_pruned_set, _) = block_data.dissolve();

let mut output_mmr = MerkleMountainRange::<HashDigest, _>::new(output_pruned_set);
let mut witness_mmr = MerkleMountainRange::<HashDigest, _>::new(witness_pruned_set);
let mut output_mmr = MerkleMountainRange::<Blake256, _>::new(output_pruned_set);
let mut witness_mmr = MerkleMountainRange::<Blake256, _>::new(witness_pruned_set);
let mut constants = self.rules.consensus_constants(current_header.height()).clone();
let mut last_sync_timer = Instant::now();
let mut avg_latency = RollingAverageTime::new(20);
Expand Down Expand Up @@ -595,7 +596,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {
bitmap.run_optimize();

let pruned_output_set = output_mmr.get_pruned_hash_set()?;
let output_mmr = MutableMmr::<HashDigest, _>::new(pruned_output_set.clone(), bitmap.clone())?;
let output_mmr = MutableMmr::<Blake256, _>::new(pruned_output_set.clone(), bitmap.clone())?;

let mmr_root = output_mmr.get_merkle_root()?;
if mmr_root != current_header.header().output_mr {
Expand Down
7 changes: 4 additions & 3 deletions base_layer/core/src/blocks/block_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ use serde::{
};
use tari_common_types::{
array::{copy_into_fixed_array, copy_into_fixed_array_lossy},
types::{BlindingFactor, BlockHash, HashDigest, BLOCK_HASH_LENGTH},
types::{BlindingFactor, BlockHash, BLOCK_HASH_LENGTH},
};
use tari_crypto::hash::blake2::Blake256;
use tari_utilities::{epoch_time::EpochTime, hex::Hex, ByteArray, Hashable};
use thiserror::Error;

Expand Down Expand Up @@ -219,7 +220,7 @@ impl BlockHeader {
pub fn merged_mining_hash(&self) -> Vec<u8> {
if self.version <= 2 {
// TODO: Remove deprecated header hashing #testnetreset
HashDigest::new()
Blake256::new()
.chain(self.version.to_le_bytes())
.chain(self.height.to_le_bytes())
.chain(self.prev_hash.as_bytes())
Expand Down Expand Up @@ -295,7 +296,7 @@ impl From<NewBlockHeaderTemplate> for BlockHeader {
impl Hashable for BlockHeader {
fn hash(&self) -> Vec<u8> {
if self.version <= 2 {
HashDigest::new()
Blake256::new()
.chain(self.merged_mining_hash())
.chain(self.pow.to_bytes())
.chain(self.nonce.to_le_bytes())
Expand Down
17 changes: 9 additions & 8 deletions base_layer/core/src/blocks/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ pub fn get_dibbler_genesis_block() -> ChainBlock {
// NB: `dibbler_genesis_sanity_check` must pass

// use croaring::Bitmap;
// use tari_common_types::types::HashDigest;
// use tari_mmr::{MerkleMountainRange, MutableMmr};
// use tari_crypto::hash::blake2::Blake256;
//
// let mut kernel_mmr = MerkleMountainRange::<HashDigest, _>::new(Vec::new());
// let mut kernel_mmr = MerkleMountainRange::<Blake256, _>::new(Vec::new());
// for k in block.body.kernels() {
// println!("k: {}", k);
// kernel_mmr.push(k.hash()).unwrap();
// }
//
// let mut witness_mmr = MerkleMountainRange::<HashDigest, _>::new(Vec::new());
// let mut output_mmr = MutableMmr::<HashDigest, _>::new(Vec::new(), Bitmap::create()).unwrap();
// let mut witness_mmr = MerkleMountainRange::<Blake256, _>::new(Vec::new());
// let mut output_mmr = MutableMmr::<Blake256, _>::new(Vec::new(), Bitmap::create()).unwrap();
//
// for o in block.body.outputs() {
// witness_mmr.push(o.witness_hash()).unwrap();
Expand Down Expand Up @@ -316,7 +316,8 @@ fn get_dibbler_genesis_block_raw() -> Block {
#[cfg(test)]
mod test {
use croaring::Bitmap;
use tari_common_types::types::{Commitment, HashDigest};
use tari_common_types::types::Commitment;
use tari_crypto::hash::blake2::Blake256;
use tari_mmr::{MerkleMountainRange, MutableMmr};

use super::*;
Expand Down Expand Up @@ -363,13 +364,13 @@ mod test {
.any(|k| k.features.contains(KernelFeatures::COINBASE_KERNEL)));

// Check MMR
let mut kernel_mmr = MerkleMountainRange::<HashDigest, _>::new(Vec::new());
let mut kernel_mmr = MerkleMountainRange::<Blake256, _>::new(Vec::new());
for k in block.block().body.kernels() {
kernel_mmr.push(k.hash()).unwrap();
}

let mut witness_mmr = MerkleMountainRange::<HashDigest, _>::new(Vec::new());
let mut output_mmr = MutableMmr::<HashDigest, _>::new(Vec::new(), Bitmap::create()).unwrap();
let mut witness_mmr = MerkleMountainRange::<Blake256, _>::new(Vec::new());
let mut output_mmr = MutableMmr::<Blake256, _>::new(Vec::new(), Bitmap::create()).unwrap();

for o in block.block().body.outputs() {
witness_mmr.push(o.witness_hash()).unwrap();
Expand Down
11 changes: 6 additions & 5 deletions base_layer/core/src/chain_storage/blockchain_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ use log::*;
use serde::{Deserialize, Serialize};
use tari_common_types::{
chain_metadata::ChainMetadata,
types::{BlockHash, Commitment, FixedHash, HashDigest, HashOutput, PublicKey, Signature},
types::{BlockHash, Commitment, FixedHash, HashOutput, PublicKey, Signature},
};
use tari_crypto::hash::blake2::Blake256;
use tari_mmr::{pruned_hashset::PrunedHashSet, MerkleMountainRange, MutableMmr};
use tari_utilities::{epoch_time::EpochTime, hex::Hex, ByteArray, Hashable};

Expand Down Expand Up @@ -1253,10 +1254,10 @@ pub fn calculate_mmr_roots<T: BlockchainBackend>(db: &T, block: &Block) -> Resul
value: header.prev_hash.to_hex(),
})?;

let mut kernel_mmr = MerkleMountainRange::<HashDigest, _>::new(kernels);
let mut output_mmr = MutableMmr::<HashDigest, _>::new(outputs, deleted)?;
let mut witness_mmr = MerkleMountainRange::<HashDigest, _>::new(range_proofs);
let mut input_mmr = MerkleMountainRange::<HashDigest, _>::new(PrunedHashSet::default());
let mut kernel_mmr = MerkleMountainRange::<Blake256, _>::new(kernels);
let mut output_mmr = MutableMmr::<Blake256, _>::new(outputs, deleted)?;
let mut witness_mmr = MerkleMountainRange::<Blake256, _>::new(range_proofs);
let mut input_mmr = MerkleMountainRange::<Blake256, _>::new(PrunedHashSet::default());

for kernel in body.kernels().iter() {
kernel_mmr.push(kernel.hash())?;
Expand Down
8 changes: 4 additions & 4 deletions base_layer/core/src/chain_storage/lmdb_db/contract_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,16 +538,16 @@ impl Display for ContractIndexKey {

#[cfg(test)]
mod tests {
use digest::Digest;
use tari_common_types::types::HashDigest;

use super::*;
mod contract_index_key {
use blake2::Digest;
use tari_crypto::hash::blake2::Blake256;

use super::*;

#[test]
fn it_represents_a_well_formed_contract_index_key() {
let hash = HashDigest::new().chain(b"foobar").finalize().into();
let hash = Blake256::new().chain(b"foobar").finalize().into();
let key = ContractIndexKey::new(hash, OutputType::ContractCheckpoint);
assert_eq!(key.as_lmdb_bytes()[0], KeyType::PerContract as u8);
assert_eq!(key.as_lmdb_bytes()[1..33], *hash.as_slice());
Expand Down
Loading

0 comments on commit 317c0c1

Please sign in to comment.