Skip to content
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
4 changes: 4 additions & 0 deletions 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 crates/cli/src/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ impl FullNodeArgs {
fn sync_source(&self) -> Option<SyncSource> {
if let Some(ref url) = self.sync.rpc {
Some(SyncSource::JsonRpc(url.clone()))
} else if let Some(ref url) = self.sync.grpc {
Some(SyncSource::Grpc(url.clone()))
} else {
self.sync.gateway.clone().map(SyncSource::Gateway)
}
Expand Down
16 changes: 14 additions & 2 deletions crates/cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ pub struct SyncOptions {
/// feeder gateway.
#[arg(long = "sync.gateway")]
#[arg(value_name = "URL")]
#[arg(conflicts_with = "rpc")]
#[arg(conflicts_with_all = ["rpc", "grpc"])]
pub gateway: Option<Url>,

/// JSON-RPC endpoint URL to use as the block download source instead of
Expand All @@ -1004,9 +1004,20 @@ pub struct SyncOptions {
/// This is mainly intended for development and testing purposes.
#[arg(long = "sync.rpc")]
#[arg(value_name = "URL")]
#[arg(conflicts_with = "gateway")]
#[arg(conflicts_with_all = ["gateway", "grpc"])]
pub rpc: Option<Url>,

/// gRPC endpoint URL to use as the block download source (e.g.,
/// `http://localhost:5051`). When set, blocks are fetched via
/// gRPC from another Katana node's gRPC server.
///
/// This is a Katana-specific endpoint and only works when syncing
/// from another Katana node with `--grpc` enabled.
#[arg(long = "sync.grpc")]
#[arg(value_name = "URL")]
#[arg(conflicts_with_all = ["gateway", "rpc"])]
pub grpc: Option<Url>,

/// Maximum number of blocks to process per pipeline iteration before
/// advancing to the next chunk.
#[arg(long = "sync.chunk-size")]
Expand All @@ -1030,6 +1041,7 @@ impl Default for SyncOptions {
tip: None,
gateway: None,
rpc: None,
grpc: None,
chunk_size: katana_full_node::DEFAULT_SYNC_CHUNK_SIZE,
download_batch_size: katana_full_node::DEFAULT_DOWNLOAD_BATCH_SIZE,
}
Expand Down
2 changes: 2 additions & 0 deletions crates/grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ num-bigint.workspace = true
tower-service.workspace = true

[dev-dependencies]
katana-starknet.workspace = true
url.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
hex = "0.4"
katana-utils = { workspace = true, features = ["node"] }
Expand Down
14 changes: 9 additions & 5 deletions crates/grpc/proto/starknet.proto
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ message GetClassRequest {
}

message GetClassResponse {
oneof result {
types.DeprecatedContractClass deprecated_contract_class = 1;
types.ContractClass contract_class = 2;
// JSON-serialized class bytes. The class types are not compatible with
// non-human-readable serialization, so we use JSON here.
oneof Class {
bytes sierra = 1;
bytes legacy = 2;
}
}

Expand All @@ -216,9 +218,11 @@ message GetClassAtRequest {
}

message GetClassAtResponse {
// JSON-serialized class bytes. The class types are not compatible with
// non-human-readable serialization, so we use JSON here.
oneof result {
types.DeprecatedContractClass deprecated_contract_class = 1;
types.ContractClass contract_class = 2;
bytes contract_class = 1;
bytes deprecated_contract_class = 2;
}
}

Expand Down
46 changes: 23 additions & 23 deletions crates/grpc/src/handlers/starknet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::protos::starknet::starknet_server::Starknet;
use crate::protos::starknet::starknet_trace_server::StarknetTrace;
use crate::protos::starknet::starknet_write_server::StarknetWrite;
use crate::protos::starknet::{
AddDeclareTransactionRequest, AddDeclareTransactionResponse,
get_class_response, AddDeclareTransactionRequest, AddDeclareTransactionResponse,
AddDeployAccountTransactionRequest, AddDeployAccountTransactionResponse,
AddInvokeTransactionRequest, AddInvokeTransactionResponse, BlockHashAndNumberRequest,
BlockHashAndNumberResponse, BlockNumberRequest, BlockNumberResponse, CallRequest, CallResponse,
Expand Down Expand Up @@ -243,18 +243,15 @@ where
.try_into()?;

let class = self.api.class_at_hash(block_id, class_hash).await.into_grpc_result()?;
let json = serde_json::to_vec(&class)
.map_err(|e| Status::internal(format!("failed to serialize class: {e}")))?;

// Convert class to proto - simplified for now
Ok(Response::new(GetClassResponse {
result: Some(crate::protos::starknet::get_class_response::Result::ContractClass(
crate::protos::types::ContractClass {
sierra_program: Vec::new(), // Would need full conversion
contract_class_version: String::new(),
entry_points_by_type: None,
abi: serde_json::to_string(&class).unwrap_or_default(),
},
)),
}))
let serialized = match class {
katana_rpc_types::Class::Sierra(_) => get_class_response::Class::Sierra(json),
katana_rpc_types::Class::Legacy(_) => get_class_response::Class::Legacy(json),
};

Ok(Response::new(GetClassResponse { class: Some(serialized) }))
}

async fn get_class_hash_at(
Expand Down Expand Up @@ -287,18 +284,21 @@ where

let class =
self.api.class_at_address(block_id, contract_address).await.into_grpc_result()?;
let json = serde_json::to_vec(&class)
.map_err(|e| Status::internal(format!("failed to serialize class: {e}")))?;

// Convert class to proto - simplified for now
Ok(Response::new(GetClassAtResponse {
result: Some(crate::protos::starknet::get_class_at_response::Result::ContractClass(
crate::protos::types::ContractClass {
sierra_program: Vec::new(),
contract_class_version: String::new(),
entry_points_by_type: None,
abi: serde_json::to_string(&class).unwrap_or_default(),
},
)),
}))
let result = match class {
katana_rpc_types::Class::Sierra(_) => {
crate::protos::starknet::get_class_at_response::Result::ContractClass(json)
}
katana_rpc_types::Class::Legacy(_) => {
crate::protos::starknet::get_class_at_response::Result::DeprecatedContractClass(
json,
)
}
};

Ok(Response::new(GetClassAtResponse { result: Some(result) }))
}

async fn get_block_transaction_count(
Expand Down
Loading
Loading