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(katana) : add explorer flag and build folder #2997

Merged
merged 26 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
242fbe0
feat: add explorer flag and build folder
ayushtom Feb 6, 2025
16f22bd
chore: remove warnings and modify startup workflow
ayushtom Feb 6, 2025
a0d8a40
chore: remove build files
ayushtom Feb 21, 2025
ef5bde1
feat: add updated env config
ayushtom Feb 22, 2025
2fbab4c
Merge branch 'main' into ayush/add-explorer-flag
ayushtom Feb 22, 2025
fa79a35
chore: update commit hash
ayushtom Feb 25, 2025
fbede5a
chore: update env variable
ayushtom Feb 25, 2025
02c87e4
chore: add coderabbit changes
ayushtom Feb 25, 2025
e3aba2a
chore: update with explorer crate and rust-embed
ayushtom Feb 26, 2025
3853e0e
chore: add build files and remove submodule config
ayushtom Feb 26, 2025
b22a91e
chore: resolve coderabbit comments
ayushtom Feb 26, 2025
7a64fd9
style and move all explorer into its own crate
kariy Feb 26, 2025
741daa9
parse url
kariy Feb 26, 2025
34d4bcc
chore: update to use submodule in build in ci
ayushtom Feb 26, 2025
fdadaee
chore: update with advanced path sanitization
ayushtom Feb 26, 2025
0686b5d
Update .gitignore
kariy Feb 26, 2025
53da7d7
chore: update remote url
ayushtom Feb 26, 2025
f89577c
prevent explorer port from being 0 in the cli
kariy Feb 26, 2025
bf1e274
chore: update ci workflow
ayushtom Feb 26, 2025
3e86793
chore: add ci logs
ayushtom Feb 26, 2025
97a2abc
chore: add additional logs
ayushtom Feb 26, 2025
5ebce04
chore: update ci
ayushtom Feb 28, 2025
de7c0dc
chore: make force submodule add
ayushtom Feb 28, 2025
a743631
chore: add dependency in test workflow
ayushtom Feb 28, 2025
89c67cf
chore: update workflow
ayushtom Feb 28, 2025
685d7d0
fix: clippy and docs workflow
ayushtom Feb 28, 2025
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
33 changes: 32 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,44 @@ env:
RUST_VERSION: 1.81.0

jobs:
build-explorer:
runs-on: ubuntu-latest
needs: [fmt, cairofmt]
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Initialize submodules
run: |
git submodule update --init --recursive
ls -la crates/katana/explorer/ui
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Build Explorer UI
run: |
cd crates/katana/explorer/ui
bun install
bun run build
- uses: actions/upload-artifact@v4
with:
name: explorer-dist
path: crates/katana/explorer/ui/dist

build:
runs-on: ubuntu-latest-4-cores
needs: [fmt, cairofmt]
needs: [fmt, cairofmt, build-explorer]
container:
image: ghcr.io/dojoengine/dojo-dev:v1.2.1
steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/download-artifact@v4
with:
name: explorer-dist
path: crates/katana/explorer/ui/dist
- uses: Swatinem/rust-cache@v2
- run: |
cargo build -r --bin katana
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ examples/spawn-and-move/manifests/saya/**
**/*.log

artifacts/

crates/katana/explorer/ui
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
[submodule "crates/katana/contracts/piltover"]
path = crates/katana/contracts/piltover
url = https://github.com/keep-starknet-strange/piltover.git
[submodule "crates/katana/explorer/ui"]
path = crates/katana/explorer/ui
url = https://github.com/cartridge-gg/explorer
branch = main
73 changes: 72 additions & 1 deletion Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"crates/katana/cli",
"crates/katana/controller",
"crates/katana/core",
"crates/katana/explorer",
"crates/katana/executor",
"crates/katana/feeder-gateway",
"crates/katana/grpc",
Expand Down Expand Up @@ -98,6 +99,7 @@ katana-codecs-derive = { path = "crates/katana/storage/codecs/derive" }
katana-core = { path = "crates/katana/core", default-features = false }
katana-db = { path = "crates/katana/storage/db" }
katana-executor = { path = "crates/katana/executor" }
katana-explorer = { path = "crates/katana/explorer" }
katana-feeder-gateway = { path = "crates/katana/feeder-gateway" }
katana-messaging = { path = "crates/katana/messaging" }
katana-node = { path = "crates/katana/node", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions crates/katana/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version.workspace = true
[dependencies]
katana-chain-spec.workspace = true
katana-core.workspace = true
katana-explorer.workspace = true
katana-messaging.workspace = true
katana-node.workspace = true
katana-primitives.workspace = true
Expand Down
37 changes: 36 additions & 1 deletion crates/katana/cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Katana node CLI options and configuration.

use std::net::SocketAddr;
use std::path::PathBuf;
use std::sync::Arc;

Expand All @@ -11,6 +12,7 @@ use clap::Parser;
use katana_chain_spec::rollup::ChainConfigDir;
use katana_chain_spec::ChainSpec;
use katana_core::constants::DEFAULT_SEQUENCER_ADDRESS;
use katana_explorer::Explorer;
use katana_messaging::MessagingConfig;
use katana_node::config::db::DbConfig;
use katana_node::config::dev::{DevConfig, FixedL1GasPriceConfig};
Expand All @@ -24,6 +26,7 @@ use katana_node::config::sequencing::SequencingConfig;
use katana_node::config::Config;
use katana_primitives::genesis::allocation::DevAllocationsGenerator;
use katana_primitives::genesis::constant::DEFAULT_PREFUNDED_ACCOUNT_BALANCE;
use katana_rpc::cors::HeaderValue;
use serde::{Deserialize, Serialize};
use tracing::{info, Subscriber};
use tracing_log::LogTracer;
Expand Down Expand Up @@ -115,6 +118,9 @@ pub struct NodeArgs {
#[cfg(feature = "slot")]
#[command(flatten)]
pub slot: SlotOptions,

#[command(flatten)]
pub explorer: ExplorerOptions,
}

impl NodeArgs {
Expand All @@ -135,6 +141,14 @@ impl NodeArgs {
// Launch the node
let handle = node.launch().await.context("failed to launch node")?;

// Then start the explorer if enabled
if self.explorer.explorer {
let rpc_url = format!("http://{}", handle.rpc.addr());
let rpc_url = Url::parse(&rpc_url).context("failed to parse node url")?;
let addr = SocketAddr::new(self.explorer.explorer_addr, self.explorer.explorer_port);
let _ = Explorer::new(rpc_url)?.start(addr)?;
}

// Wait until an OS signal (ie SIGINT, SIGTERM) is received or the node is shutdown.
tokio::select! {
_ = dojo_utils::signal::wait_signals() => {
Expand Down Expand Up @@ -229,14 +243,35 @@ impl NodeArgs {
modules
};

let mut cors_origins = self.server.http_cors_origins.clone();

// Add explorer URL to CORS origins if explorer is enabled
if self.explorer.explorer {
// Add both http://127.0.0.1:PORT and http://localhost:PORT
cors_origins.push(
HeaderValue::from_str(&format!(
"http://127.0.0.1:{}",
self.explorer.explorer_port
))
.context("Failed to create CORS header")?,
);
cors_origins.push(
HeaderValue::from_str(&format!(
"http://localhost:{}",
self.explorer.explorer_port
))
.context("Failed to create CORS header")?,
);
}

Ok(RpcConfig {
apis: modules,
port: self.server.http_port,
addr: self.server.http_addr,
max_connections: self.server.max_connections,
cors_origins,
max_request_body_size: None,
max_response_body_size: None,
cors_origins: self.server.http_cors_origins.clone(),
max_event_page_size: Some(self.server.max_event_page_size),
max_proof_keys: Some(self.server.max_proof_keys),
max_call_gas: Some(self.server.max_call_gas),
Expand Down
42 changes: 42 additions & 0 deletions crates/katana/cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#[cfg(feature = "server")]
use std::net::IpAddr;
use std::net::Ipv4Addr;

use clap::Args;
use katana_node::config::execution::{DEFAULT_INVOCATION_MAX_STEPS, DEFAULT_VALIDATION_MAX_STEPS};
Expand Down Expand Up @@ -409,6 +410,47 @@ pub struct SlotOptions {
pub controller: bool,
}

const DEFAULT_EXPLORER_ADDR: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST);
const DEFAULT_EXPLORER_PORT: u16 = 3001;

#[derive(Debug, Args, Clone, Serialize, Deserialize, PartialEq)]
#[command(next_help_heading = "Explorer options")]
pub struct ExplorerOptions {
/// Enable and launch the explorer frontend
///
/// This will start a web server that serves the explorer UI.
#[arg(long)]
#[serde(default)]
pub explorer: bool,

/// The address to run the explorer frontend on.
#[arg(long = "explorer.addr", value_name = "ADDRESS")]
#[arg(default_value_t = DEFAULT_EXPLORER_ADDR)]
pub explorer_addr: IpAddr,

/// The port to run the explorer frontend on.
///
/// NOTE(@kariy):
// Right now we prevent the port from being 0 because that would mean the actual port would only
// be available after the server has been started. And due to some limitations with how the
// explorer requires that the node is started first (to get the actual socket address) and
// that we also need to pass the explorer address as CORS to the node server.
#[arg(long = "explorer.port", value_name = "PORT")]
#[arg(default_value_t = DEFAULT_EXPLORER_PORT)]
#[arg(value_parser = clap::value_parser!(u16).range(1..))]
pub explorer_port: u16,
}

impl Default for ExplorerOptions {
fn default() -> Self {
Self {
explorer: false,
explorer_addr: DEFAULT_EXPLORER_ADDR,
explorer_port: DEFAULT_EXPLORER_PORT,
}
}
}

// ** Default functions to setup serde of the configuration file **
fn default_seed() -> String {
DEFAULT_DEV_SEED.to_string()
Expand Down
14 changes: 14 additions & 0 deletions crates/katana/explorer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "katana-explorer"
version.workspace = true
edition.workspace = true
repository.workspace = true
license-file.workspace = true

[dependencies]
anyhow.workspace = true
url.workspace = true
tiny_http = "0.12"
tracing.workspace = true
urlencoding = "2.1.2"
rust-embed = "6.8.1"
Loading