Skip to content

Commit

Permalink
Merge branch 'tomas/trigger-test-sync' (#2511)
Browse files Browse the repository at this point in the history
* origin/tomas/trigger-test-sync:
  ci/action: add triggerable chain sync
  changelog: add #2511
  test/e2e: add a triggerable test for chain sync
  client: added cli command query node's status
  • Loading branch information
tzemanovic committed Feb 6, 2024
2 parents c31951d + 965ed3b commit 237552e
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/features/2511-test-sync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Added a client command "status" to query a node's status.
([\#2511](https://github.com/anoma/namada/pull/2511))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Triggerable Tasks
name: Triggerable PoS state-machine test

on:
workflow_dispatch:
Expand Down Expand Up @@ -26,7 +26,7 @@ env:
AWS_REGION: us-east-1

jobs:
pos:
test-pos:
runs-on: ${{ matrix.os }}
timeout-minutes: ${{ matrix.timeout }}
strategy:
Expand Down
118 changes: 118 additions & 0 deletions .github/workflows/triggerable_sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Triggerable chain sync test

on:
workflow_dispatch:
inputs:
branch:
description: 'Branch name'
required: true
type: string
chain_id:
description: 'Chain ID'
required: true
type: string
add_peer:
description: "Optional address to add to Comet's P2P config (must be a valid `TendermintAddress`, e.g. `tcp://[email protected]:26656`)."
required: false
default: ''
type: string

env:
RUSTC_WRAPPER: sccache
SCCACHE_S3_USE_SSL: ${{ secrets.CACHE_SSL }}
GIT_LFS_SKIP_SMUDGE: 1
CARGO_INCREMENTAL: 0
RUST_BACKTRACE: full
SCCACHE_BUCKET: namada-cache
SCCACHE_ENDPOINT: ${{ secrets.CACHE_ENDPOINT }}
AWS_ACCESS_KEY_ID: ${{ secrets.CACHE_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.CACHE_SECRET_KEY }}
AWS_REGION: us-east-1

jobs:
test-sync:
runs-on: ${{ matrix.os }}
timeout-minutes: ${{ matrix.timeout }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
mold_version: [2.4.0]
name: ["Run chain sync test"]
nightly_version: [nightly-2023-06-01]
timeout: [360]

steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
- name: Get latest commit SHA
run: |
git fetch origin ${{ inputs.branch }}
echo "COMMIT_SHA=$(git rev-parse origin/${{ inputs.branch }})" >> $GITHUB_ENV
- name: Install libudev
run: sudo apt-get update && sudo apt-get -y install libudev-dev
- name: Install Protoc
uses: heliaxdev/setup-protoc@v2
with:
version: "25.0"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Run sccache-cache
uses: mozilla-actions/[email protected]
- name: Setup rust toolchain
uses: oxidecomputer/actions-rs_toolchain@ad3f86084a8a5acf2c09cb691421b31cf8af7a36
with:
toolchain: ${{ matrix.nightly_version }}
profile: default
- name: Cache cargo registry
uses: actions/cache@v3
continue-on-error: false
with:
path: |
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-${{ github.job }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Start sccache server
run: sccache --start-server
- name: Install mold linker
run: |
wget -q -O- https://github.com/rui314/mold/releases/download/v${{ matrix.mold_version }}/mold-${{ matrix.mold_version }}-x86_64-linux.tar.gz | tar -xz
mv mold-${{ matrix.mold_version }}-x86_64-linux/bin/mold /usr/local/bin
- name: Download namada release binaries
run: |
unset AWS_SESSION_TOKEN
aws --endpoint-url $S3_ENDPOINT_URL s3 cp s3://$BUCKET_NAME $ZIP_FILENAME --region $AWS_REGION
unzip $ZIP_FILENAME
env:
BUCKET_NAME: namada-binaries
AWS_REGION: us-east-1
S3_ENDPOINT_URL: https://minio.heliax.click
ZIP_FILENAME: binaries-$COMMIT_SHA.zip
AWS_ACCESS_KEY_ID: ${{ secrets.MINIO_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.MINIO_SECRET_KEY }}
- name: Run the test
run: cargo +{{ matrix.nightly_version }}
test e2e::ledger_tests::test_sync_chain -- --exact --ignored
env:
NAMADA_E2E_USE_PREBUILT_BINARIES: "true"
NAMADA_E2E_KEEP_TEMP: "true"
NAMADA_LOG_COLOR: "false"
NAMADA_ADD_PEER: "{{ inputs.add_peer }}"
NAMADA_CHAIN_ID: "{{ inputs.chain_id }}"
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=/usr/local/bin/mold"
- name: Upload logs
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: logs-sync-$COMMIT_SHA
path: |
/tmp/.*/logs/
/tmp/.*/setup/validator-*/logs/
/tmp/.*/setup/valiator-*/e2e-test.*/*.toml
retention-days: 5
- name: Stats sccache server
run: sccache --show-stats || true
- name: Start sccache server
run: sccache --stop-server || true
23 changes: 23 additions & 0 deletions crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ pub mod cmds {
.subcommand(TxResignSteward::def().display_order(4))
// Queries
.subcommand(QueryEpoch::def().display_order(5))
.subcommand(QueryStatus::def().display_order(5))
.subcommand(QueryAccount::def().display_order(5))
.subcommand(QueryTransfers::def().display_order(5))
.subcommand(QueryConversions::def().display_order(5))
Expand Down Expand Up @@ -311,6 +312,7 @@ pub mod cmds {
let redelegate = Self::parse_with_ctx(matches, Redelegate);
let claim_rewards = Self::parse_with_ctx(matches, ClaimRewards);
let query_epoch = Self::parse_with_ctx(matches, QueryEpoch);
let query_status = Self::parse_with_ctx(matches, QueryStatus);
let query_account = Self::parse_with_ctx(matches, QueryAccount);
let query_transfers = Self::parse_with_ctx(matches, QueryTransfers);
let query_conversions =
Expand Down Expand Up @@ -374,6 +376,7 @@ pub mod cmds {
.or(tx_update_steward_commission)
.or(tx_resign_steward)
.or(query_epoch)
.or(query_status)
.or(query_transfers)
.or(query_conversions)
.or(query_masp_reward_tokens)
Expand Down Expand Up @@ -461,6 +464,7 @@ pub mod cmds {
TxUpdateStewardCommission(TxUpdateStewardCommission),
TxResignSteward(TxResignSteward),
QueryEpoch(QueryEpoch),
QueryStatus(QueryStatus),
QueryAccount(QueryAccount),
QueryTransfers(QueryTransfers),
QueryConversions(QueryConversions),
Expand Down Expand Up @@ -1463,6 +1467,25 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct QueryStatus(pub args::Query<args::CliTypes>);

impl SubCmd for QueryStatus {
const CMD: &'static str = "status";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| QueryStatus(args::Query::parse(matches)))
}

fn def() -> App {
App::new(Self::CMD)
.about("Query the node's status.")
.add_args::<args::Query<args::CliTypes>>()
}
}

#[derive(Clone, Debug)]
pub struct QueryAccount(pub args::QueryAccount<args::CliTypes>);

Expand Down
10 changes: 10 additions & 0 deletions crates/apps/src/lib/cli/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,16 @@ impl CliApi {
let namada = ctx.to_sdk(client, io);
rpc::query_and_print_epoch(&namada).await;
}
Sub::QueryStatus(QueryStatus(args)) => {
let chain_ctx = ctx.borrow_mut_chain_or_exit();
let ledger_address =
chain_ctx.get(&args.ledger_address);
let client = client.unwrap_or_else(|| {
C::from_tendermint_address(&ledger_address)
});
let namada = ctx.to_sdk(client, io);
rpc::query_and_print_status(&namada).await;
}
Sub::QueryValidatorState(QueryValidatorState(args)) => {
let chain_ctx = ctx.borrow_mut_chain_or_exit();
let ledger_address =
Expand Down
19 changes: 19 additions & 0 deletions crates/apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ use namada_sdk::error::{
};
use namada_sdk::masp::{Conversions, MaspChange, MaspTokenRewardData};
use namada_sdk::proof_of_stake::types::ValidatorMetaData;
use namada_sdk::queries::Client;
use namada_sdk::rpc::{
self, enriched_bonds_and_unbonds, query_epoch, TxResponse,
};
use namada_sdk::tendermint_rpc::endpoint::status;
use namada_sdk::tx::{display_inner_resp, display_wrapper_resp_and_get_result};
use namada_sdk::wallet::AddressVpType;
use namada_sdk::{display, display_line, edisplay_line, error, prompt, Namada};
Expand Down Expand Up @@ -87,6 +89,23 @@ pub async fn query_and_print_epoch(context: &impl Namada) -> Epoch {
epoch
}

/// Query and print node's status.
pub async fn query_and_print_status(
context: &impl Namada,
) -> Option<status::Response> {
let status = context.client().status().await;
match status {
Ok(status) => {
display_line!(context.io(), "Node's status {status:#?}");
Some(status)
}
Err(err) => {
edisplay_line!(context.io(), "Status query failed with {err:#?}");
None
}
}
}

/// Query the last committed block
pub async fn query_block(context: &impl Namada) {
let block = namada_sdk::rpc::query_block(context.client())
Expand Down
90 changes: 90 additions & 0 deletions crates/tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ use namada::governance::storage::proposal::{PGFInternalTarget, PGFTarget};
use namada::token;
use namada::types::address::Address;
use namada::types::storage::Epoch;
use namada_apps::cli::context::ENV_VAR_CHAIN_ID;
use namada_apps::config::ethereum_bridge;
use namada_apps::config::utils::convert_tm_addr_to_socket_addr;
use namada_apps::facade::tendermint_config::net::Address as TendermintAddress;
use namada_core::types::chain::ChainId;
use namada_core::types::token::NATIVE_MAX_DECIMAL_PLACES;
use namada_sdk::governance::pgf::cli::steward::Commission;
use namada_sdk::masp::fs::FsShieldedUtils;
Expand Down Expand Up @@ -60,6 +62,8 @@ use crate::strings::{
};
use crate::{run, run_as};

const ENV_VAR_NAMADA_ADD_PEER: &str = "NAMADA_ADD_PEER";

fn start_namada_ledger_node(
test: &Test,
idx: Option<u64>,
Expand Down Expand Up @@ -3943,3 +3947,89 @@ fn proposal_change_shielded_reward() -> Result<()> {

Ok(())
}

/// Test sync with a chain.
///
/// The chain ID must be set via `NAMADA_CHAIN_ID` env var.
/// Additionally, `NAMADA_ADD_PEER` maybe be specified with a string that must
/// be parsable into `TendermintAddress`.
///
/// To run this test use `--ignored`.
#[test]
#[ignore = "This test is only ran when explicitly triggered"]
fn test_sync_chain() -> Result<()> {
let chain_id_raw = std::env::var(ENV_VAR_CHAIN_ID).unwrap_or_else(|_| {
panic!("Set `{ENV_VAR_CHAIN_ID}` env var to sync with.")
});
let chain_id = ChainId::from_str(chain_id_raw.trim())?;
let working_dir = setup::working_dir();
let test_dir = setup::TestDir::new();
let test = Test {
working_dir,
test_dir,
net: setup::Network { chain_id },
async_runtime: Default::default(),
};
let base_dir = test.test_dir.path();

// Setup the chain
let mut join_network = setup::run_cmd(
Bin::Client,
[
"utils",
"join-network",
"--chain-id",
chain_id_raw.as_str(),
"--dont-prefetch-wasm",
],
Some(60),
&test.working_dir,
base_dir,
format!("{}:{}", std::file!(), std::line!()),
)?;
join_network.exp_string("Successfully configured for chain")?;
join_network.assert_success();

// Add peer if any given
if let Ok(add_peer) = std::env::var(ENV_VAR_NAMADA_ADD_PEER) {
let mut config = namada_apps::config::Config::load(
base_dir,
&test.net.chain_id,
None,
);
config.ledger.cometbft.p2p.persistent_peers.push(
TendermintAddress::from_str(&add_peer).unwrap_or_else(|_| {
panic!(
"Invalid `{ENV_VAR_NAMADA_ADD_PEER}` value. Must be a \
valid `TendermintAddress`."
)
}),
);
config.write(base_dir, &test.net.chain_id, true).unwrap();
}

// Start a non-validator node
let mut ledger = start_namada_ledger_node_wait_wasm(
&test,
None,
// init-chain may take a long time for large setups
Some(1200),
)?;
ledger.exp_string("finalize_block: Block height: 1")?;
let _bg_ledger = ledger.background();

// Wait to be synced
loop {
let mut client = run!(test, Bin::Client, ["status"], Some(30))?;
if client.exp_string("catching_up: false").is_ok() {
println!("Node is synced!");
break;
} else {
let sleep_secs = 300;
println!("Not synced yet. Sleeping for {sleep_secs} secs.");
sleep(sleep_secs);
}
}

Ok(())
}

0 comments on commit 237552e

Please sign in to comment.