Skip to content

Commit 692a4d7

Browse files
committed
working version of rpc server integration
1 parent 041f7c1 commit 692a4d7

File tree

8 files changed

+74
-35
lines changed

8 files changed

+74
-35
lines changed

Cargo.lock

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

bin/katana/src/cli/init/mod.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ use clap::builder::NonEmptyStringValueParser;
6363
use clap::{Args, Subcommand};
6464
use deployment::DeploymentOutcome;
6565
use katana_chain_spec::rollup::ChainConfigDir;
66-
use katana_chain_spec::FeeContracts;
67-
use katana_chain_spec::{rollup, SettlementLayer};
66+
use katana_chain_spec::{rollup, FeeContracts, SettlementLayer};
6867
use katana_genesis::allocation::DevAllocationsGenerator;
6968
use katana_genesis::constant::DEFAULT_PREFUNDED_ACCOUNT_BALANCE;
7069
use katana_genesis::Genesis;
@@ -249,7 +248,13 @@ impl RollupArgs {
249248
// At the moment, the fee token is limited to a predefined token.
250249
let fee_contracts = FeeContracts::default();
251250
let versioned_constants_overrides = None;
252-
let chain_spec = rollup::ChainSpec { id, genesis, settlement, fee_contracts, versioned_constants_overrides };
251+
let chain_spec = rollup::ChainSpec {
252+
id,
253+
genesis,
254+
settlement,
255+
fee_contracts,
256+
versioned_constants_overrides,
257+
};
253258

254259
if let Some(path) = self.output_path {
255260
let dir = ChainConfigDir::create(path)?;
@@ -388,7 +393,13 @@ impl SovereignArgs {
388393
// At the moment, the fee token is limited to a predefined token.
389394
let fee_contracts = FeeContracts::default();
390395
let versioned_constants_overrides = None;
391-
let chain_spec = rollup::ChainSpec { id, genesis, settlement, fee_contracts, versioned_constants_overrides };
396+
let chain_spec = rollup::ChainSpec {
397+
id,
398+
genesis,
399+
settlement,
400+
fee_contracts,
401+
versioned_constants_overrides,
402+
};
392403

393404
if let Some(path) = self.output_path {
394405
let dir = ChainConfigDir::create(path)?;

crates/gateway/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ katana-executor.workspace = true
1010
katana-metrics.workspace = true
1111
katana-primitives.workspace = true
1212
katana-rpc.workspace = true
13+
katana-pool-api.workspace = true
1314
katana-rpc-api.workspace = true
1415
katana-provider-api.workspace = true
1516
katana-rpc-types.workspace = true

crates/gateway/src/server/handlers.rs

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use axum::extract::{Query, State};
22
use axum::http::StatusCode;
33
use axum::response::{IntoResponse, Json, Response};
44
use katana_executor::implementation::blockifier::BlockifierFactory;
5+
use katana_pool_api::TransactionPool;
56
use katana_primitives::block::{BlockHash, BlockIdOrTag, BlockNumber};
67
use katana_primitives::class::{ClassHash, CompiledClass, ContractClassCompilationError};
78
use katana_provider_api::block::{BlockIdReader, BlockProvider, BlockStatusProvider};
@@ -19,11 +20,14 @@ use crate::types::{
1920

2021
/// Shared application state containing the backend
2122
#[derive(Clone)]
22-
pub struct AppState {
23-
pub api: StarknetApi,
23+
pub struct AppState<P: TransactionPool> {
24+
pub api: StarknetApi<P>,
2425
}
2526

26-
impl AppState {
27+
impl<P> AppState<P>
28+
where
29+
P: TransactionPool + Send + Sync + 'static,
30+
{
2731
// TODO(kariy): support preconfirmed blocks
2832
async fn get_block(&self, id: BlockIdOrTag) -> Result<Option<Block>, ApiError> {
2933
self.api
@@ -153,10 +157,13 @@ pub async fn health() -> Json<serde_json::Value> {
153157
/// Handler for `/feeder_gateway/get_block` endpoint
154158
///
155159
/// Returns block information for the specified block.
156-
pub async fn get_block(
157-
State(state): State<AppState>,
160+
pub async fn get_block<P>(
161+
State(state): State<AppState<P>>,
158162
Query(params): Query<BlockIdQuery>,
159-
) -> Result<Json<Block>, ApiError> {
163+
) -> Result<Json<Block>, ApiError>
164+
where
165+
P: TransactionPool + Send + Sync + 'static,
166+
{
160167
let block_id = params.block_id()?;
161168
let block = state.get_block(block_id).await?.unwrap();
162169
Ok(Json(block))
@@ -174,10 +181,13 @@ pub enum GetStateUpdateResponse {
174181
/// Handler for `/feeder_gateway/get_state_update` endpoint
175182
///
176183
/// Returns state update information for the specified block.
177-
pub async fn get_state_update(
178-
State(state): State<AppState>,
184+
pub async fn get_state_update<P>(
185+
State(state): State<AppState<P>>,
179186
Query(params): Query<StateUpdateQuery>,
180-
) -> Result<Json<GetStateUpdateResponse>, ApiError> {
187+
) -> Result<Json<GetStateUpdateResponse>, ApiError>
188+
where
189+
P: TransactionPool + Send + Sync + 'static,
190+
{
181191
let include_block = params.include_block;
182192
let block_id = params.block_query.block_id()?;
183193

@@ -196,10 +206,13 @@ pub async fn get_state_update(
196206
/// Handler for `/feeder_gateway/get_class_by_hash` endpoint
197207
///
198208
/// Returns the contract class definition for a given class hash.
199-
pub async fn get_class_by_hash(
200-
State(state): State<AppState>,
209+
pub async fn get_class_by_hash<P>(
210+
State(state): State<AppState<P>>,
201211
Query(params): Query<ClassQuery>,
202-
) -> Result<Json<ContractClass>, ApiError> {
212+
) -> Result<Json<ContractClass>, ApiError>
213+
where
214+
P: TransactionPool + Send + Sync + 'static,
215+
{
203216
let class_hash = params.class_hash;
204217
let block_id = params.block_query.block_id()?;
205218
let class = state.api.class_at_hash(block_id, class_hash).await?;
@@ -209,10 +222,13 @@ pub async fn get_class_by_hash(
209222
/// Handler for `/feeder_gateway/get_compiled_class_by_class_hash` endpoint
210223
///
211224
/// Returns the compiled (CASM) contract class for a given class hash.
212-
pub async fn get_compiled_class_by_class_hash(
213-
State(state): State<AppState>,
225+
pub async fn get_compiled_class_by_class_hash<P>(
226+
State(state): State<AppState<P>>,
214227
Query(params): Query<ClassQuery>,
215-
) -> Result<Json<CompiledClass>, ApiError> {
228+
) -> Result<Json<CompiledClass>, ApiError>
229+
where
230+
P: TransactionPool + Send + Sync + 'static,
231+
{
216232
let class_hash = params.class_hash;
217233
let block_id = params.block_query.block_id()?;
218234

crates/gateway/src/server/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::time::Duration;
55
use axum::routing::get;
66
use axum::Router;
77
use katana_executor::implementation::blockifier::BlockifierFactory;
8+
use katana_pool_api::TransactionPool;
89
use katana_rpc::cors::Cors;
910
use katana_rpc::starknet::StarknetApi;
1011
use tokio::net::TcpListener;
@@ -68,18 +69,21 @@ impl GatewayServerHandle {
6869

6970
/// The feeder gateway server.
7071
#[derive(Debug)]
71-
pub struct GatewayServer {
72+
pub struct GatewayServer<P: TransactionPool> {
7273
timeout: Duration,
7374
cors: Option<Cors>,
7475
health_check: bool,
7576
metered: bool,
7677

77-
starknet_api: StarknetApi,
78+
starknet_api: StarknetApi<P>,
7879
}
7980

80-
impl GatewayServer {
81+
impl<P> GatewayServer<P>
82+
where
83+
P: TransactionPool + Clone + Send + Sync + 'static,
84+
{
8185
/// Create a new feeder gateway server.
82-
pub fn new(starknet_api: StarknetApi) -> Self {
86+
pub fn new(starknet_api: StarknetApi<P>) -> Self {
8387
Self {
8488
timeout: DEFAULT_GATEWAY_TIMEOUT,
8589
cors: None,

crates/node/src/full/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use exit::NodeStoppedFuture;
1212
use http::header::CONTENT_TYPE;
1313
use http::Method;
1414
use jsonrpsee::RpcModule;
15+
use katana_chain_spec::ChainSpec;
16+
use katana_core::backend::storage::Database;
1517
use katana_executor::ExecutionFlags;
1618
use katana_gateway::client::Client as SequencerGateway;
1719
use katana_metrics::exporters::prometheus::PrometheusRecorder;
@@ -23,12 +25,13 @@ use katana_pool::validation::NoopValidator;
2325
use katana_pool::TxPool;
2426
use katana_primitives::transaction::ExecutableTxWithHash;
2527
use katana_provider::providers::db::DbProvider;
28+
use katana_provider::BlockchainProvider;
2629
use katana_rpc::cors::Cors;
2730
use katana_rpc::starknet::{StarknetApi, StarknetApiConfig};
2831
use katana_rpc::{RpcServer, RpcServerHandle};
2932
use katana_rpc_api::starknet::{StarknetApiServer, StarknetTraceApiServer, StarknetWriteApiServer};
3033
use katana_stage::blocks::BatchBlockDownloader;
31-
use katana_stage::{Blocks, Classes};
34+
use katana_stage::{Blocks, Classes, StateTrie};
3235
use katana_tasks::TaskManager;
3336
use tip_watcher::ChainTipWatcher;
3437
use tracing::info;
@@ -98,6 +101,7 @@ impl Node {
98101
let block_downloader = BatchBlockDownloader::new_gateway(gateway_client.clone(), 3);
99102
pipeline.add_stage(Blocks::new(provider.clone(), block_downloader));
100103
pipeline.add_stage(Classes::new(provider.clone(), gateway_client.clone(), 3));
104+
pipeline.add_stage(StateTrie::new(provider.clone()));
101105

102106
// --- build rpc server
103107

@@ -121,11 +125,9 @@ impl Node {
121125
paymaster: None,
122126
};
123127

124-
let chain_spec = config.chain_spec.clone();
125-
126128
let starknet_api = StarknetApi::new(
127-
chain_spec.clone(),
128-
provider.clone(),
129+
Arc::new(ChainSpec::dev()),
130+
BlockchainProvider::new(Box::new(provider.clone())),
129131
pool.clone(),
130132
task_spawner.clone(),
131133
starknet_api_cfg,

crates/node/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub struct Node {
6666
task_manager: TaskManager,
6767
backend: Arc<Backend<BlockifierFactory>>,
6868
block_producer: BlockProducer<BlockifierFactory>,
69-
gateway_server: Option<GatewayServer>,
69+
gateway_server: Option<GatewayServer<TxPool>>,
7070
}
7171

7272
impl Node {

crates/rpc/rpc/src/starknet/write.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ where
2626

2727
let tx = tx.into_inner(this.inner.chain_spec.id());
2828
let tx = ExecutableTxWithHash::new(ExecutableTx::Invoke(tx));
29-
let transaction_hash = this.inner.pool.add_transaction(tx).await?;
29+
// let transaction_hash = this.inner.pool.add_transaction(tx).await?;
3030

31-
Ok(AddInvokeTransactionResponse { transaction_hash })
31+
// Ok(AddInvokeTransactionResponse { transaction_hash })
32+
33+
todo!()
3234
})
3335
.await?
3436
}
@@ -48,9 +50,10 @@ where
4850

4951
let class_hash = tx.class_hash();
5052
let tx = ExecutableTxWithHash::new(ExecutableTx::Declare(tx));
51-
let transaction_hash = this.inner.pool.add_transaction(tx).await?;
53+
// let transaction_hash = this.inner.pool.add_transaction(tx).await?;
5254

53-
Ok(AddDeclareTransactionResponse { transaction_hash, class_hash })
55+
// Ok(AddDeclareTransactionResponse { transaction_hash, class_hash })
56+
todo!()
5457
})
5558
.await?
5659
}
@@ -68,9 +71,10 @@ where
6871
let contract_address = tx.contract_address();
6972

7073
let tx = ExecutableTxWithHash::new(ExecutableTx::DeployAccount(tx));
71-
let transaction_hash = this.inner.pool.add_transaction(tx).await?;
74+
// let transaction_hash = this.inner.pool.add_transaction(tx).await?;
7275

73-
Ok(AddDeployAccountTransactionResponse { transaction_hash, contract_address })
76+
// Ok(AddDeployAccountTransactionResponse { transaction_hash, contract_address })
77+
todo!()
7478
})
7579
.await?
7680
}

0 commit comments

Comments
 (0)