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): implement more feeder gateway types #2744

Merged
merged 15 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
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.

21 changes: 20 additions & 1 deletion crates/katana/executor/src/implementation/blockifier/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use katana_cairo::cairo_vm::types::errors::program_errors::ProgramError;
use katana_cairo::cairo_vm::vm::runners::cairo_runner::ExecutionResources;
use katana_cairo::starknet_api::block::{BlockNumber, BlockTimestamp};
use katana_cairo::starknet_api::core::{
self, ChainId, ClassHash, CompiledClassHash, ContractAddress, Nonce,
self, ChainId, ClassHash, CompiledClassHash, ContractAddress, EntryPointSelector, Nonce,
};
use katana_cairo::starknet_api::data_availability::DataAvailabilityMode;
use katana_cairo::starknet_api::deprecated_contract_class::EntryPointType;
Expand Down Expand Up @@ -184,6 +184,25 @@ pub fn to_executor_tx(tx: ExecutableTxWithHash) -> Transaction {

match tx.transaction {
ExecutableTx::Invoke(tx) => match tx {
InvokeTx::V0(tx) => {
let calldata = tx.calldata;
let signature = tx.signature;

Transaction::AccountTransaction(AccountTransaction::Invoke(InvokeTransaction {
tx: ApiInvokeTransaction::V0(
katana_cairo::starknet_api::transaction::InvokeTransactionV0 {
entry_point_selector: EntryPointSelector(tx.entry_point_selector),
contract_address: to_blk_address(tx.contract_address),
signature: TransactionSignature(signature),
calldata: Calldata(Arc::new(calldata)),
max_fee: Fee(tx.max_fee),
},
),
tx_hash: TransactionHash(hash),
only_query: false,
}))
}

InvokeTx::V1(tx) => {
let calldata = tx.calldata;
let signature = tx.signature;
Expand Down
1 change: 1 addition & 0 deletions crates/katana/feeder-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ katana-rpc-types.workspace = true

reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
starknet.workspace = true
thiserror.workspace = true
url.workspace = true
Expand Down
21 changes: 11 additions & 10 deletions crates/katana/feeder-gateway/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl SequencerGateway {
block_id: BlockIdOrTag,
) -> Result<StateUpdateWithBlock, Error> {
self.feeder_gateway("get_state_update")
.with_query_param("includeBlock", "true")
.add_query_param("includeBlock", "true")
.with_block_id(block_id)
.send()
.await
Expand All @@ -69,7 +69,7 @@ impl SequencerGateway {
block_id: BlockIdOrTag,
) -> Result<ContractClass, Error> {
self.feeder_gateway("get_class_by_hash")
.with_query_param("classHash", &format!("{hash:#x}"))
.add_query_param("classHash", &format!("{hash:#x}"))
.with_block_id(block_id)
.send()
.await
Expand All @@ -81,7 +81,7 @@ impl SequencerGateway {
block_id: BlockIdOrTag,
) -> Result<CasmContractClass, Error> {
self.feeder_gateway("get_compiled_class_by_class_hash")
.with_query_param("classHash", &format!("{hash:#x}"))
.add_query_param("classHash", &format!("{hash:#x}"))
.with_block_id(block_id)
.send()
.await
Expand Down Expand Up @@ -112,13 +112,13 @@ impl<'a> RequestBuilder<'a> {
match block_id {
// latest block is implied, if no block id specified
BlockIdOrTag::Tag(BlockTag::Latest) => self,
BlockIdOrTag::Tag(BlockTag::Pending) => self.with_query_param("blockNumber", "pending"),
BlockIdOrTag::Hash(hash) => self.with_query_param("blockHash", &format!("{hash:#x}")),
BlockIdOrTag::Number(num) => self.with_query_param("blockNumber", &num.to_string()),
BlockIdOrTag::Tag(BlockTag::Pending) => self.add_query_param("blockNumber", "pending"),
BlockIdOrTag::Hash(hash) => self.add_query_param("blockHash", &format!("{hash:#x}")),
BlockIdOrTag::Number(num) => self.add_query_param("blockNumber", &num.to_string()),
}
}

fn with_query_param(mut self, key: &str, value: &str) -> Self {
fn add_query_param(mut self, key: &str, value: &str) -> Self {
self.url.query_pairs_mut().append_pair(key, value);
self
}
Expand Down Expand Up @@ -181,6 +181,7 @@ pub enum ErrorCode {

#[cfg(test)]
mod tests {

use super::*;

#[test]
Expand Down Expand Up @@ -214,9 +215,9 @@ mod tests {
let req = RequestBuilder { client: &client, url: base_url };

let url = req
.with_query_param("param1", "value1")
.with_query_param("param2", "value2")
.with_query_param("param3", "value3")
.add_query_param("param1", "value1")
.add_query_param("param2", "value2")
.add_query_param("param3", "value3")
.url;

let query = url.query().unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
use std::collections::{BTreeMap, BTreeSet};

use katana_primitives::block::{BlockHash, BlockNumber, GasPrices};
pub use katana_primitives::class::CasmContractClass;
use katana_primitives::class::{
ClassHash, CompiledClassHash, LegacyContractClass, SierraContractClass,
};
use katana_primitives::contract::{Nonce, StorageKey, StorageValue};
use katana_primitives::da::L1DataAvailabilityMode;
use katana_primitives::version::ProtocolVersion;
use katana_primitives::{ContractAddress, Felt};
use katana_rpc_types::class::ConversionError;
pub use katana_rpc_types::class::RpcSierraContractClass;
use serde::Deserialize;
use starknet::providers::sequencer::models::Block;
use starknet::providers::sequencer::models::BlockStatus;

mod receipt;
mod transaction;

pub use receipt::*;
pub use transaction::*;

/// The contract class type returns by `/get_class_by_hash` endpoint.
#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -63,6 +72,31 @@ pub struct StateUpdateWithBlock {
pub block: Block,
}

#[derive(Debug, Deserialize)]
pub struct Block {
#[serde(default)]
pub block_hash: Option<BlockHash>,
#[serde(default)]
pub block_number: Option<BlockNumber>,
pub parent_block_hash: BlockHash,
pub timestamp: u64,
pub sequencer_address: Option<ContractAddress>,
#[serde(default)]
pub state_root: Option<Felt>,
#[serde(default)]
pub transaction_commitment: Option<Felt>,
#[serde(default)]
pub event_commitment: Option<Felt>,
pub status: BlockStatus,
pub l1_da_mode: L1DataAvailabilityMode,
pub l1_gas_price: GasPrices,
pub l1_data_gas_price: GasPrices,
pub transactions: Vec<ConfirmedTransaction>,
pub transaction_receipts: Vec<ConfirmedReceipt>,
#[serde(default)]
pub starknet_version: Option<ProtocolVersion>,
}

// -- Conversion to Katana primitive types.

impl TryFrom<ContractClass> for katana_primitives::class::ContractClass {
Expand Down
22 changes: 22 additions & 0 deletions crates/katana/feeder-gateway/src/types/receipt.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use katana_primitives::receipt::{Event, MessageToL1};
use katana_primitives::Felt;
use serde::Deserialize;
use starknet::providers::sequencer::models::{
ExecutionResources, L1ToL2Message, TransactionExecutionStatus,
};

#[derive(Debug, Deserialize)]
pub struct ConfirmedReceipt {
pub transaction_hash: Felt,
pub transaction_index: u64,
#[serde(default)]
pub execution_status: Option<TransactionExecutionStatus>,
#[serde(default)]
pub revert_error: Option<String>,
#[serde(default)]
pub execution_resources: Option<ExecutionResources>,
pub l1_to_l2_consumed_message: Option<L1ToL2Message>,
pub l2_to_l1_messages: Vec<MessageToL1>,
pub events: Vec<Event>,
pub actual_fee: Felt,
}
Loading
Loading