Skip to content

Commit cc11cd3

Browse files
committed
wip
1 parent ba73d38 commit cc11cd3

File tree

12 files changed

+77
-237
lines changed

12 files changed

+77
-237
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cli/Cargo.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ katana-executor.workspace = true
1212
katana-messaging.workspace = true
1313
katana-node.workspace = true
1414
katana-genesis.workspace = true
15-
katana-pool.workspace = true
16-
katana-pool-api.workspace = true
1715
katana-primitives.workspace = true
1816
katana-provider.workspace = true
1917
katana-rpc-server.workspace = true
20-
katana-rpc-types.workspace = true
2118
katana-slot-controller = { workspace = true, optional = true }
2219
katana-tee = { workspace = true, optional = true }
2320
katana-tracing.workspace = true
@@ -30,11 +27,9 @@ alloy-primitives.workspace = true
3027
anyhow.workspace = true
3128
clap.workspace = true
3229
console.workspace = true
33-
futures.workspace = true
3430
serde.workspace = true
3531
serde_json.workspace = true
3632
shellexpand = "3.1.0"
37-
starknet = { workspace = true, optional = true }
3833
tokio.workspace = true
3934
toml.workspace = true
4035
tracing.workspace = true
@@ -49,7 +44,6 @@ starknet.workspace = true
4944
paymaster = [
5045
"dep:katana-paymaster",
5146
"dep:katana-slot-controller",
52-
"dep:starknet",
5347
"katana-node/paymaster",
5448
"katana-rpc-server/paymaster",
5549
]

crates/cli/src/args.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl SequencerNodeArgs {
169169
let config = self.config()?;
170170

171171
#[cfg(feature = "vrf")]
172-
let vrf_sidecar = match self.vrf_config(&config.rpc)? {
172+
let vrf_sidecar = match self.vrf_config()? {
173173
Some((_, sidecar)) => sidecar,
174174
None => None,
175175
};
@@ -292,7 +292,7 @@ impl SequencerNodeArgs {
292292
let paymaster = self.paymaster_config(&chain)?.map(|(config, _)| config);
293293

294294
#[cfg(feature = "vrf")]
295-
let vrf = self.vrf_config(&rpc)?.map(|(config, _)| config);
295+
let vrf = self.vrf_config()?.map(|(config, _)| config);
296296

297297
#[cfg(all(feature = "vrf", feature = "cartridge"))]
298298
if vrf.is_some() && paymaster.is_none() {
@@ -630,9 +630,8 @@ impl SequencerNodeArgs {
630630
#[cfg(feature = "vrf")]
631631
fn vrf_config(
632632
&self,
633-
rpc_config: &RpcConfig,
634633
) -> Result<Option<(katana_node::config::paymaster::VrfConfig, Option<VrfSidecarInfo>)>> {
635-
build_vrf_config(&self.vrf, Some(rpc_config.socket_addr()))
634+
build_vrf_config(&self.vrf)
636635
}
637636

638637
#[cfg(feature = "tee")]

crates/cli/src/options.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl PaymasterOptions {
641641
}
642642

643643
#[cfg(feature = "vrf")]
644-
#[derive(Debug, Args, Clone, Serialize, Deserialize, PartialEq)]
644+
#[derive(Debug, Default, Args, Clone, Serialize, Deserialize, PartialEq)]
645645
#[command(next_help_heading = "VRF options")]
646646
pub struct VrfOptions {
647647
/// Enable the VRF service.
@@ -660,19 +660,6 @@ pub struct VrfOptions {
660660
#[serde(default)]
661661
pub url: Option<Url>,
662662

663-
/// Port to bind the sidecar VRF service on (vrf-server uses 3000).
664-
///
665-
/// Only used when running in sidecar mode. Not applicable if `--vrf.url` is provided.
666-
#[arg(conflicts_with = "vrf_url")]
667-
#[arg(
668-
long = "vrf.port",
669-
value_name = "PORT",
670-
id = "vrf_port",
671-
default_value_t = default_vrf_port()
672-
)]
673-
#[serde(default = "default_vrf_port")]
674-
pub port: u16,
675-
676663
/// Optional path to the VRF sidecar binary (defaults to `vrf-server` in PATH).
677664
///
678665
/// Only used when running in sidecar mode. Not applicable if `--vrf.url` is provided.
@@ -682,13 +669,6 @@ pub struct VrfOptions {
682669
pub bin: Option<PathBuf>,
683670
}
684671

685-
#[cfg(feature = "vrf")]
686-
impl Default for VrfOptions {
687-
fn default() -> Self {
688-
VrfOptions { enabled: false, url: None, port: default_vrf_port(), bin: None }
689-
}
690-
}
691-
692672
#[cfg(feature = "vrf")]
693673
impl VrfOptions {
694674
/// Returns true if the VRF is enabled (either explicitly or via URL).
@@ -711,10 +691,6 @@ impl VrfOptions {
711691
self.url = other.url.clone();
712692
}
713693

714-
if self.port == default_vrf_port() {
715-
self.port = other.port;
716-
}
717-
718694
if self.bin.is_none() {
719695
self.bin = other.bin.clone();
720696
}
@@ -867,11 +843,6 @@ fn default_api_url() -> Url {
867843
Url::parse("https://api.cartridge.gg").expect("qed; invalid url")
868844
}
869845

870-
#[cfg(feature = "vrf")]
871-
fn default_vrf_port() -> u16 {
872-
3000
873-
}
874-
875846
#[derive(Debug, Default, Args, Clone, Serialize, Deserialize, PartialEq)]
876847
#[command(next_help_heading = "Tracer options")]
877848
pub struct TracerOptions {

crates/cli/src/sidecar.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ pub struct PaymasterSidecarInfo {
6363
#[cfg(feature = "vrf")]
6464
pub fn build_vrf_config(
6565
options: &VrfOptions,
66-
rpc_addr: Option<SocketAddr>,
6766
) -> Result<Option<(VrfConfig, Option<VrfSidecarInfo>)>> {
6867
if !options.is_enabled() {
6968
return Ok(None);
@@ -77,20 +76,16 @@ pub fn build_vrf_config(
7776
let url = options.url.clone().expect("URL must be set in external mode");
7877
(url, None)
7978
} else {
80-
// Sidecar mode: use configured port (VRF server uses fixed port 3000)
81-
let port = options.port;
82-
let url = Url::parse(&format!("http://127.0.0.1:{port}")).expect("valid url");
79+
// Sidecar mode: find a free port dynamically
80+
let listener = std::net::TcpListener::bind("127.0.0.1:0")?;
81+
let addr = listener.local_addr()?;
82+
let port = addr.port();
83+
let url = Url::parse(&format!("http://{addr}"))?;
8384
let sidecar_info = VrfSidecarInfo { port };
8485
(url, Some(sidecar_info))
8586
};
8687

87-
// Construct RPC URL for VRF server to query state
88-
let rpc_url =
89-
rpc_addr.map(|addr| Url::parse(&format!("http://{addr}"))).transpose().expect("valid URL");
90-
91-
let config = VrfConfig { url, rpc_url };
92-
93-
Ok(Some((config, sidecar_info)))
88+
Ok(Some((VrfConfig { url }, sidecar_info)))
9489
}
9590

9691
// ============================================================================

crates/node/src/config/paymaster.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use url::Url;
2-
31
#[cfg(feature = "cartridge")]
42
use katana_primitives::{ContractAddress, Felt};
3+
use url::Url;
54

65
#[derive(Debug, Clone, PartialEq, Eq)]
76
pub struct PaymasterConfig {
@@ -22,8 +21,6 @@ pub struct PaymasterConfig {
2221
pub struct VrfConfig {
2322
/// The VRF service URL.
2423
pub url: Url,
25-
/// RPC URL for VRF server to query state (for Nonce-based seed computation).
26-
pub rpc_url: Option<Url>,
2724
}
2825

2926
/// Configuration for connecting to a Cartridge paymaster service.

crates/node/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,16 @@ where
233233

234234
#[cfg(feature = "vrf")]
235235
let vrf = if let Some(vrf) = &config.vrf {
236+
use url::Url;
237+
236238
let derived = crate::sidecar::derive_vrf_accounts(vrf, &config, &backend)?;
239+
let rpc_url = Url::parse(&format!("http://{}", config.rpc.socket_addr()))
240+
.expect("valid rpc url");
241+
237242
Some(katana_rpc_server::cartridge::VrfServiceConfig {
243+
rpc_url,
238244
url: vrf.url.clone(),
239245
account_address: derived.vrf_account_address,
240-
rpc_url: vrf.rpc_url.clone(),
241246
})
242247
} else {
243248
None

crates/paymaster/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,9 @@ repository.workspace = true
66
version.workspace = true
77

88
[dependencies]
9-
katana-genesis.workspace = true
109
katana-primitives.workspace = true
11-
katana-rpc-client.workspace = true
12-
katana-rpc-types.workspace = true
1310

1411
anyhow.workspace = true
15-
futures.workspace = true
1612
reqwest.workspace = true
1713
serde.workspace = true
1814
serde_json.workspace = true
@@ -22,4 +18,5 @@ tracing.workspace = true
2218
url.workspace = true
2319

2420
[dev-dependencies]
21+
katana-genesis.workspace = true
2522
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

0 commit comments

Comments
 (0)