Skip to content

Commit

Permalink
chore!: upgrade to latest feature-dan2 (#918)
Browse files Browse the repository at this point in the history
Description
---

Upgrades this repo to use latest code from feature-dan2
Updates libp2p and our sr25519 implementation to latest tari-crypto
Update cucumber mining code
Update signature challenge for claim burn
Add network to domain hashes and block

Motivation and Context
---
Updates to use changes from update PR
tari-project/tari#6103
How Has This Been Tested?
---
CI, manually

What process can a PR reviewer use to test or verify this change?
---
Should work as before

Breaking Changes
---

- [ ] None
- [x] Requires data directory to be deleted
- [ ] Other - Please specify
  • Loading branch information
sdbondi committed Jan 30, 2024
1 parent 7772efa commit b526c09
Show file tree
Hide file tree
Showing 60 changed files with 1,191 additions and 682 deletions.
789 changes: 417 additions & 372 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions Cargo.toml
Expand Up @@ -103,6 +103,7 @@ tari_wallet_daemon_client = { path = "clients/wallet_daemon_client" }
transaction_generator = { path = "utilities/transaction_generator" }

# external minotari/tari dependencies
tari_hash_domains = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
minotari_app_grpc = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
minotari_app_utilities = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
minotari_console_wallet = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
Expand All @@ -115,14 +116,14 @@ tari_common_types = { git = "https://github.com/tari-project/tari.git", branch =

# avoid including default features so each crate can choose which ones to import
tari_core = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2", default-features = false }
tari_crypto = "0.19"
tari_crypto = "0.20.0"
tari_key_manager = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
tari_metrics = { git = "https://github.com/tari-project/tari.git" }
tari_metrics = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
tari_mmr = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
tari_p2p = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
tari_shutdown = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
tari_storage = { git = "https://github.com/tari-project/tari.git", branch = "feature-dan2" }
tari_utilities = "0.6"
tari_utilities = "0.7.0"

# third-party dependencies
anyhow = "1.0.75"
Expand All @@ -136,7 +137,7 @@ bigdecimal = "0.4.1"
bincode = "2.0.0-rc.3"
bitflags = "2.4"
blake2 = "0.10.6"
borsh = "0.10"
borsh = "1.3"
bytes = "1.5"
cacache = "12.0.0"
cargo_metadata = "0.15.3"
Expand Down Expand Up @@ -174,7 +175,7 @@ itertools = "0.11.0"
lazy_static = "1.4.0"
libp2p = "0.53.1"
# Adds support for Schnorr-Ristretto (sr25519)
libp2p-identity = { git = "https://github.com/tari-project/rust-libp2p.git", rev = "5459d4d7cc79437d091fe3e390e8609a5ac06ea3" }
libp2p-identity = "0.2.8"
libsqlite3-sys = "0.25"
liquid = "0.26.4"
lmdb-zero = "0.4.4"
Expand Down Expand Up @@ -209,7 +210,7 @@ time = "0.3.15"
tokio = { version = "1.34", default-features = false }
tokio-stream = "0.1.7"
tokio-util = "0.7.10"
tonic = "0.6.2"
tonic = "0.8.3"
tower = "0.4"
tower-http = { version = "0.3.5", default-features = false }
tower-layer = "0.3"
Expand All @@ -236,14 +237,13 @@ overflow-checks = true
# Temporarily lock pgp to commit (master branch at time of writing) because the currently released crate locks zeroize to =1.3
liblmdb-sys = { git = "https://github.com/tari-project/lmdb-rs", tag = "0.7.6-tari.1" }
# Use Tari's libp2p fork that adds support for Schnorr-Ristretto
multiaddr = { git = "https://github.com/tari-project/rust-libp2p.git", rev = "5459d4d7cc79437d091fe3e390e8609a5ac06ea3" }
multiaddr = { git = "https://github.com/tari-project/rust-libp2p.git", rev = "9b73988f611a877595de8a4a205aa86fb78cd626" }
#libp2p = { git = "https://github.com/tari-project/rust-libp2p.git", rev = "ae1c06a9615a0ac020e459904ec984a6ab253678" }
libp2p-identity = { git = "https://github.com/tari-project/rust-libp2p.git", rev = "5459d4d7cc79437d091fe3e390e8609a5ac06ea3" }
libp2p-identity = { git = "https://github.com/tari-project/rust-libp2p.git", rev = "9b73988f611a877595de8a4a205aa86fb78cd626" }

# Make a copy of this code, uncomment and replace account and my-branch with the name of your fork and the branch you want to temporarily use
#[patch."https://github.com/tari-project/tari.git"]
#minotari_app_grpc = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#minotari_app_grpc = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#minotari_wallet_grpc_client= { git = "https://github.com/account/tari.git", branch = "my-branch" }
#minotari_node_grpc_client = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_common = { git = "https://github.com/account/tari.git", branch = "my-branch" }
Expand All @@ -256,9 +256,12 @@ libp2p-identity = { git = "https://github.com/tari-project/rust-libp2p.git", rev
#tari_p2p = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_shutdown = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_storage = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#minotari_wallet_grpc_client = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_script = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#minotari_wallet = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#minotari_console_wallet = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_service_framework = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_comms_dht = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#minotari_app_utilities = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#minotari_node = { git = "https://github.com/account/tari.git", branch = "my-branch" }
#tari_metrics = { git = "https://github.com/account/tari.git", branch = "my-branch" }

Expand Up @@ -29,6 +29,7 @@ use tari_base_node_client::{
BaseNodeClient,
BaseNodeClientError,
};
use tari_common::configuration::Network;
use tari_common_types::types::{Commitment, FixedHash, FixedHashSizeError};
use tari_core::transactions::transaction_components::{
CodeTemplateRegistration,
Expand Down Expand Up @@ -63,6 +64,7 @@ use crate::{
const LOG_TARGET: &str = "tari::dan::base_layer_scanner";

pub fn spawn<TAddr: NodeAddressable + 'static>(
network: Network,
global_db: GlobalDb<SqliteGlobalDbAdapter<TAddr>>,
base_node_client: GrpcBaseNodeClient,
epoch_manager: EpochManagerHandle<TAddr>,
Expand All @@ -75,6 +77,7 @@ pub fn spawn<TAddr: NodeAddressable + 'static>(
) -> JoinHandle<anyhow::Result<()>> {
task::spawn(async move {
let base_layer_scanner = BaseLayerScanner::new(
network,
global_db,
base_node_client,
epoch_manager,
Expand All @@ -92,6 +95,7 @@ pub fn spawn<TAddr: NodeAddressable + 'static>(
}

pub struct BaseLayerScanner<TAddr> {
network: Network,
global_db: GlobalDb<SqliteGlobalDbAdapter<TAddr>>,
last_scanned_height: u64,
last_scanned_tip: Option<FixedHash>,
Expand All @@ -110,6 +114,7 @@ pub struct BaseLayerScanner<TAddr> {

impl<TAddr: NodeAddressable + 'static> BaseLayerScanner<TAddr> {
pub fn new(
network: Network,
global_db: GlobalDb<SqliteGlobalDbAdapter<TAddr>>,
base_node_client: GrpcBaseNodeClient,
epoch_manager: EpochManagerHandle<TAddr>,
Expand All @@ -121,6 +126,7 @@ impl<TAddr: NodeAddressable + 'static> BaseLayerScanner<TAddr> {
base_layer_scanning_interval: Duration,
) -> Self {
Self {
network,
global_db,
last_scanned_tip: None,
last_scanned_height: 0,
Expand Down Expand Up @@ -374,7 +380,7 @@ impl<TAddr: NodeAddressable + 'static> BaseLayerScanner<TAddr> {
});
self.state_store
.with_write_tx(|tx| {
let genesis = Block::genesis();
let genesis = Block::genesis(self.network);

// TODO: This should be proposed in a block...
SubstateRecord {
Expand Down
Expand Up @@ -4,6 +4,7 @@
use std::{sync::Arc, time::Instant};

use log::*;
use tari_common::configuration::Network;
use tari_common_types::types::PublicKey;
use tari_crypto::tari_utilities::ByteArray;
use tari_dan_common_types::{services::template_provider::TemplateProvider, SubstateAddress};
Expand Down Expand Up @@ -36,13 +37,15 @@ pub trait TransactionExecutor {
pub struct TariDanTransactionProcessor<TTemplateProvider> {
template_provider: Arc<TTemplateProvider>,
fee_table: FeeTable,
network: Network,
}

impl<TTemplateProvider> TariDanTransactionProcessor<TTemplateProvider> {
pub fn new(template_provider: TTemplateProvider, fee_table: FeeTable) -> Self {
pub fn new(network: Network, template_provider: TTemplateProvider, fee_table: FeeTable) -> Self {
Self {
template_provider: Arc::new(template_provider),
fee_table,
network,
}
}
}
Expand Down Expand Up @@ -74,6 +77,7 @@ where TTemplateProvider: TemplateProvider<Template = LoadedTemplate>
auth_params,
virtual_substates,
modules,
self.network,
);
let tx_id = transaction.hash();
let result = match processor.execute(transaction.clone()) {
Expand Down
2 changes: 2 additions & 0 deletions applications/tari_indexer/src/bootstrap.rs
Expand Up @@ -112,6 +112,7 @@ pub async fn spawn_services(
// Epoch manager
let validator_node_client_factory = TariValidatorNodeRpcClientFactory::new(networking.clone());
let (epoch_manager, _) = tari_epoch_manager::base_layer::spawn_service(
config.network,
EpochManagerConfig {
base_layer_confirmations: consensus_constants.base_layer_confirmations,
committee_size: consensus_constants.committee_size,
Expand All @@ -129,6 +130,7 @@ pub async fn spawn_services(

// Base Node scanner
base_layer_scanner::spawn(
config.network,
global_db,
base_node_client.clone(),
epoch_manager.clone(),
Expand Down
6 changes: 5 additions & 1 deletion applications/tari_indexer/src/dry_run/processor.rs
Expand Up @@ -23,6 +23,7 @@
use std::{collections::HashMap, sync::Arc};

use log::info;
use tari_common::configuration::Network;
use tari_dan_app_utilities::{
template_manager::implementation::TemplateManager,
transaction_executor::{TariDanTransactionProcessor, TransactionExecutor},
Expand Down Expand Up @@ -67,6 +68,7 @@ pub struct DryRunTransactionProcessor<TSubstateCache> {
template_manager: TemplateManager<PeerAddress>,
substate_scanner:
Arc<SubstateScanner<EpochManagerHandle<PeerAddress>, TariValidatorNodeRpcClientFactory, TSubstateCache>>,
network: Network,
}

impl<TSubstateCache> DryRunTransactionProcessor<TSubstateCache>
Expand All @@ -79,6 +81,7 @@ where TSubstateCache: SubstateCache + 'static
SubstateScanner<EpochManagerHandle<PeerAddress>, TariValidatorNodeRpcClientFactory, TSubstateCache>,
>,
template_manager: TemplateManager<PeerAddress>,
network: Network,
) -> Self {
let transaction_autofiller = TransactionAutofiller::new(substate_scanner.clone());

Expand All @@ -88,6 +91,7 @@ where TSubstateCache: SubstateCache + 'static
transaction_autofiller,
template_manager,
substate_scanner,
network,
}
}

Expand Down Expand Up @@ -138,7 +142,7 @@ where TSubstateCache: SubstateCache + 'static
FeeTable::zero_rated()
};

TariDanTransactionProcessor::new(self.template_manager.clone(), fee_table)
TariDanTransactionProcessor::new(self.network, self.template_manager.clone(), fee_table)
}

fn transaction_includes_fees(transaction: &Transaction) -> bool {
Expand Down
1 change: 1 addition & 0 deletions applications/tari_indexer/src/lib.rs
Expand Up @@ -126,6 +126,7 @@ pub async fn run_indexer(config: ApplicationConfig, mut shutdown_signal: Shutdow
services.validator_node_client_factory.clone(),
dan_layer_scanner,
services.template_manager.clone(),
config.network,
);

// Run the JSON-RPC API
Expand Down
16 changes: 11 additions & 5 deletions applications/tari_validator_node/src/bootstrap.rs
Expand Up @@ -31,7 +31,10 @@ use serde::Serialize;
use sqlite_message_logger::SqliteMessageLogger;
use tari_base_node_client::grpc::GrpcBaseNodeClient;
use tari_common::{
configuration::bootstrap::{grpc_default_port, ApplicationType},
configuration::{
bootstrap::{grpc_default_port, ApplicationType},
Network,
},
exit_codes::{ExitCode, ExitError},
};
use tari_common_types::types::PublicKey;
Expand Down Expand Up @@ -182,10 +185,11 @@ pub async fn spawn_services(
// Connect to shard db
let state_store =
SqliteStateStore::connect(&format!("sqlite://{}", config.validator_node.state_db_path().display()))?;
state_store.with_write_tx(|tx| bootstrap_state(tx))?;
state_store.with_write_tx(|tx| bootstrap_state(tx, config.network))?;

// Epoch manager
let (epoch_manager, join_handle) = tari_epoch_manager::base_layer::spawn_service(
config.network,
// TODO: We should be able to pass consensus constants here. However, these are currently located in dan_core
// which depends on epoch_manager, so would be a circular dependency.
EpochManagerConfig {
Expand Down Expand Up @@ -219,7 +223,7 @@ pub async fn spawn_services(
per_log_cost: 1,
}
};
let payload_processor = TariDanTransactionProcessor::new(template_manager.clone(), fee_table);
let payload_processor = TariDanTransactionProcessor::new(config.network, template_manager.clone(), fee_table);

let validator_node_client_factory = TariValidatorNodeRpcClientFactory::new(networking.clone());

Expand All @@ -238,6 +242,7 @@ pub async fn spawn_services(
ConsensusOutboundMessaging::new(loopback_sender, networking.clone(), message_logger.clone());

let (consensus_join_handle, consensus_handle, rx_consensus_to_mempool) = consensus::spawn(
config.network,
state_store.clone(),
keypair.clone(),
epoch_manager.clone(),
Expand Down Expand Up @@ -291,6 +296,7 @@ pub async fn spawn_services(

// Base Node scanner
let join_handle = base_layer_scanner::spawn(
config.network,
global_db.clone(),
base_node_client.clone(),
epoch_manager.clone(),
Expand Down Expand Up @@ -433,13 +439,13 @@ async fn spawn_p2p_rpc(
}

// TODO: Figure out the best way to have the engine shard store mirror these bootstrapped states.
fn bootstrap_state<TTx>(tx: &mut TTx) -> Result<(), StorageError>
fn bootstrap_state<TTx>(tx: &mut TTx, network: Network) -> Result<(), StorageError>
where
TTx: StateStoreWriteTransaction + DerefMut,
TTx::Target: StateStoreReadTransaction,
TTx::Addr: NodeAddressable + Serialize,
{
let genesis_block = Block::genesis();
let genesis_block = Block::genesis(network);
let substate_id = SubstateId::Resource(PUBLIC_IDENTITY_RESOURCE_ADDRESS);
let substate_address = SubstateAddress::from_address(&substate_id, 0);
let mut metadata: Metadata = Default::default();
Expand Down
5 changes: 4 additions & 1 deletion applications/tari_validator_node/src/consensus/mod.rs
@@ -1,6 +1,7 @@
// Copyright 2023 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use tari_common::configuration::Network;
use tari_consensus::hotstuff::{ConsensusWorker, ConsensusWorkerContext, HotstuffWorker};
use tari_dan_storage::consensus_models::TransactionPool;
use tari_epoch_manager::base_layer::EpochManagerHandle;
Expand Down Expand Up @@ -38,6 +39,7 @@ use tari_rpc_state_sync::RpcStateSyncManager;
use crate::p2p::services::messaging::{ConsensusInboundMessaging, ConsensusOutboundMessaging};

pub async fn spawn(
network: Network,
store: SqliteStateStore<PeerAddress>,
keypair: RistrettoKeypair,
epoch_manager: EpochManagerHandle<PeerAddress>,
Expand All @@ -62,6 +64,7 @@ pub async fn spawn(

let hotstuff_worker = HotstuffWorker::<TariConsensusSpec>::new(
validator_addr,
network,
inbound_messaging,
outbound_messaging,
rx_new_transactions,
Expand All @@ -80,7 +83,7 @@ pub async fn spawn(
let context = ConsensusWorkerContext {
epoch_manager: epoch_manager.clone(),
hotstuff: hotstuff_worker,
state_sync: RpcStateSyncManager::new(epoch_manager, store, leader_strategy, client_factory),
state_sync: RpcStateSyncManager::new(network, epoch_manager, store, leader_strategy, client_factory),
tx_current_state,
};

Expand Down
10 changes: 3 additions & 7 deletions applications/tari_validator_node/src/lib.rs
Expand Up @@ -147,17 +147,13 @@ pub async fn run_validator_node(config: &ApplicationConfig, shutdown_signal: Shu

fs::write(config.common.base_path.join("pid"), process::id().to_string())
.map_err(|e| ExitError::new(ExitCode::UnknownError, e))?;
run_dan_node(services, shutdown_signal).await?;

Ok(())
}

async fn run_dan_node(services: Services, shutdown_signal: ShutdownSignal) -> Result<(), ExitError> {
let node = DanNode::new(services);
info!(target: LOG_TARGET, "🚀 Validator node started!");
node.start(shutdown_signal)
.await
.map_err(|e| ExitError::new(ExitCode::UnknownError, e))
.map_err(|e| ExitError::new(ExitCode::UnknownError, e))?;

Ok(())
}

async fn create_base_layer_clients(
Expand Down
2 changes: 2 additions & 0 deletions dan_layer/common_types/Cargo.toml
Expand Up @@ -7,9 +7,11 @@ repository.workspace = true
license.workspace = true

[dependencies]
tari_common = { workspace = true }
tari_common_types = { workspace = true }
tari_crypto = { workspace = true, features = ["borsh"] }
tari_engine_types = { workspace = true }
tari_hash_domains = { workspace = true }
tari_bor = { workspace = true, default-features = true }
tari_mmr = { workspace = true }
tari_core = { workspace = true, default-features = false, features = [
Expand Down
7 changes: 1 addition & 6 deletions dan_layer/common_types/src/hashing.rs
Expand Up @@ -25,6 +25,7 @@

use blake2::{digest::consts::U32, Blake2b};
use tari_crypto::{hash_domain, hashing::DomainSeparatedHasher};
use tari_hash_domains::ValidatorNodeBmtHashDomain;
use tari_mmr::{BalancedBinaryMerkleProof, BalancedBinaryMerkleTree, MergedBalancedBinaryMerkleProof};

use crate::hasher::{tari_hasher, TariHasher};
Expand Down Expand Up @@ -55,12 +56,6 @@ fn dan_hasher(label: &'static str) -> TariHasher {
tari_hasher::<TariDanConsensusHashDomain>(label)
}

// From tari_core
hash_domain!(
ValidatorNodeBmtHashDomain,
"com.tari.base_layer.core.validator_node_mmr",
1
);
pub type ValidatorNodeBmtHasherBlake2b = DomainSeparatedHasher<Blake2b<U32>, ValidatorNodeBmtHashDomain>;
pub type ValidatorNodeBalancedMerkleTree = BalancedBinaryMerkleTree<ValidatorNodeBmtHasherBlake2b>;
pub type ValidatorNodeMerkleProof = BalancedBinaryMerkleProof<ValidatorNodeBmtHasherBlake2b>;
Expand Down

0 comments on commit b526c09

Please sign in to comment.