Skip to content

Commit

Permalink
fix: blocking on async thread, add formatting in CI (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dodecahedr0x authored Feb 1, 2025
1 parent 78f21a2 commit ffc923c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 32 deletions.
29 changes: 20 additions & 9 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,32 @@ name: Rust

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

env:
CARGO_TERM_COLOR: always

jobs:
run_cargo_checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Rustup install nightly
run: rustup toolchain install nightly
- name: Rustup install rustfmt
run: rustup component add rustfmt --toolchain nightly
- name: Run Cargo fmt
run: cargo +nightly fmt --all -- --check
- name: Run Cargo clippy
run: cargo clippy --all-targets --all-features
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- uses: actions/checkout@v4
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

### Design

Instead of using a full Solana test validator `solana-test-validator`, `surfpool` uses the low level `solan-svm` API through the excellent wrapper [LiteSVM](https://github.com/LiteSVM/litesvm).
Instead of using a full Solana test validator `solana-test-validator`, `surfpool` uses the low level `solana-svm` API through the excellent wrapper [LiteSVM](https://github.com/LiteSVM/litesvm).
This approach provides greater flexibility and significantly faster boot times.

`surfpool` is also available as library on crates.io - facilitating its integration in other projects.
`surfpool` is also available as a library on crates.io - facilitating its integration in other projects.

### Command line

Expand Down
34 changes: 19 additions & 15 deletions crates/cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ pub const DEFAULT_BINDING_ADDRESS: &str = "localhost";
#[allow(dead_code)]
impl Context {
pub fn empty() -> Context {
Context { logger: None, tracer: false }
Context {
logger: None,
tracer: false,
}
}

pub fn try_log<F>(&self, closure: F)
Expand Down Expand Up @@ -51,20 +54,27 @@ enum Command {
#[derive(Parser, PartialEq, Clone, Debug)]
pub struct StartSimnet {
/// Path to the manifest
#[arg(long = "manifest-file-path", short = 'm', default_value = "./Surfpool.toml")]
#[arg(
long = "manifest-file-path",
short = 'm',
default_value = "./Surfpool.toml"
)]
pub manifest_path: String,
/// Set the port
#[arg(long = "port", short = 'p', default_value = DEFAULT_BINDING_PORT )]
pub network_binding_port: u16,
/// Set the ip
#[arg(long = "ip", short = 'i', default_value = DEFAULT_BINDING_ADDRESS )]
pub network_binding_ip_address: String,
pub network_binding_ip_address: String,
}

pub fn main() {
let logger = hiro_system_kit::log::setup_logger();
let _guard = hiro_system_kit::log::setup_global_logger(logger.clone());
let ctx = Context { logger: Some(logger), tracer: false };
let ctx = Context {
logger: Some(logger),
tracer: false,
};

let opts: Opts = match Opts::try_parse() {
Ok(opts) => opts,
Expand All @@ -74,20 +84,14 @@ pub fn main() {
}
};

match hiro_system_kit::nestable_block_on(handle_command(opts, &ctx)) {
Err(e) => {
error!(ctx.expect_logger(), "{e}");
std::thread::sleep(std::time::Duration::from_millis(500));
process::exit(1);
}
Ok(_) => {}
if let Err(e) = hiro_system_kit::nestable_block_on(handle_command(opts, &ctx)) {
error!(ctx.expect_logger(), "{e}");
std::thread::sleep(std::time::Duration::from_millis(500));
process::exit(1);
}
}

async fn handle_command(
opts: Opts,
ctx: &Context,
) -> Result<(), String> {
async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
match opts.command {
Command::Simnet(cmd) => {
simnet::handle_start_simnet_command(&cmd, ctx).await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/cli/simnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ use surfpool_core::start_simnet;

pub async fn handle_start_simnet_command(_cmd: &StartSimnet, _ctx: &Context) -> Result<(), String> {
println!("Where you train before surfing Solana");
start_simnet();
start_simnet().await.map_err(|e| e.to_string())?;
Ok(())
}
2 changes: 1 addition & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pub mod cli;

fn main() {
cli::main();
}
}
6 changes: 3 additions & 3 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use litesvm;
pub use solana_rpc_client;
pub use solana_sdk;


pub fn start_simnet() {
hiro_system_kit::nestable_block_on(simnet::start());
pub async fn start_simnet() -> Result<(), Box<dyn std::error::Error>> {
simnet::start().await?;
Ok(())
}
2 changes: 1 addition & 1 deletion crates/core/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ pub struct RunloopContext {

impl Metadata for RunloopContext {}

use crate::simnet::GlobalState;
use jsonrpc_core::futures::FutureExt;
use std::future::Future;
use crate::simnet::GlobalState;

#[derive(Clone)]
pub struct SurfpoolMiddleware {
Expand Down

0 comments on commit ffc923c

Please sign in to comment.