Skip to content

Commit

Permalink
Merge branch 'main'
Browse files Browse the repository at this point in the history
  • Loading branch information
35359595 committed May 17, 2024
2 parents 48bc58f + 65a6a8c commit 91ca30d
Show file tree
Hide file tree
Showing 39 changed files with 559 additions and 412 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:
with:
reporter: 'github-pr-check'
fail_on_error: true
clippy_flags: --workspace --all-targets --all-features -- -Dwarnings
clippy_flags: --workspace --all-targets --all-features -- -D warnings

fmt:
name: fmt
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions docker/docker-compose.metrics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ services:
volumes:
- './monitoring/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml'
- 'prometheus_storage:/prometheus'
network_mode: "host"
ports:
- "9090:9090"
extra_hosts:
- 'host.docker.internal:host-gateway'
grafana:
image: grafana/grafana:latest
container_name: grafana
restart: unless-stopped
network_mode: "host"
ports:
- "3000:3000"
volumes:
- 'grafana_storage:/var/lib/grafana'
volumes:
Expand Down
4 changes: 2 additions & 2 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ sgx = ["dep:sgx-prover", "sgx-prover/enable"]

[[bin]]
name = "raiko-host"
path = "src/main.rs"
path = "src/bin/main.rs"

[[bin]]
name = "docs"
path = "src/docs.rs"
path = "src/bin/docs.rs"
90 changes: 90 additions & 0 deletions host/config/chain_spec_list_default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[
{
"name": "ethereum",
"chain_id": 1,
"max_spec_id": "CANCUN",
"hard_forks": {
"FRONTIER": {
"Block": 0
},
"MERGE": {
"Block": 15537394
},
"SHANGHAI": {
"Block": 17034870
},
"CANCUN": {
"Timestamp": 1710338135
}
},
"eip_1559_constants": {
"base_fee_change_denominator": "0x8",
"base_fee_max_increase_denominator": "0x8",
"base_fee_max_decrease_denominator": "0x8",
"elasticity_multiplier": "0x2"
},
"l1_contract": null,
"l2_contract": null,
"rpc": "https://rpc.ankr.com/eth",
"beacon_rpc": "https://ethereum-beacon-api.publicnode.com",
"sgx_verifier_address": null,
"genesis_time": 1606824023,
"seconds_per_slot": 12,
"is_taiko": false
},
{
"name": "holesky",
"chain_id": 17000,
"max_spec_id": "CANCUN",
"hard_forks": {
"FRONTIER": {
"Block": 0
},
"SHANGHAI": {
"Timestamp": 1696000704
},
"CANCUN": {
"Timestamp": 1707305664
}
},
"eip_1559_constants": {
"base_fee_change_denominator": "0x8",
"base_fee_max_increase_denominator": "0x8",
"base_fee_max_decrease_denominator": "0x8",
"elasticity_multiplier": "0x2"
},
"l1_contract": null,
"l2_contract": null,
"rpc": "https://ethereum-holesky-rpc.publicnode.com",
"beacon_rpc": "https://api.holesky.blobscan.com",
"sgx_verifier_address": null,
"genesis_time": 1695902400,
"seconds_per_slot": 12,
"is_taiko": false
},
{
"name": "taiko_a7",
"chain_id": 167009,
"max_spec_id": "SHANGHAI",
"hard_forks": {
"SHANGHAI": {
"Block": 0
},
"CANCUN": "TBD"
},
"eip_1559_constants": {
"base_fee_change_denominator": "0x8",
"base_fee_max_increase_denominator": "0x8",
"base_fee_max_decrease_denominator": "0x8",
"elasticity_multiplier": "0x2"
},
"l1_contract": "0x79c9109b764609df928d16fc4a91e9081f7e87db",
"l2_contract": "0x1670090000000000000000000000000000010001",
"rpc": "https://rpc.hekla.taiko.xyz",
"beacon_rpc": null,
"sgx_verifier_address": "0x532efbf6d62720d0b2a2bb9d11066e8588cae6d9",
"genesis_time": 0,
"seconds_per_slot": 1,
"is_taiko": true
}
]
File renamed without changes.
2 changes: 1 addition & 1 deletion host/src/main.rs → host/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![allow(incomplete_features)]
use raiko_host::{error::HostResult, server::serve, ProverState};
use raiko_host::{interfaces::error::HostResult, server::serve, ProverState};
use std::{env, path::PathBuf};
use tracing::debug;
use tracing_appender::{
Expand Down
2 changes: 1 addition & 1 deletion host/src/error.rs → host/src/interfaces/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use axum::{http::StatusCode, response::IntoResponse};
use raiko_lib::prover::ProverError;
use utoipa::ToSchema;

use crate::request::ProofType;
use crate::interfaces::request::ProofType;

/// The standardized error returned by the Raiko host.
#[derive(thiserror::Error, Debug, ToSchema)]
Expand Down
2 changes: 2 additions & 0 deletions host/src/interfaces/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod error;
pub mod request;
65 changes: 18 additions & 47 deletions host/src/request.rs → host/src/interfaces/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{path::Path, str::FromStr};
use alloy_primitives::{Address, B256};
use clap::{Args, ValueEnum};
use raiko_lib::{
consts::Network,
input::{GuestInput, GuestOutput},
protocol_instance::ProtocolInstance,
prover::{Proof, Prover},
Expand All @@ -16,7 +15,7 @@ use serde_with::{serde_as, DisplayFromStr};
use utoipa::ToSchema;

use crate::{
error::{HostError, HostResult},
interfaces::error::{HostError, HostResult},
merge,
raiko::NativeProver,
};
Expand Down Expand Up @@ -107,20 +106,22 @@ impl ProofType {
.await
.map_err(|e| e.into()),
ProofType::Sp1 => {
#[cfg(feature = "sp1")]
return sp1_driver::Sp1Prover::run(input, output, config)
.await
.map_err(|e| e.into());

Err(HostError::FeatureNotSupportedError(self.clone()))
if cfg!(feature = "sp1") {
sp1_driver::Sp1Prover::run(input, output, config)
.await
.map_err(|e| e.into())
} else {
Err(HostError::FeatureNotSupportedError(self.clone()))
}
}
ProofType::Risc0 => {
#[cfg(feature = "risc0")]
return risc0_driver::Risc0Prover::run(input, output, config)
.await
.map_err(|e| e.into());

Err(HostError::FeatureNotSupportedError(self.clone()))
if cfg!(feature = "risc0") {
risc0_driver::Risc0Prover::run(input, output, config)
.await
.map_err(|e| e.into())
} else {
Err(HostError::FeatureNotSupportedError(self.clone()))
}
}
ProofType::Sgx => {
#[cfg(feature = "sgx")]
Expand All @@ -140,15 +141,8 @@ impl ProofType {
pub struct ProofRequest {
/// The block number for the block to generate a proof for.
pub block_number: u64,
/// RPC URL for retrieving block by block number.
pub rpc: String,
/// The L1 node URL for signal root verify and get txlist info from proposed
/// transaction.
pub l1_rpc: String,
/// The beacon node URL for retrieving data blobs.
pub beacon_rpc: String,
/// The network to generate the proof for.
pub network: Network,
pub network: String,
/// The L1 network to grnerate the proof for.
pub l1_network: String,
/// Graffiti.
Expand All @@ -171,16 +165,6 @@ pub struct ProofRequestOpt {
/// The block number for the block to generate a proof for.
pub block_number: Option<u64>,
#[arg(long, require_equals = true)]
/// RPC URL for retrieving block by block number.
pub rpc: Option<String>,
#[arg(long, require_equals = true)]
/// The L1 node URL for signal root verify and get txlist info from proposed
/// transaction.
pub l1_rpc: Option<String>,
#[arg(long, require_equals = true)]
/// The beacon node URL for retrieving data blobs.
pub beacon_rpc: Option<String>,
#[arg(long, require_equals = true)]
/// The network to generate the proof for.
pub network: Option<String>,
#[arg(long, require_equals = true)]
Expand Down Expand Up @@ -258,22 +242,9 @@ impl TryFrom<ProofRequestOpt> for ProofRequest {
block_number: value.block_number.ok_or(HostError::InvalidRequestConfig(
"Missing block number".to_string(),
))?,
rpc: value
.rpc
.ok_or(HostError::InvalidRequestConfig("Missing rpc".to_string()))?,
l1_rpc: value.l1_rpc.ok_or(HostError::InvalidRequestConfig(
"Missing l1_rpc".to_string(),
network: value.network.ok_or(HostError::InvalidRequestConfig(
"Missing network".to_string(),
))?,
beacon_rpc: value.beacon_rpc.ok_or(HostError::InvalidRequestConfig(
"Missing beacon_rpc".to_string(),
))?,
network: value
.network
.ok_or(HostError::InvalidRequestConfig(
"Missing network".to_string(),
))?
.parse()
.map_err(|_| HostError::InvalidRequestConfig("Invalid network".to_string()))?,
l1_network: value.l1_network.ok_or(HostError::InvalidRequestConfig(
"Missing l1_network".to_string(),
))?,
Expand Down
28 changes: 21 additions & 7 deletions host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod error;
pub mod interfaces;
pub mod metrics;
pub mod preflight;
pub mod provider_db;
pub mod provider;
pub mod raiko;
pub mod request;
pub mod rpc_provider;
pub mod server;

use std::{alloc, collections::HashMap, path::PathBuf};

use crate::interfaces::{error::HostResult, request::ProofRequestOpt};
use alloy_primitives::Address;
use alloy_rpc_types::EIP1186AccountProofResponse;
use anyhow::Context;
use cap::Cap;
use clap::Parser;
use raiko_lib::consts::SupportedChainSpecs;
use serde::{Deserialize, Serialize};
use serde_json::Value;

use crate::{error::HostResult, request::ProofRequestOpt};
use tracing::info;

type MerkleProof = HashMap<Address, EIP1186AccountProofResponse>;

Expand Down Expand Up @@ -90,6 +89,10 @@ pub struct Cli {
/// a proof of specified type. Curl json-rpc overrides its contents
config_path: PathBuf,

#[arg(long, require_equals = true)]
/// Path to a chain spec file that includes supported chain list
chain_spec_path: Option<PathBuf>,

#[arg(long, require_equals = true)]
/// Use a local directory as a cache for input. Accepts a custom directory.
cache_path: Option<PathBuf>,
Expand All @@ -113,6 +116,7 @@ impl Cli {
let mut config: Value = serde_json::from_reader(reader)?;
let this = serde_json::to_value(&self)?;
merge(&mut config, &this);

*self = serde_json::from_value(config)?;
Ok(())
}
Expand All @@ -135,6 +139,7 @@ fn merge(a: &mut Value, b: &Value) {
#[derive(Debug, Clone)]
pub struct ProverState {
pub opts: Cli,
pub chain_specs: SupportedChainSpecs,
}

impl ProverState {
Expand All @@ -144,14 +149,23 @@ impl ProverState {
// Read the config file.
opts.merge_from_file()?;

let chain_specs = if let Some(cs_path) = &opts.chain_spec_path {
let chain_specs = SupportedChainSpecs::merge_from_file(cs_path.clone())
.unwrap_or(SupportedChainSpecs::default());
info!("Supported chains: {:?}", chain_specs.supported_networks());
chain_specs
} 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() {
std::fs::create_dir_all(cache_path).context("Could not create cache dir")?;
}
}

Ok(Self { opts })
Ok(Self { opts, chain_specs })
}
}

Expand Down
2 changes: 1 addition & 1 deletion host/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use prometheus::{
IntCounterVec, IntGauge,
};

use crate::request::ProofType;
use crate::interfaces::request::ProofType;

lazy_static! {
pub static ref HOST_REQ_COUNT: IntCounterVec = register_int_counter_vec!(
Expand Down
Loading

0 comments on commit 91ca30d

Please sign in to comment.