Skip to content

Commit

Permalink
Merge branch 'development' into qtari-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
stringhandler committed Apr 15, 2024
2 parents 9189e85 + b5f2c46 commit 10cbb61
Show file tree
Hide file tree
Showing 24 changed files with 484 additions and 267 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/base_node_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ jobs:
run: |
echo "VBRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
echo "VSHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
TARI_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/["]/, "", $2); printf("%s",$2) }' "$GITHUB_WORKSPACE/applications/minotari_node/Cargo.toml")
TARI_VERSION=$(awk -F ' = ' '$1 ~ /^version/ \
{ gsub(/["]/, "", $2); printf("%s",$2) }' \
"$GITHUB_WORKSPACE/applications/minotari_node/Cargo.toml")
echo "TARI_VERSION=${TARI_VERSION}" >> $GITHUB_ENV
echo "TARI_VERSION=${TARI_VERSION}" >> $GITHUB_OUTPUT
if [[ "${{ matrix.builds.features }}" == "" ]]; then
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/build_dockers_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ jobs:
if [ -z "${{ inputs.version }}" ] ; then
echo "Get tari version"
TARI_SOURCE_ROOT="tari/"
VAPP=$(awk -F ' = ' \
'$1 ~ /version/ { gsub(/["]/, "", $2); printf("%s",$2) }' \
VAPP=$(awk -F ' = ' '$1 ~ /^version/ \
{ gsub(/["]/, "", $2); printf("%s",$2) }' \
"${TARI_SOURCE_ROOT}/applications/minotari_node/Cargo.toml")
VBRANCH=$(git --git-dir ${TARI_SOURCE_ROOT}/.git branch --show-current)
VSHA_SHORT=$(git --git-dir ${TARI_SOURCE_ROOT}/.git rev-parse --short HEAD)
VERSION="v${VAPP}_${VBRANCH}_$(date -u '+%Y%m%d')_${VSHA_SHORT}"
Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/build_libffis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
## build only single target image
# matrix_selection=$( jq -c '.[] | select( ."runs-on" == "ubuntu-latest" )' ${{ env.matrix-json-file }} )
# matrix_selection=$( jq -c '.[] | select( ."target" == "x86_64-linux-android" )' ${{ env.matrix-json-file }} )
# matrix_selection=$( jq -c '.[] | select( ."target" | contains("android") )' ${{ env.matrix-json-file }} )
#
## buid select target images - build_enabled
matrix_selection=$( jq -c '.[] | select( ."build_enabled" != false )' ${{ env.matrix-json-file }} )
Expand Down Expand Up @@ -225,9 +226,12 @@ jobs:
path: ${{ runner.temp }}/lib${{ matrix.libffis }}-${{ env.TARGET_PLATFORM }}-${{ env.TARGET_ARCH }}${{ env.TARGET_SIM }}

ios_assemble:
name: Assemble iOS multiArch for ${{ matrix.libffis }}"
name: Assemble iOS multiArch for ${{ matrix.libffis }}
# Disable iOS Assembly workflow
#if: ${{ false }}
#continue-on-error: true

# Limits to only iOS builds
# Limits to only iOS builds?
runs-on: macos-latest
needs: [matrix-prep, builds]

Expand Down Expand Up @@ -353,9 +357,11 @@ jobs:

create_release:
name: Create release for ffi libraries
if: ${{ startsWith(github.ref, 'refs/tags/v') }}

runs-on: ubuntu-latest
needs: [matrix-prep, builds, ios_assemble]
if: ${{ startsWith(github.ref, 'refs/tags/v') }}

steps:
- name: Download all ffi libraries
uses: actions/download-artifact@v4
Expand Down
2 changes: 2 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ passthrough = [
"FEATURES",
"ROARING_ARCH",
"TARI_NETWORK",
"TARI_TARGET_NETWORK",
"TARI_NETWORK_DIR",
]

# Don't forget export:
Expand Down
9 changes: 8 additions & 1 deletion applications/minotari_node/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
// 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::{cmp, str::FromStr, sync::Arc, time::Duration};
use std::{
cmp,
str::FromStr,
sync::{Arc, RwLock},
time::Duration,
};

use log::*;
use minotari_app_utilities::{consts, identity_management, identity_management::load_from_json};
Expand Down Expand Up @@ -52,6 +57,7 @@ use tari_core::{
mempool::{service::MempoolHandle, Mempool, MempoolServiceInitializer, MempoolSyncInitializer},
proof_of_work::randomx_factory::RandomXFactory,
transactions::CryptoFactories,
OutputSmt,
};
use tari_p2p::{
auto_update::SoftwareUpdaterService,
Expand Down Expand Up @@ -81,6 +87,7 @@ pub struct BaseNodeBootstrapper<'a, B> {
pub factories: CryptoFactories,
pub randomx_factory: RandomXFactory,
pub interrupt_signal: ShutdownSignal,
pub smt: Arc<RwLock<OutputSmt>>,
}

impl<B> BaseNodeBootstrapper<'_, B>
Expand Down
6 changes: 5 additions & 1 deletion applications/minotari_node/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// 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::sync::Arc;
use std::sync::{Arc, RwLock};

use log::*;
use tari_common::{
Expand All @@ -42,6 +42,7 @@ use tari_core::{
transaction::TransactionFullValidator,
DifficultyCalculator,
},
OutputSmt,
};
use tari_p2p::{auto_update::SoftwareUpdaterHandle, services::liveness::LivenessHandle};
use tari_service_framework::ServiceHandles;
Expand Down Expand Up @@ -210,6 +211,7 @@ async fn build_node_context(
let factories = CryptoFactories::default();
let randomx_factory = RandomXFactory::new(app_config.base_node.max_randomx_vms);
let difficulty_calculator = DifficultyCalculator::new(rules.clone(), randomx_factory.clone());
let smt = Arc::new(RwLock::new(OutputSmt::new()));
let validators = Validators::new(
BlockBodyFullValidator::new(rules.clone(), true),
HeaderFullValidator::new(rules.clone(), difficulty_calculator.clone()),
Expand All @@ -226,6 +228,7 @@ async fn build_node_context(
validators,
app_config.base_node.storage,
difficulty_calculator,
smt.clone(),
)
.map_err(|err| {
if let ChainStorageError::DatabaseResyncRequired(reason) = err {
Expand Down Expand Up @@ -262,6 +265,7 @@ async fn build_node_context(
factories: factories.clone(),
randomx_factory,
interrupt_signal: interrupt_signal.clone(),
smt,
}
.bootstrap()
.await?;
Expand Down
7 changes: 6 additions & 1 deletion applications/minotari_node/src/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::{
env::temp_dir,
fs,
io::{self, Write},
sync::Arc,
sync::{Arc, RwLock},
};

use anyhow::anyhow;
Expand Down Expand Up @@ -53,6 +53,7 @@ use tari_core::{
mocks::MockValidator,
DifficultyCalculator,
},
OutputSmt,
};

use crate::{BaseNodeConfig, DatabaseType};
Expand Down Expand Up @@ -97,6 +98,7 @@ pub async fn run_recovery(node_config: &BaseNodeConfig) -> Result<(), anyhow::Er
let factories = CryptoFactories::default();
let randomx_factory = RandomXFactory::new(node_config.max_randomx_vms);
let difficulty_calculator = DifficultyCalculator::new(rules.clone(), randomx_factory);
let smt = Arc::new(RwLock::new(OutputSmt::new()));
let validators = Validators::new(
BlockBodyFullValidator::new(rules.clone(), true),
HeaderFullValidator::new(rules.clone(), difficulty_calculator.clone()),
Expand All @@ -114,6 +116,7 @@ pub async fn run_recovery(node_config: &BaseNodeConfig) -> Result<(), anyhow::Er
validators,
node_config.storage,
difficulty_calculator,
smt,
)?;
do_recovery(db.into(), temp_db).await?;

Expand Down Expand Up @@ -142,12 +145,14 @@ async fn do_recovery<D: BlockchainBackend + 'static>(
MockValidator::new(true),
MockValidator::new(true),
);
let smt = Arc::new(RwLock::new(OutputSmt::new()));
let source_database = BlockchainDatabase::new(
source_backend,
rules.clone(),
validators,
BlockchainDatabaseConfig::default(),
DifficultyCalculator::new(rules, Default::default()),
smt,
)?;
let max_height = source_database
.get_chain_metadata()
Expand Down
5 changes: 3 additions & 2 deletions base_layer/core/src/base_node/sync/block_sync/synchronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ impl<'a, B: BlockchainBackend + 'static> BlockSynchronizer<'a, B> {
let validator = self.block_validator.clone();
let res = task::spawn_blocking(move || {
let txn = db.db_read_access()?;
validator.validate_body(&*txn, &task_block)
let smt = db.smt().clone();
validator.validate_body(&*txn, &task_block, smt)
})
.await?;

Expand Down Expand Up @@ -367,7 +368,7 @@ impl<'a, B: BlockchainBackend + 'static> BlockSynchronizer<'a, B> {
self.db
.write_transaction()
.delete_orphan(header_hash)
.insert_tip_block_body(block.clone())
.insert_tip_block_body(block.clone(), self.db.inner().smt())
.set_best_block(
block.height(),
header_hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,14 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {
debug!(target: LOG_TARGET, "Synchronizing kernels");
self.synchronize_kernels(sync_peer.clone(), client, to_header).await?;
debug!(target: LOG_TARGET, "Synchronizing outputs");
let cloned_backup_smt = self.db.inner().smt_read_access()?.clone();
match self.synchronize_outputs(sync_peer, client, to_header).await {
Ok(_) => Ok(()),
Err(err) => {
// We need to clean up the outputs
let _ = self.clean_up_failed_output_sync(to_header).await;
let mut smt = self.db.inner().smt_write_access()?;
*smt = cloned_backup_smt;
Err(err)
},
}
Expand Down Expand Up @@ -618,7 +621,7 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {
let mut utxo_counter = 0u64;
let mut stxo_counter = 0u64;
let timer = Instant::now();
let mut output_smt = db.fetch_tip_smt().await?;
let mut output_smt = (*db.inner().smt_write_access()?).clone();
let mut last_sync_timer = Instant::now();
let mut avg_latency = RollingAverageTime::new(20);

Expand Down Expand Up @@ -766,8 +769,8 @@ impl<'a, B: BlockchainBackend + 'static> HorizonStateSynchronization<'a, B> {
txn.commit().await?;
}
}
// This has a very low probability of failure
db.set_tip_smt(output_smt).await?;
let mut writing_lock_output_smt = db.inner().smt_write_access()?;
*writing_lock_output_smt = output_smt;
debug!(
target: LOG_TARGET,
"Finished syncing TXOs: {} unspent and {} spent downloaded in {:.2?}",
Expand Down
15 changes: 8 additions & 7 deletions base_layer/core/src/chain_storage/async_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// 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::{mem, ops::RangeBounds, sync::Arc, time::Instant};
use std::{
mem,
ops::RangeBounds,
sync::{Arc, RwLock},
time::Instant,
};

use log::*;
use primitive_types::U256;
Expand Down Expand Up @@ -222,10 +227,6 @@ impl<B: BlockchainBackend + 'static> AsyncBlockchainDb<B> {

make_async_fn!(fetch_tip_header() -> ChainHeader, "fetch_tip_header");

make_async_fn!(fetch_tip_smt() -> OutputSmt, "fetch_tip_smt");

make_async_fn!(set_tip_smt(smt: OutputSmt) -> (), "set_tip_smt");

make_async_fn!(insert_valid_headers(headers: Vec<ChainHeader>) -> (), "insert_valid_headers");

//---------------------------------- Block --------------------------------------------//
Expand Down Expand Up @@ -393,8 +394,8 @@ impl<'a, B: BlockchainBackend + 'static> AsyncDbTransaction<'a, B> {
self
}

pub fn insert_tip_block_body(&mut self, block: Arc<ChainBlock>) -> &mut Self {
self.transaction.insert_tip_block_body(block);
pub fn insert_tip_block_body(&mut self, block: Arc<ChainBlock>, smt: Arc<RwLock<OutputSmt>>) -> &mut Self {
self.transaction.insert_tip_block_body(block, smt);
self
}

Expand Down
6 changes: 3 additions & 3 deletions base_layer/core/src/chain_storage/blockchain_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub trait BlockchainBackend: Send + Sync {
fn fetch_outputs_in_block_with_spend_state(
&self,
header_hash: &HashOutput,
spend_status_at_header: Option<HashOutput>,
spend_status_at_header: Option<&HashOutput>,
) -> Result<Vec<(TransactionOutput, bool)>, ChainStorageError>;

/// Fetch a specific output. Returns the output
Expand Down Expand Up @@ -181,6 +181,6 @@ pub trait BlockchainBackend: Send + Sync {
start_height: u64,
end_height: u64,
) -> Result<Vec<TemplateRegistrationEntry>, ChainStorageError>;
/// Returns the tip utxo smt
fn fetch_tip_smt(&self) -> Result<OutputSmt, ChainStorageError>;
/// Calculates the tip utxo smt
fn calculate_tip_smt(&self) -> Result<OutputSmt, ChainStorageError>;
}
Loading

0 comments on commit 10cbb61

Please sign in to comment.