Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into updated_BUILD.md
Browse files Browse the repository at this point in the history
  • Loading branch information
fixxxedpoint committed Jan 17, 2023
2 parents 4e82122 + 6ca0b7c commit dc555c8
Show file tree
Hide file tree
Showing 37 changed files with 620 additions and 416 deletions.
2 changes: 1 addition & 1 deletion .github/actions/run-e2e-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ runs:
RESERVED_SEATS="${{ inputs.reserved-seats }}"
NON_RESERVED_SEATS="${{ inputs.non-reserved-seats }}"
if [[ -n "${RANDOMIZED}" ]]; then
ARGS+=(-r "${RANDOMIZED}")
fi
Expand Down
9 changes: 8 additions & 1 deletion .github/scripts/run_consensus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
set -euo pipefail

# default node count
# change when increasing the number of node containers
NODE_COUNT=5
# max node count that will not crash current GH machines
MAX_NODE_COUNT=6
# default minimum validator count
MIN_VALIDATOR_COUNT=4
DOCKER_COMPOSE=${DOCKER_COMPOSE:-"docker/docker-compose.yml"}
OVERRIDE_DOCKER_COMPOSE=${OVERRIDE_DOCKER_COMPOSE:-""}
Expand Down Expand Up @@ -51,6 +53,11 @@ done

export NODE_COUNT

if [[ ${NODE_COUNT} -gt ${MAX_NODE_COUNT} ]]; then
echo "Tried to run ${NODE_COUNT} nodes. Max node count allowed: ${MAX_NODE_COUNT}."
exit 1
fi

function generate_authorities {
local authorities_count="$1"

Expand Down
59 changes: 28 additions & 31 deletions .github/workflows/deploy-to-devnet.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Deploy to Devnet

# This workflow performs automatic deployment of aleph-node to the Devnet environment
# It does it from the scratch, ie it
# 1) syncs the validators keys from S3,
# 2) generates raw chainspec from the deployed aleph-node binary,
# 3) restart nodes with cleaned db

on:
workflow_dispatch:

Expand All @@ -22,8 +28,7 @@ jobs:
id: vars
shell: bash
run: |
echo "##[set-output name=branch;]$(echo ${GITHUB_REF##*/})"
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
Expand All @@ -49,58 +54,50 @@ jobs:
with:
version: 'v1.23.6'

- name: Run fork-off update
env:
RELEASE_TAG: ${{ steps.vars.outputs.sha_short }}

- name: Sync all validator's keystores from S3
run: |
#!/bin/bash
COMMIT_ID=$(curl -s -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "system_version"}' https://rpc.test.azero.dev | jq -r '.result' | cut -d "-" -f 2 | head -c 7)
echo $COMMIT_ID
# sync all validator's keystores from S3
aws s3 cp s3://alephzero-devnet-eu-central-1-keys-bucket/data data --recursive
# rename validator paths
declare -A NAMES=([aleph-node-validator-0]=5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH [aleph-node-validator-1]=5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o [aleph-node-validator-2]=5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9 [aleph-node-validator-3]=5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK [aleph-node-validator-4]=5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW [aleph-node-validator-5]=5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR [aleph-node-validator-6]=5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY [aleph-node-validator-7]=5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ [aleph-node-validator-8]=5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX [aleph-node-validator-9]=5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q)
for NAME in "${!NAMES[@]}"; do
mv -v data/$NAME data/${NAMES[$NAME]}
done
# generate chainspec, it will reuse keys from the synced keystore
docker run -i -v $(pwd)/data:/data --env RUST_BACKTRACE=1 --entrypoint "/usr/local/bin/aleph-node" public.ecr.aws/p6e8q1z1/aleph-node:${COMMIT_ID} bootstrap-chain --raw --base-path /data --chain-id a0dnet1 --account-ids 5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH,5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o,5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9,5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK,5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW,5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR,5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY,5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ,5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX,5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q --sudo-account-id 5F4SvwaUEQubiqkPF8YnRfcN77cLsT2DfG4vFeQmSXNjR7hD > chainspec.skeleton.json
docker run -i -v $(pwd):/app public.ecr.aws/p6e8q1z1/fork-off:latest --ws-rpc-endpoint=wss://ws.test.azero.dev --initial-spec-path=chainspec.skeleton.json --combined-spec-path=chainspec.json
- name: Generate chainspec
env:
RELEASE_TAG: ${{ steps.vars.outputs.sha_short }}

run: |
#!/bin/bash
aws s3 cp s3://alephzero-devnet-eu-central-1-keys-bucket/data data --recursive
docker run -i -v $(pwd)/data:/data --env RUST_BACKTRACE=1 --entrypoint "/usr/local/bin/aleph-node" public.ecr.aws/p6e8q1z1/aleph-node:${RELEASE_TAG} bootstrap-chain --raw --base-path /data --chain-id a0dnet1 --account-ids 5D34dL5prEUaGNQtPPZ3yN5Y6BnkfXunKXXz6fo7ZJbLwRRH,5GBNeWRhZc2jXu7D55rBimKYDk8PGk8itRYFTPfC8RJLKG5o,5Dfis6XL8J2P6JHUnUtArnFWndn62SydeP8ee8sG2ky9nfm9,5F4H97f7nQovyrbiq4ZetaaviNwThSVcFobcA5aGab6167dK,5DiDShBWa1fQx6gLzpf3SFBhMinCoyvHM1BWjPNsmXS8hkrW,5EFb84yH9tpcFuiKUcsmdoF7xeeY3ajG1ZLQimxQoFt9HMKR,5DZLHESsfGrJ5YzT3HuRPXsSNb589xQ4Unubh1mYLodzKdVY,5GHJzqvG6tXnngCpG7B12qjUvbo5e4e9z8Xjidk3CQZHxTPZ,5CUnSsgAyLND3bxxnfNhgWXSe9Wn676JzLpGLgyJv858qhoX,5CVKn7HAZW1Ky4r7Vkgsr7VEW88C2sHgUNDiwHY9Ct2hjU8q --sudo-account-id 5F4SvwaUEQubiqkPF8YnRfcN77cLsT2DfG4vFeQmSXNjR7hD > chainspec.json
aws s3 cp chainspec.json s3://alephzero-devnet-eu-central-1-keys-bucket/chainspec.json
# stop and clean devnet
- name: Stop and purge db Devnet
run: |
#!/bin/bash
aws eks --region eu-central-1 update-kubeconfig --name alephzero-devnet-eu-central-1-eks
kubectl delete sts aleph-node-validator -n devnet --ignore-not-found=true
kubectl delete pvc -l app=aleph-node-validator -n devnet --ignore-not-found=true
kubectl delete job send-runtime-hook -n devnet --ignore-not-found=true
cd aleph-apps/aleph-node-validators/overlays/devnet/eu-central-1
kustomize edit set image "aleph-node-validator-image-placeholder=public.ecr.aws/p6e8q1z1/aleph-node:${COMMIT_ID}"
kustomize edit remove resource send-runtime-hook.yaml
kustomize build . | kubectl apply -f -
sleep 2
kubectl rollout status --watch --timeout=3600s statefulset/aleph-node-validator -n devnet
echo "Waiting 15 minutes"
sleep 900
- name: Start Devnet
env:
RELEASE_TAG: ${{ steps.vars.outputs.sha_short }}
run: |
#!/bin/bash
cd aleph-apps/aleph-node-validators/overlays/devnet/eu-central-1
kustomize edit set image "aleph-node-validator-image-placeholder=public.ecr.aws/p6e8q1z1/aleph-node:${RELEASE_TAG}"
kustomize build . | kubectl apply -f -
sleep 2
kubectl rollout status --watch --timeout=3600s statefulset/aleph-node-validator -n devnet
kustomize edit add resource send-runtime-hook.yaml
kustomize build . | kubectl apply -f -
- name: Waiting 5 minutes for validators to boot
run: |
#!/bin/bash
sleep 300
- name: GIT | Commit changes to aleph-apps repository.
uses: EndBug/[email protected]
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/nightly-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ jobs:
uses: ./.github/actions/run-e2e-test
with:
test-case: authorities_are_staking
randomized: true
node-count: 6
follow-up-finalization-check: true
timeout-minutes: 60

run-e2e-high-out-latency:
Expand Down
2 changes: 1 addition & 1 deletion aleph-client/Cargo.lock

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

2 changes: 1 addition & 1 deletion aleph-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "aleph_client"
# TODO bump major version when API stablize
version = "2.7.0"
version = "2.8.0"
edition = "2021"
license = "Apache 2.0"

Expand Down
75 changes: 53 additions & 22 deletions aleph-client/src/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::{thread::sleep, time::Duration};
use anyhow::anyhow;
use codec::Decode;
use log::info;
use serde::{Deserialize, Serialize};
use subxt::{
blocks::ExtrinsicEvents,
ext::sp_core::Bytes,
metadata::DecodeWithMetadata,
rpc::RpcParams,
Expand All @@ -13,7 +15,8 @@ use subxt::{
};

use crate::{
api, sp_weights::weight_v2::Weight, AccountId, BlockHash, Call, KeyPair, SubxtClient, TxStatus,
api, sp_weights::weight_v2::Weight, AccountId, AlephConfig, BlockHash, Call, KeyPair,
SubxtClient, TxHash, TxStatus,
};

/// Capable of communicating with a live Aleph chain.
Expand All @@ -36,11 +39,13 @@ pub struct RootConnection {

/// Castability to a plain connection.
pub trait AsConnection {
/// Allows cast to [`Connection`] reference
fn as_connection(&self) -> &Connection;
}

/// Castability to a signed connection.
pub trait AsSigned {
/// Allows cast to [`SignedConnection`] reference
fn as_signed(&self) -> &SignedConnection;
}

Expand Down Expand Up @@ -105,39 +110,55 @@ pub trait ConnectionApi: Sync {
async fn rpc_call<R: Decode>(&self, func_name: String, params: RpcParams) -> anyhow::Result<R>;
}

/// Data regarding submitted transaction.
#[derive(Copy, Clone, Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct TxInfo {
pub block_hash: BlockHash,
pub tx_hash: TxHash,
}

impl From<ExtrinsicEvents<AlephConfig>> for TxInfo {
fn from(ee: ExtrinsicEvents<AlephConfig>) -> Self {
Self {
block_hash: ee.block_hash(),
tx_hash: ee.extrinsic_hash(),
}
}
}

/// Signed connection should be able to sends transactions to chain
#[async_trait::async_trait]
pub trait SignedConnectionApi: ConnectionApi {
/// Send a transaction to a chain. It waits for a given tx `status`.
/// * `tx` - encoded transaction payload
/// * `status` - a [`TxStatus`] for a tx to wait for
/// # Returns
/// Block hash of block where transaction was put or error
/// Block hash of block where transaction was put together with transaction hash, or error.
/// # Examples
/// ```ignore
/// let tx = api::tx()
/// .balances()
/// .transfer(MultiAddress::Id(dest), amount);
/// send_tx(tx, status).await
/// let tx = api::tx()
/// .balances()
/// .transfer(MultiAddress::Id(dest), amount);
/// send_tx(tx, status).await
/// ```
async fn send_tx<Call: TxPayload + Send + Sync>(
&self,
tx: Call,
status: TxStatus,
) -> anyhow::Result<BlockHash>;
) -> anyhow::Result<TxInfo>;

/// Send a transaction to a chain. It waits for a given tx `status`.
/// * `tx` - encoded transaction payload
/// * `params` - optional tx params e.g. tip
/// * `status` - a [`TxStatus`] of a tx to wait for
/// # Returns
/// Block hash of block where transaction was put or error
/// Block hash of block where transaction was put together with transaction hash, or error.
async fn send_tx_with_params<Call: TxPayload + Send + Sync>(
&self,
tx: Call,
params: BaseExtrinsicParamsBuilder<SubstrateConfig, PlainTip>,
status: TxStatus,
) -> anyhow::Result<BlockHash>;
) -> anyhow::Result<TxInfo>;

/// Returns account id which signs this connection
fn account_id(&self) -> &AccountId;
Expand All @@ -153,14 +174,14 @@ pub trait SignedConnectionApi: ConnectionApi {
#[async_trait::async_trait]
pub trait SudoCall {
/// API for [`sudo_unchecked_weight`](https://paritytech.github.io/substrate/master/pallet_sudo/pallet/enum.Call.html#variant.sudo_unchecked_weight) call.
async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result<BlockHash>;
async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result<TxInfo>;
/// API for [`sudo`](https://paritytech.github.io/substrate/master/pallet_sudo/pallet/enum.Call.html#variant.sudo) call.
async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result<BlockHash>;
async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result<TxInfo>;
}

#[async_trait::async_trait]
impl SudoCall for RootConnection {
async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result<BlockHash> {
async fn sudo_unchecked(&self, call: Call, status: TxStatus) -> anyhow::Result<TxInfo> {
info!(target: "aleph-client", "sending call as sudo_unchecked {:?}", call);
let sudo = api::tx().sudo().sudo_unchecked_weight(
call,
Expand All @@ -173,7 +194,7 @@ impl SudoCall for RootConnection {
self.as_signed().send_tx(sudo, status).await
}

async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result<BlockHash> {
async fn sudo(&self, call: Call, status: TxStatus) -> anyhow::Result<TxInfo> {
info!(target: "aleph-client", "sending call as sudo {:?}", call);
let sudo = api::tx().sudo().sudo(call);

Expand Down Expand Up @@ -263,7 +284,7 @@ impl<S: AsSigned + Sync> SignedConnectionApi for S {
&self,
tx: Call,
status: TxStatus,
) -> anyhow::Result<BlockHash> {
) -> anyhow::Result<TxInfo> {
self.send_tx_with_params(tx, Default::default(), status)
.await
}
Expand All @@ -273,7 +294,7 @@ impl<S: AsSigned + Sync> SignedConnectionApi for S {
tx: Call,
params: BaseExtrinsicParamsBuilder<SubstrateConfig, PlainTip>,
status: TxStatus,
) -> anyhow::Result<BlockHash> {
) -> anyhow::Result<TxInfo> {
if let Some(details) = tx.validation_details() {
info!(target:"aleph-client", "Sending extrinsic {}.{} with params: {:?}", details.pallet_name, details.call_name, params);
}
Expand All @@ -286,15 +307,25 @@ impl<S: AsSigned + Sync> SignedConnectionApi for S {
.await
.map_err(|e| anyhow!("Failed to submit transaction: {:?}", e))?;

// In case of Submitted hash does not mean anything
let hash = match status {
TxStatus::InBlock => progress.wait_for_in_block().await?.block_hash(),
TxStatus::Finalized => progress.wait_for_finalized_success().await?.block_hash(),
TxStatus::Submitted => return Ok(BlockHash::from_low_u64_be(0)),
let info: TxInfo = match status {
TxStatus::InBlock => progress
.wait_for_in_block()
.await?
.wait_for_success()
.await?
.into(),
TxStatus::Finalized => progress.wait_for_finalized_success().await?.into(),
// In case of Submitted block hash does not mean anything
TxStatus::Submitted => {
return Ok(TxInfo {
block_hash: Default::default(),
tx_hash: progress.extrinsic_hash(),
})
}
};
info!(target: "aleph-client", "tx included in block {:?}", hash);
info!(target: "aleph-client", "tx with hash {:?} included in block {:?}", info.tx_hash, info.block_hash);

Ok(hash)
Ok(info)
}

fn account_id(&self) -> &AccountId {
Expand Down
9 changes: 6 additions & 3 deletions aleph-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
extern crate core;

pub use contract_transcode;
pub use subxt::ext::sp_core::Pair;
pub use subxt::{blocks::ExtrinsicEvents, ext::sp_core::Pair};
use subxt::{
ext::sp_core::{ed25519, sr25519, H256},
tx::PairSigner,
Expand Down Expand Up @@ -49,14 +49,17 @@ pub type KeyPair = PairSigner<AlephConfig, sr25519::Pair>;
pub type AccountId = subxt::ext::sp_core::crypto::AccountId32;
/// An alias for a client type.
pub type Client = OnlineClient<AlephConfig>;
/// An alias for a hash type.
/// An alias for a block hash type.
pub type BlockHash = H256;
/// An alias for a transaction hash type.
pub type TxHash = H256;

/// An alias for an RPC client type.
pub type SubxtClient = OnlineClient<AlephConfig>;

pub use connections::{
Connection, ConnectionApi, RootConnection, SignedConnection, SignedConnectionApi, SudoCall,
AsConnection, AsSigned, Connection, ConnectionApi, RootConnection, SignedConnection,
SignedConnectionApi, SudoCall,
};

/// When submitting a transaction, wait for given status before proceeding.
Expand Down
Loading

0 comments on commit dc555c8

Please sign in to comment.