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

feat(host): apply reqactor,reqpool #453

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
93 changes: 89 additions & 4 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ members = [
"pipeline",
"core",
"taskdb",
"redis-derive",
"reqpool",
"reqactor",
]

# Always optimize; building and running the guest takes much longer without optimization.
Expand All @@ -37,6 +40,9 @@ opt-level = 3
raiko-lib = { path = "./lib", features = ["std"] }
raiko-core = { path = "./core" }
raiko-tasks = { path = "./taskdb" }
raiko-redis-derive = { path = "./redis-derive" }
raiko-reqpool = { path = "./reqpool" }
raiko-reqactor = { path = "./reqactor" }

# reth
reth-primitives = { git = "https://github.com/taikoxyz/taiko-reth.git", branch = "v1.0.0-rc.2-taiko", default-features = false, features = [
Expand Down Expand Up @@ -186,6 +192,8 @@ dirs = "5.0.1"
pathdiff = "0.2.1"
dotenv = "0.15.0"
backoff = "0.4.0"
derive-getters = "0.5.0"
test-log = "0.2.16"

[patch.crates-io]
revm = { git = "https://github.com/taikoxyz/revm.git", branch = "v36-taiko" }
Expand Down
4 changes: 4 additions & 0 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ sgx-prover = { path = "../provers/sgx/prover", optional = true }
raiko-lib = { workspace = true }
raiko-core = { workspace = true }
raiko-tasks = { workspace = true }
raiko-reqpool = { workspace = true }
raiko-reqactor = { workspace = true }

# alloy
alloy-rlp = { workspace = true }
Expand Down Expand Up @@ -82,13 +84,15 @@ assert_cmd = { workspace = true }
rstest = { workspace = true }
ethers-core = { workspace = true }
rand = { workspace = true }
test-log = { workspace = true }

[features]
default = []
sp1 = ["raiko-core/sp1"]
risc0 = ["raiko-core/risc0"]
sgx = ["raiko-core/sgx"]
integration = []
test-utils = ["raiko-core/test-utils"]

[[bin]]
name = "raiko-host"
Expand Down
4 changes: 2 additions & 2 deletions host/config/chain_spec_list_default.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"l1_contract": null,
"l2_contract": null,
"rpc": "https://ethereum-rpc.publicnode.com",
"rpc": "https://eth.drpc.org",
"beacon_rpc": "https://ethereum-beacon-api.publicnode.com",
"verifier_address_forks": {
"FRONTIER": {
Expand Down Expand Up @@ -152,4 +152,4 @@
"seconds_per_slot": 1,
"is_taiko": true
}
]
]
1 change: 1 addition & 0 deletions host/make_prove_request_taiko_mainnet_native_780758_0.json

Large diffs are not rendered by default.

42 changes: 29 additions & 13 deletions host/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![allow(incomplete_features)]
use raiko_host::{interfaces::HostResult, server::serve, ProverState};
use raiko_host::{interfaces::HostResult, parse_chain_specs, parse_opts, server::serve};
use raiko_reqpool::RedisPoolConfig;
use std::path::PathBuf;
use tracing::{debug, info};
use tracing_appender::{
Expand All @@ -14,20 +15,35 @@ async fn main() -> HostResult<()> {
env_logger::Builder::from_default_env()
.target(env_logger::Target::Stdout)
.init();
let state = ProverState::init()?;
let _guard = subscribe_log(
&state.opts.log_path,
&state.opts.log_level,
state.opts.max_log,
);
debug!("Start config:\n{:#?}", state.opts.proof_request_opt);
debug!("Args:\n{:#?}", state.opts);
let opts = parse_opts()?;
let chain_specs = parse_chain_specs(&opts);
let default_request_config = opts.proof_request_opt.clone();
let max_proving_concurrency = opts.concurrency_limit;

info!("Supported chains: {:?}", state.chain_specs);
info!("Start config:\n{:#?}", state.opts.proof_request_opt);
info!("Args:\n{:#?}", state.opts);
let pool = raiko_reqpool::Pool::open(RedisPoolConfig {
keroro520 marked this conversation as resolved.
Show resolved Hide resolved
redis_url: opts.redis_url.clone(),
redis_ttl: opts.redis_ttl,
enable_memory_backend: opts.use_memory_backend,
})
.map_err(|e| anyhow::anyhow!(e))?;

serve(state).await?;
let actor = raiko_reqactor::start_actor(
pool,
chain_specs.clone(),
default_request_config.clone(),
max_proving_concurrency,
)
.await;

let _guard = subscribe_log(&opts.log_path, &opts.log_level, opts.max_log);
debug!("Start config:\n{:#?}", default_request_config);
debug!("Args:\n{:#?}", opts);
info!("Supported chains: {:?}", chain_specs);

let address = opts.address.as_str();
let concurrency = opts.concurrency_limit;
let jwt_secret = opts.jwt_secret.clone();
serve(actor, address, concurrency, jwt_secret).await?;
Ok(())
}

Expand Down
37 changes: 24 additions & 13 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ pub struct Opts {

#[arg(long, require_equals = true, default_value = "3600")]
pub redis_ttl: u64,

#[arg(long, default_value = "false")]
pub use_memory_backend: bool,
}

impl Opts {
Expand Down Expand Up @@ -168,23 +171,11 @@ pub enum Message {

impl ProverState {
pub fn init() -> HostResult<Self> {
// Read the command line arguments;
let mut opts = Opts::parse();
// Read env supported options.
opts.merge_from_env();
// Read the config file.
opts.merge_from_file()?;

let opts = parse_opts()?;
Self::init_with_opts(opts)
}

pub fn init_with_opts(opts: Opts) -> HostResult<Self> {
let chain_specs = if let Some(cs_path) = &opts.chain_spec_path {
SupportedChainSpecs::merge_from_file(cs_path.clone()).unwrap_or_default()
} else {
SupportedChainSpecs::default()
};

// Check if the cache path exists and create it if it doesn't.
if let Some(cache_path) = &opts.cache_path {
if !cache_path.exists() {
Expand All @@ -196,6 +187,7 @@ impl ProverState {
let pause_flag = Arc::new(AtomicBool::new(false));

let opts_clone = opts.clone();
let chain_specs = parse_chain_specs(&opts);
let chain_specs_clone = chain_specs.clone();
let sender = task_channel.clone();
tokio::spawn(async move {
Expand Down Expand Up @@ -245,6 +237,25 @@ impl ProverState {
}
}

pub fn parse_opts() -> HostResult<Opts> {
// Read the command line arguments;
let mut opts = Opts::parse();
// Read env supported options.
opts.merge_from_env();
// Read the config file.
opts.merge_from_file()?;

Ok(opts)
}

pub fn parse_chain_specs(opts: &Opts) -> SupportedChainSpecs {
if let Some(cs_path) = &opts.chain_spec_path {
SupportedChainSpecs::merge_from_file(cs_path.clone()).expect("Failed to parse chain specs")
} else {
SupportedChainSpecs::default()
}
}

#[global_allocator]
static ALLOCATOR: Cap<alloc::System> = Cap::new(alloc::System, usize::MAX);

Expand Down
Loading