Skip to content

Commit

Permalink
feat: multi-network ci (#6162)
Browse files Browse the repository at this point in the history
When formally implementing compiler features, the setting of the
`TARI_NETWORK` and (from now) `TARI_TARGET_NETWORK` envar and the
related compiler flags matter.

These changes require that when tests run, the correct network flags are
set.

For example,
`blocks::genesis_block::test::stagenet_genesis_sanity_check` should only
run when `TARI_NETWORK=stagenet`.

The current setup reveals a problem:
There is not a 1:1 mapping between the build _target_ and the actual
network the binary may run on. E.g. the mainnet build can run on either
stagenet or mainnet.

Unfortunately the `TARI_NETWORK` envar was used to set both of these
variables.

Since these are 2 different things, this commit introduced
`TARI_TARGET_NETWORK` which sets the **build target**. In most contexts,
this then decouples the configured network, which is specified by the
`TARI_NETWORK` envar as usual.

The other changes in this commit revolve around updating merkle roots
and the correct faucet sets to make the target/network/faucet
combination consistent.

The CI is configured to run tests for each of `{target} ({network})`
* Testnet (Esme)
* Nextnet (Nextnet)
* Mainnet (Stagenet)

Description
---

This replaces part of #6131 

Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
CjS77 committed Feb 26, 2024
1 parent 5c5da46 commit 8990b57
Show file tree
Hide file tree
Showing 27 changed files with 287 additions and 51 deletions.
12 changes: 12 additions & 0 deletions .config/nextest.toml
Expand Up @@ -3,3 +3,15 @@ slow-timeout = { period = "60s", terminate-after=2}

[profile.ci.junit] # this can be some other profile, too
path = "junit.xml"

[profile.intellij]
retries = 0
slow-timeout = { period = "30s" }
failure-output = "immediate-final"
fail-fast = false

[profile.intellij.junit] # this can be some other profile, too
path = "junit.xml"



2 changes: 2 additions & 0 deletions .github/workflows/base_node_binaries.yml
Expand Up @@ -109,8 +109,10 @@ jobs:
run: |
source buildtools/multinet_envs.sh ${{ env.GHA_NETWORK }}
echo ${TARI_NETWORK}
echo ${TARI_TARGET_NETWORK}
echo ${TARI_NETWORK_DIR}
echo "TARI_NETWORK=${TARI_NETWORK}" >> $GITHUB_ENV
echo "TARI_TARGET_NETWORK=${TARI_TARGET_NETWORK}" >> $GITHUB_ENV
echo "TARI_NETWORK_DIR=${TARI_NETWORK_DIR}" >> $GITHUB_ENV
echo "TARI_NETWORK_DIR=${TARI_NETWORK_DIR}" >> $GITHUB_OUTPUT
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build_dockers_workflow.yml
Expand Up @@ -119,6 +119,8 @@ jobs:
source tari/buildtools/multinet_envs.sh ${{github.ref_name}}
echo ${TARI_NETWORK}
echo "TARI_NETWORK=${TARI_NETWORK}" >> $GITHUB_ENV
echo ${TARI_TARGET_NETWORK}
echo "TARI_TARGET_NETWORK=${TARI_TARGET_NETWORK}" >> $GITHUB_ENV
- name: environment setup
shell: bash
Expand Down Expand Up @@ -225,6 +227,7 @@ jobs:
APP_NAME=${{ matrix.builds.app_name }}
APP_EXEC=${{ matrix.builds.app_exec }}
TARI_NETWORK=${{ env.TARI_NETWORK }}
TARI_TARGET_NETWORK=${{ env.TARI_TARGET_NETWORK }}
${{ env.DOCKER_SUBTAG }}
tags: |
${{ steps.meta.outputs.tags }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build_libffis.yml
Expand Up @@ -102,8 +102,10 @@ jobs:
run: |
source buildtools/multinet_envs.sh ${{ github.ref_name }}
echo ${TARI_NETWORK}
echo ${TARI_TARGET_NETWORK}
echo ${TARI_NETWORK_CHANGELOG}
echo "TARI_NETWORK=${TARI_NETWORK}" >> $GITHUB_ENV
echo "TARI_TARGET_NETWORK=${TARI_TARGET_NETWORK}" >> $GITHUB_ENV
echo "TARI_NETWORK_CHANGELOG=${TARI_NETWORK_CHANGELOG}" >> $GITHUB_ENV
- name: Declare Android/iOS envs
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -167,6 +167,17 @@ jobs:
permissions:
checks: write
pull-requests: write
strategy:
matrix:
tari_target_network: [
{ target: "testnet", network: "esmeralda" },
{ target: "nextnet", network: "nextnet" },
{ target: "mainnet", network: "stagenet" },
]
env:
TARI_TARGET_NETWORK: ${{ matrix.tari_target_network.target }}
TARI_NETWORK: ${{ matrix.tari_target_network.network }}
RUST_LOG: debug
steps:
- name: checkout
uses: actions/checkout@v4
Expand All @@ -192,21 +203,22 @@ jobs:
~/.cargo/registry/CACHEDIR.TAG
~/.cargo/git
target
key: tari-${{ runner.os }}-${{ runner.cpu-model }}-${{ env.toolchain }}-nightly-${{ hashFiles('**/Cargo.lock') }}
key: tari-${{ runner.os }}-${{ runner.cpu-model }}-${{ env.toolchain }}-nightly-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.tari_target_network.target }}
restore-keys: |
tari-${{ runner.os }}-${{ runner.cpu-model }}-${{ env.toolchain }}-nightly-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.tari_target_network.network }}
tari-${{ runner.os }}-${{ runner.cpu-model }}-${{ env.toolchain }}-nightly-${{ hashFiles('**/Cargo.lock') }}
tari-${{ runner.os }}-${{ runner.cpu-model }}-${{ env.toolchain }}-nightly
- name: Install cargo-nextest
run: cargo install cargo-nextest --locked --force
- name: cargo test compile
run: cargo test --no-run --locked --all-features --release
run: cargo test -vv --no-run --locked --all-features --release
- name: cargo test
run: cargo nextest run --all-features --release -E "not package(tari_integration_tests)" --profile ci
- name: upload artifact
uses: actions/upload-artifact@v4 # upload test results as artifact
if: always()
with:
name: test-results
name: test-results-${{ matrix.tari_target_network.target }}.${{ matrix.tari_target_network.network }}
path: ${{ github.workspace }}/target/nextest/ci/junit.xml

# Allows other workflows to know the PR number
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions applications/minotari_app_grpc/Cargo.toml
Expand Up @@ -31,6 +31,7 @@ tonic = { version = "0.8.3", features = ["tls"]}
zeroize = "1"

[build-dependencies]
tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.9" }
tonic-build = "0.8.4"

[package.metadata.cargo-machete]
Expand Down
3 changes: 3 additions & 0 deletions applications/minotari_app_grpc/build.rs
@@ -1,7 +1,10 @@
// Copyright 2022 The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use tari_features::resolver::build_features;

fn main() -> Result<(), Box<dyn std::error::Error>> {
build_features();
tonic_build::configure().build_client(true).build_server(true).compile(
&[
"proto/base_node.proto",
Expand Down
4 changes: 2 additions & 2 deletions applications/minotari_app_utilities/Cargo.toml
Expand Up @@ -9,7 +9,7 @@ license = "BSD-3-Clause"
tari_common = { path = "../../common" }
tari_common_types = { path = "../../base_layer/common_types" }
tari_comms = { path = "../../comms/core" }
tari_features = { path = "../../common/tari_features" }
tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.9" }
tari_utilities = { version = "0.7" }
minotari_app_grpc = { path = "../minotari_app_grpc", optional = true }

Expand All @@ -27,7 +27,7 @@ tonic = "0.8.3"

[build-dependencies]
tari_common = { path = "../../common", features = ["build", "static-application-info"] }
tari_features = { path = "../../common/tari_features" }
tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.9" }

[features]
miner_input = ["minotari_app_grpc"]
6 changes: 3 additions & 3 deletions applications/minotari_app_utilities/src/network_check.rs
Expand Up @@ -48,13 +48,13 @@ impl From<NetworkCheckError> for ExitError {
}
}

#[cfg(tari_network_mainnet)]
#[cfg(tari_target_network_mainnet)]
pub const TARGET_NETWORK: Target = Target::MainNet;

#[cfg(tari_network_nextnet)]
#[cfg(tari_target_network_nextnet)]
pub const TARGET_NETWORK: Target = Target::NextNet;

#[cfg(all(not(tari_network_mainnet), not(tari_network_nextnet)))]
#[cfg(all(not(tari_target_network_mainnet), not(tari_target_network_nextnet)))]
pub const TARGET_NETWORK: Target = Target::TestNet;

pub fn is_network_choice_valid(network: Network) -> Result<Network, NetworkCheckError> {
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_console_wallet/Cargo.toml
Expand Up @@ -82,7 +82,7 @@ default-features = false
features = ["crossterm"]

[build-dependencies]
tari_features = { path = "../../common/tari_features" }
tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.9" }

[features]
default = ["libtor"]
Expand Down
2 changes: 1 addition & 1 deletion applications/minotari_merge_mining_proxy/Cargo.toml
Expand Up @@ -46,4 +46,4 @@ tracing = "0.1"
url = "2.1.1"

[build-dependencies]
tari_features = { path = "../../common/tari_features"}
tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.9"}
2 changes: 1 addition & 1 deletion applications/minotari_node/Cargo.toml
Expand Up @@ -58,7 +58,7 @@ safe = []
libtor = ["tari_libtor"]

[build-dependencies]
tari_features = { path = "../../common/tari_features"}
tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.9"}

[package.metadata.cargo-machete]
ignored = [
Expand Down
1 change: 1 addition & 0 deletions base_layer/core/Cargo.toml
Expand Up @@ -105,6 +105,7 @@ quickcheck = "1.0"

[build-dependencies]
tari_common = { path = "../../common", features = ["build"], version = "1.0.0-pre.9" }
tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.9" }

[[bench]]
name = "mempool"
Expand Down
3 changes: 3 additions & 0 deletions base_layer/core/build.rs
Expand Up @@ -20,7 +20,10 @@
// 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 tari_features::resolver::build_features;

fn main() {
build_features();
tari_common::build::ProtobufCompiler::new()
.include_paths(&["src/proto"])
.proto_paths(&[
Expand Down
36 changes: 20 additions & 16 deletions base_layer/core/src/blocks/genesis_block.rs
Expand Up @@ -111,17 +111,17 @@ pub fn get_stagenet_genesis_block() -> ChainBlock {
if add_faucet_utxos {
// NB! Update 'consensus_constants.rs/pub fn igor()/ConsensusConstants {faucet_value: ?}' with total value
// NB: `stagenet_genesis_sanity_check` must pass
let file_contents = include_str!("faucets/esmeralda_faucet.json");
let file_contents = include_str!("faucets/stagenet_faucet.json");
add_faucet_utxos_to_genesis_block(file_contents, &mut block);
// Enable print only if you need to generate new Merkle roots, then disable it again
let print_values = false;
print_mr_values(&mut block, print_values);

// Hardcode the Merkle roots once they've been computed above
block.header.kernel_mr =
FixedHash::from_hex("3f4011ec1e8ddfbd66fb7331c5623b38f529a66e81233d924df85f2070b2aacb").unwrap();
FixedHash::from_hex("a08ff15219beea81d4131465290443fb3bd99d28b8af85975dbb2c77cb4cb5a0").unwrap();
block.header.output_mr =
FixedHash::from_hex("3e40efda288a57d3319c63388dd47ffe4b682baaf6a3b58622ec94d77ad712a2").unwrap();
FixedHash::from_hex("435f13e21be06b0d0ae9ad3869ac7c723edd933983fa2e26df843c82594b3245").unwrap();
block.header.validator_node_mr =
FixedHash::from_hex("277da65c40b2cf99db86baedb903a3f0a38540f3a94d40c826eecac7e27d5dfc").unwrap();
}
Expand Down Expand Up @@ -163,17 +163,17 @@ pub fn get_nextnet_genesis_block() -> ChainBlock {
if add_faucet_utxos {
// NB! Update 'consensus_constants.rs/pub fn igor()/ConsensusConstants {faucet_value: ?}' with total value
// NB: `nextnet_genesis_sanity_check` must pass
let file_contents = include_str!("faucets/esmeralda_faucet.json");
let file_contents = include_str!("faucets/nextnet_faucet.json");
add_faucet_utxos_to_genesis_block(file_contents, &mut block);
// Enable print only if you need to generate new Merkle roots, then disable it again
let print_values = false;
print_mr_values(&mut block, print_values);

// Hardcode the Merkle roots once they've been computed above
block.header.kernel_mr =
FixedHash::from_hex("3f4011ec1e8ddfbd66fb7331c5623b38f529a66e81233d924df85f2070b2aacb").unwrap();
FixedHash::from_hex("36881d87e25183f5189d2dca5f7da450c399e7006dafd9bd9240f73a5fb3f0ad").unwrap();
block.header.output_mr =
FixedHash::from_hex("3e40efda288a57d3319c63388dd47ffe4b682baaf6a3b58622ec94d77ad712a2").unwrap();
FixedHash::from_hex("7b65d5140485b44e33eef3690d46c41e4dc5c4520ad7464d7740f376f4f0a728").unwrap();
block.header.validator_node_mr =
FixedHash::from_hex("277da65c40b2cf99db86baedb903a3f0a38540f3a94d40c826eecac7e27d5dfc").unwrap();
}
Expand Down Expand Up @@ -368,6 +368,7 @@ mod test {

use tari_common_types::{epoch::VnEpoch, types::Commitment};
use tari_utilities::ByteArray;
use Network;

use super::*;
use crate::{
Expand All @@ -383,14 +384,16 @@ mod test {
};

#[test]
fn stagenet_genesis_sanity_check() {
// Note: Generate new data for `pub fn get_stagenet_genesis_block()` and `fn get_stagenet_genesis_block_raw()`
#[cfg(tari_target_network_testnet)]
fn esme_genesis_sanity_check() {
// Note: Generate new data for `pub fn get_esmeralda_genesis_block()` and `fn get_esmeralda_genesis_block_raw()`
// if consensus values change, e.g. new faucet or other
let block = get_stagenet_genesis_block();
check_block(Network::StageNet, &block, 100, 1);
let block = get_esmeralda_genesis_block();
check_block(Network::Esmeralda, &block, 100, 1);
}

#[test]
#[cfg(tari_target_network_nextnet)]
fn nextnet_genesis_sanity_check() {
// Note: Generate new data for `pub fn get_nextnet_genesis_block()` and `fn get_stagenet_genesis_block_raw()`
// if consensus values change, e.g. new faucet or other
Expand All @@ -399,17 +402,18 @@ mod test {
}

#[test]
fn esmeralda_genesis_sanity_check() {
// Note: Generate new data for `pub fn get_esmeralda_genesis_block()` and `fn get_esmeralda_genesis_block_raw()`
#[cfg(tari_target_network_mainnet)]
fn stagenet_genesis_sanity_check() {
Network::set_current(Network::StageNet).unwrap();
// Note: Generate new data for `pub fn get_stagenet_genesis_block()` and `fn get_stagenet_genesis_block_raw()`
// if consensus values change, e.g. new faucet or other
let block = get_esmeralda_genesis_block();
check_block(Network::Esmeralda, &block, 100, 1);
let block = get_stagenet_genesis_block();
check_block(Network::StageNet, &block, 100, 1);
}

#[test]
fn igor_genesis_sanity_check() {
// Note: Generate new data for `pub fn get_igor_genesis_block()` and `fn get_igor_genesis_block_raw()`
// if consensus values change, e.g. new faucet or other
// Note: If outputs and kernels are added, this test will fail unless you explicitly check that network == Igor
let block = get_igor_genesis_block();
check_block(Network::Igor, &block, 0, 0);
}
Expand Down
1 change: 1 addition & 0 deletions base_layer/core/src/proof_of_work/sha3x_pow.rs
Expand Up @@ -96,6 +96,7 @@ pub mod test {
}

#[test]
#[cfg(tari_target_network_testnet)]
fn validate_max_target() {
let mut header = get_header();
header.nonce = 631;
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/src/transactions/coinbase_builder.rs
Expand Up @@ -662,7 +662,7 @@ mod test {
let block_reward = rules.emission_schedule().block_reward(42) + missing_fee;
let builder = CoinbaseBuilder::new(key_manager.clone());
let builder = builder
.with_block_height(4200000)
.with_block_height(4_200_000)
.with_fees(1 * uT)
.with_spend_key_id(p.spend_key_id.clone())
.with_encryption_key_id(TariKeyId::default())
Expand Down
34 changes: 34 additions & 0 deletions base_layer/core/src/transactions/transaction_components/test.rs
Expand Up @@ -280,6 +280,11 @@ async fn sender_signature_verification() {

#[test]
fn kernel_hash() {
#[cfg(tari_target_network_mainnet)]
if let Network::MainNet = Network::get_current_or_default() {
eprintln!("This test is configured for stagenet only");
return;
}
let s = PrivateKey::from_hex("6c6eebc5a9c02e1f3c16a69ba4331f9f63d0718401dea10adc4f9d3b879a2c09").unwrap();
let r = PublicKey::from_hex("28e8efe4e5576aac931d358d0f6ace43c55fa9d4186d1d259d1436caa876d43b").unwrap();
let sig = Signature::new(r, s);
Expand All @@ -291,6 +296,17 @@ fn kernel_hash() {
.with_lock_height(500)
.build()
.unwrap();
#[cfg(tari_target_network_nextnet)]
assert_eq!(
&k.hash().to_hex(),
"c1f6174935d08358809fcf244a9a1edb078b74a1ae18ab4c7dd501b0294a2a94"
);
#[cfg(tari_target_network_mainnet)]
assert_eq!(
&k.hash().to_hex(),
"b94992cb59695ebad3786e9f51a220e91c627f8b38f51bcf6c87297325d1b410"
);
#[cfg(tari_target_network_testnet)]
assert_eq!(
&k.hash().to_hex(),
"38b03d013f941e86c027969fbbc190ca2a28fa2d7ac075d50dbfb6232deee646"
Expand All @@ -310,6 +326,24 @@ fn kernel_metadata() {
.with_lock_height(500)
.build()
.unwrap();
#[cfg(tari_target_network_mainnet)]
match Network::get_current_or_default() {
Network::MainNet => {
eprintln!("This test is configured for stagenet only");
},
Network::StageNet => assert_eq!(
&k.hash().to_hex(),
"75a357c2769098b19a6aedc7e46f6be305f4f1a1831556cd380b0b0f20bfdf12"
),
n => panic!("Only mainnet networks should target mainnet. Network was {}", n),
}

#[cfg(tari_target_network_nextnet)]
assert_eq!(
&k.hash().to_hex(),
"22e39392dfeae9653c73437880be71e99f4b8a2b23289d54f57b8931deebfeed"
);
#[cfg(tari_target_network_testnet)]
assert_eq!(
&k.hash().to_hex(),
"ebc852fbac798c25ce497b416f69ec11a97e186aacaa10e2bb4ca5f5a0f197f2"
Expand Down
4 changes: 3 additions & 1 deletion base_layer/tari_mining_helper_ffi/Cargo.toml
Expand Up @@ -19,8 +19,10 @@ hex = "0.4.2"

[dev-dependencies]
tari_core = { path = "../core", features = ["transactions", "base_node"]}

rand = "0.8"

[build-dependencies]
tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.9" }

[lib]
crate-type = ["staticlib","cdylib"]

0 comments on commit 8990b57

Please sign in to comment.