Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSUB-1089: Enable ci jobs for crunch #16

Merged
merged 14 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
on:
push:
branches: [main, dev]
pull_request:

name: CI
permissions: read-all

jobs:
rustfmt:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Configure rustc version
run: |
RUSTC_VERSION=$(grep channel rust-toolchain.toml | tail -n1 | tr -d " " | cut -f2 -d'"')
echo "RUSTC_VERSION=$RUSTC_VERSION" >> "$GITHUB_ENV"

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUSTC_VERSION }}
profile: minimal
override: true
components: rustfmt

- name: Check formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: -- --check

clippy:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Configure rustc version
run: |
RUSTC_VERSION=$(grep channel rust-toolchain.toml | tail -n1 | tr -d " " | cut -f2 -d'"')
echo "RUSTC_VERSION=$RUSTC_VERSION" >> "$GITHUB_ENV"

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUSTC_VERSION }}
profile: minimal
override: true
components: clippy
- uses: Swatinem/rust-cache@v2

- name: Run Clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features -- -D warnings

check:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Configure rustc version
run: |
RUSTC_VERSION=$(grep channel rust-toolchain.toml | tail -n1 | tr -d " " | cut -f2 -d'"')
echo "RUSTC_VERSION=$RUSTC_VERSION" >> "$GITHUB_ENV"

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUSTC_VERSION }}
target: wasm32-unknown-unknown
profile: minimal
override: true
- uses: Swatinem/rust-cache@v2

- name: Check Build
run: |
RUSTFLAGS="-D warnings" cargo check --release

unit-test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Configure rustc version
run: |
RUSTC_VERSION=$(grep channel rust-toolchain.toml | tail -n1 | tr -d " " | cut -f2 -d'"')
echo "RUSTC_VERSION=$RUSTC_VERSION" >> "$GITHUB_ENV"

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUSTC_VERSION }}
profile: minimal
override: true
- uses: Swatinem/rust-cache@v2

- name: Run cargo test
uses: actions-rs/cargo@v1
env:
CRUNCH_CONFIG_FILENAME: environments/cc3/testnet/.env
with:
command: test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Release

on:
workflow_dispatch:
Expand Down
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "1.77.0" # rustc 1.77.0 (aedd173a2 2024-03-17)
components = ["cargo", "clippy", "rustc", "rustfmt", "rust-src"]
profile = "minimal"
16 changes: 4 additions & 12 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,9 @@
//
// Set Config struct into a CONFIG lazy_static to avoid multiple processing.
//
use clap::{
App,
Arg,
SubCommand,
};
use dotenv;
use clap::{App, Arg, SubCommand};
use lazy_static::lazy_static;
use log::{
info,
warn,
};
use log::{info, warn};
use serde::Deserialize;
use std::env;

Expand Down Expand Up @@ -489,12 +481,12 @@ fn get_config() -> Config {

// Try to load configuration from file first
let config_path = matches.value_of("config-path").unwrap_or(".env");
match dotenv::from_filename(&config_path).ok() {
match dotenv::from_filename(config_path).ok() {
Some(_) => info!("Loading configuration from {} file", &config_path),
None => {
let config_path =
env::var("CRUNCH_CONFIG_FILENAME").unwrap_or(".env".to_string());
if let Some(_) = dotenv::from_filename(&config_path).ok() {
if dotenv::from_filename(&config_path).is_ok() {
info!("Loading configuration from {} file", &config_path);
}
}
Expand Down
25 changes: 11 additions & 14 deletions src/crunch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub async fn create_or_await_substrate_node_client(
pub fn get_from_seed(seed: &str, pass: Option<&str>) -> sr25519::Pair {
// Use regex to remove control characters
let re = Regex::new(r"[\x00-\x1F]").unwrap();
let clean_seed = re.replace_all(&seed.trim(), "");
let clean_seed = re.replace_all(seed.trim(), "");
sr25519::Pair::from_string(&clean_seed, pass)
.expect("constructed from known-good static value; qed")
}
Expand Down Expand Up @@ -237,7 +237,7 @@ fn spawn_and_restart_subscription_on_error() {
}
});

let h = healthcheck();
healthcheck();

task::block_on(t);
}
Expand All @@ -250,10 +250,8 @@ fn spawn_and_restart_crunch_flakes_on_error() {
let c: Crunch = Crunch::new().await;
if let Err(e) = c.try_run_batch().await {
let sleep_min = u32::pow(config.error_interval, n);
match e {
_ => {
error!("{}", e);
}
{
error!("{}", e);
}
thread::sleep(time::Duration::from_secs((60 * sleep_min).into()));
n += 1;
Expand All @@ -263,13 +261,13 @@ fn spawn_and_restart_crunch_flakes_on_error() {
}
});

let h = healthcheck();
healthcheck();

task::block_on(t);
}

fn healthcheck() -> async_std::task::JoinHandle<()> {
let h = task::spawn(async {
task::spawn(async {
let listener = TcpListener::bind("127.0.0.1:9999").unwrap();
let response = "HTTP/1.1 200 OK\r\n\r\n".as_bytes();

Expand All @@ -279,18 +277,17 @@ fn healthcheck() -> async_std::task::JoinHandle<()> {

// we need to read the full request before we respond or we get a 'connection reset by peer error'
let buf_reader = BufReader::new(&mut stream);
let http_request: Vec<_> = buf_reader
let _http_request: Vec<_> = buf_reader
.lines()
.map(|result| result.unwrap())
.take_while(|line| !line.is_empty())
.collect();

stream.write_all(response).unwrap();
}
});

return h;
})
}

fn spawn_crunch_view() {
let crunch_task = task::spawn(async {
let c: Crunch = Crunch::new().await;
Expand All @@ -309,7 +306,7 @@ pub fn random_wait(max: u64) -> u64 {
pub async fn try_fetch_stashes_from_remote_url(
) -> Result<Option<Vec<String>>, CrunchError> {
let config = CONFIG.clone();
if config.stashes_url.len() == 0 {
if config.stashes_url.is_empty() {
return Ok(None);
}
let response = reqwest::get(&config.stashes_url).await?.text().await?;
Expand Down Expand Up @@ -339,7 +336,7 @@ pub async fn try_fetch_onet_data(
return Ok(None);
}

let endpoint = if config.onet_api_url != "" {
let endpoint = if !config.onet_api_url.is_empty() {
config.onet_api_url
} else {
format!("https://{}-onet-api-beta.turboflakes.io", chain_name)
Expand Down
12 changes: 2 additions & 10 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

use codec;
use reqwest;
use std::{
str::Utf8Error,
string::String,
};
use subxt::error::{
DispatchError,
MetadataError,
};
use std::{str::Utf8Error, string::String};
use subxt::error::{DispatchError, MetadataError};
use thiserror::Error;

/// Crunch specific error messages
Expand Down
2 changes: 1 addition & 1 deletion src/pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub fn nomination_pool_account(account_type: AccountType, pool_id: u32) -> Accou
let buffer_hex = buffer.encode_hex::<String>();
// NOTE: subxt::utils::AccountId32 currently doesn't support from hex conversion
let acc = subxt::ext::sp_runtime::AccountId32::from_str(&buffer_hex).unwrap();
return AccountId32::from_str(&acc.to_string()).unwrap();
AccountId32::from_str(&acc.to_string()).unwrap()
}

#[test]
Expand Down
Loading
Loading