Skip to content

Commit

Permalink
Merge pull request #2387 from eqlabs/t00ts/rpc-refactor
Browse files Browse the repository at this point in the history
feat(rpc): Remove support for `v02` and `v03` RPC versions
  • Loading branch information
t00ts authored Nov 20, 2024
2 parents 0451be8 + c7e21df commit 333ceb3
Show file tree
Hide file tree
Showing 57 changed files with 493 additions and 3,874 deletions.
4 changes: 2 additions & 2 deletions crates/pathfinder/src/monitoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::atomic::AtomicBool;
use std::sync::Arc;

use metrics_exporter_prometheus::PrometheusHandle;
use pathfinder_rpc::v02::types::syncing::Syncing;
use pathfinder_rpc::types::syncing::Syncing;
use pathfinder_rpc::SyncState;

#[derive(Clone)]
Expand Down Expand Up @@ -86,7 +86,7 @@ mod tests {

use metrics_exporter_prometheus::PrometheusBuilder;
use pathfinder_common::BlockNumber;
use pathfinder_rpc::v02::types::syncing::{NumberedBlock, Status, Syncing};
use pathfinder_rpc::types::syncing::{NumberedBlock, Status, Syncing};
use pathfinder_rpc::SyncState;
use tokio::sync::RwLock;

Expand Down
2 changes: 1 addition & 1 deletion crates/pathfinder/src/state/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use pathfinder_crypto::Felt;
use pathfinder_ethereum::{EthereumApi, EthereumStateUpdate};
use pathfinder_merkle_tree::contract_state::update_contract_state;
use pathfinder_merkle_tree::{ClassCommitmentTree, StorageCommitmentTree};
use pathfinder_rpc::v02::types::syncing::{self, NumberedBlock, Syncing};
use pathfinder_rpc::types::syncing::{self, NumberedBlock, Syncing};
use pathfinder_rpc::{Notifications, PendingData, Reorg, SyncState, TopicBroadcasters};
use pathfinder_storage::{Connection, Storage, Transaction, TransactionBehavior};
use primitive_types::H160;
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/src/dto/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde_with::ser::SerializeAsWrap;
use super::U64Hex;
use crate::dto::serialize::SerializeForVersion;
use crate::dto::{serialize, Felt};
use crate::v02::types;
use crate::types;

pub struct DeprecatedContractClass<'a>(pub &'a types::CairoContractClass);
pub struct ContractClass<'a>(pub &'a types::SierraContractClass);
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/src/dto/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::serialize::SerializeForVersion;
use super::{DeserializeForVersion, Value};
use crate::dto::serialize::{self, Serializer};

pub struct SyncStatus<'a>(pub &'a crate::v02::types::syncing::Status);
pub struct SyncStatus<'a>(pub &'a crate::types::syncing::Status);

pub struct Felt<'a>(pub &'a pathfinder_crypto::Felt);
pub struct BlockHash<'a>(pub &'a pathfinder_common::BlockHash);
Expand Down Expand Up @@ -309,8 +309,8 @@ mod tests {

#[test]
fn sync_status() {
use crate::v02::types::syncing::NumberedBlock;
let status = crate::v02::types::syncing::Status {
use crate::types::syncing::NumberedBlock;
let status = crate::types::syncing::Status {
starting: NumberedBlock {
number: pathfinder_common::BlockNumber::GENESIS,
hash: block_hash!("0x123"),
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use pathfinder_common::{ChainId, StarknetVersion};
use pathfinder_executor::{ClassInfo, IntoStarkFelt};
use starknet_api::core::PatriciaKey;

use crate::v02::types::request::{
use crate::types::request::{
BroadcastedDeployAccountTransaction,
BroadcastedInvokeTransaction,
BroadcastedTransaction,
};
use crate::v02::types::SierraContractClass;
use crate::types::SierraContractClass;

pub enum ExecutionStateError {
BlockNotFound,
Expand All @@ -29,7 +29,7 @@ pub(crate) fn map_broadcasted_transaction(
transaction: &BroadcastedTransaction,
chain_id: ChainId,
) -> anyhow::Result<pathfinder_executor::Transaction> {
use crate::v02::types::request::BroadcastedDeclareTransaction;
use crate::types::request::BroadcastedDeclareTransaction;

let class_info = match &transaction {
BroadcastedTransaction::Declare(BroadcastedDeclareTransaction::V0(tx)) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/src/jsonrpc/router/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ mod tests {
SubscriptionMessage,
};
use crate::pending::PendingWatcher;
use crate::v02::types::syncing::Syncing;
use crate::types::syncing::Syncing;
use crate::{Notifications, SyncState};

#[tokio::test]
Expand Down
7 changes: 3 additions & 4 deletions crates/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ mod pathfinder;
mod pending;
#[cfg(test)]
mod test_setup;
pub mod v02;
pub mod v03;
pub mod types;
pub mod v06;
pub mod v07;
pub mod v08;
Expand All @@ -39,7 +38,7 @@ use tower_http::ServiceBuilderExt;
use crate::jsonrpc::rpc_handler;
use crate::jsonrpc::websocket::websocket_handler;
pub use crate::jsonrpc::websocket::{BlockHeader, TopicBroadcasters};
use crate::v02::types::syncing::Syncing;
use crate::types::syncing::Syncing;

const DEFAULT_MAX_CONNECTIONS: usize = 1024;

Expand Down Expand Up @@ -832,7 +831,7 @@ mod tests {

#[test]
fn roundtrip_syncing() {
use crate::v02::types::syncing::{NumberedBlock, Status, Syncing};
use crate::types::syncing::{NumberedBlock, Status, Syncing};

let examples = [
(line!(), "false", Syncing::False(false)),
Expand Down
10 changes: 5 additions & 5 deletions crates/rpc/src/method/add_declare_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use starknet_gateway_types::request::add_transaction::{
};

use crate::context::RpcContext;
use crate::v02::types::request::BroadcastedDeclareTransaction;
use crate::types::request::BroadcastedDeclareTransaction;

#[derive(Debug)]
pub enum AddDeclareTransactionError {
Expand Down Expand Up @@ -319,13 +319,13 @@ mod tests {
};

use super::*;
use crate::v02::types::request::{
use crate::types::request::{
BroadcastedDeclareTransaction,
BroadcastedDeclareTransactionV1,
BroadcastedDeclareTransactionV2,
BroadcastedDeclareTransactionV3,
};
use crate::v02::types::{
use crate::types::{
CairoContractClass,
ContractClass,
DataAvailabilityMode,
Expand Down Expand Up @@ -383,7 +383,7 @@ mod tests {
use super::super::*;
use crate::dto::serialize::SerializeForVersion;
use crate::dto::{serialize, DeserializeForVersion};
use crate::v02::types::request::BroadcastedDeclareTransactionV1;
use crate::types::request::BroadcastedDeclareTransactionV1;
use crate::RpcVersion;

fn test_declare_txn() -> Transaction {
Expand Down Expand Up @@ -480,7 +480,7 @@ mod tests {

use super::super::*;
use crate::dto::DeserializeForVersion;
use crate::v02::types::request::BroadcastedDeclareTransactionV2;
use crate::types::request::BroadcastedDeclareTransactionV2;
use crate::RpcVersion;

fn test_declare_txn() -> Transaction {
Expand Down
6 changes: 3 additions & 3 deletions crates/rpc/src/method/add_deploy_account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use starknet_gateway_client::GatewayApi;
use starknet_gateway_types::error::{KnownStarknetErrorCode, SequencerError};

use crate::context::RpcContext;
use crate::v02::types::request::{
use crate::types::request::{
BroadcastedDeployAccountTransaction,
BroadcastedDeployAccountTransactionV1,
};
Expand Down Expand Up @@ -246,8 +246,8 @@ mod tests {

use super::*;
use crate::dto::serialize::{self, SerializeForVersion};
use crate::v02::types::request::BroadcastedDeployAccountTransactionV3;
use crate::v02::types::{DataAvailabilityMode, ResourceBound, ResourceBounds};
use crate::types::request::BroadcastedDeployAccountTransactionV3;
use crate::types::{DataAvailabilityMode, ResourceBound, ResourceBounds};

const INPUT_JSON: &str = r#"{
"max_fee": "0xbf391377813",
Expand Down
10 changes: 5 additions & 5 deletions crates/rpc/src/method/add_invoke_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use starknet_gateway_client::GatewayApi;
use starknet_gateway_types::error::SequencerError;

use crate::context::RpcContext;
use crate::v02::types::request::BroadcastedInvokeTransaction;
use crate::types::request::BroadcastedInvokeTransaction;

#[derive(Debug, PartialEq, Eq)]
pub enum Transaction {
Expand Down Expand Up @@ -216,8 +216,8 @@ mod tests {
use pathfinder_common::{ResourceAmount, ResourcePricePerUnit, Tip, TransactionVersion};

use super::*;
use crate::v02::types::request::BroadcastedInvokeTransactionV1;
use crate::v02::types::{DataAvailabilityMode, ResourceBound, ResourceBounds};
use crate::types::request::BroadcastedInvokeTransactionV1;
use crate::types::{DataAvailabilityMode, ResourceBound, ResourceBounds};

fn test_invoke_txn() -> Transaction {
Transaction::Invoke(BroadcastedInvokeTransaction::V1(
Expand Down Expand Up @@ -360,7 +360,7 @@ mod tests {
#[tokio::test]
#[ignore = "gateway 429"]
async fn duplicate_transaction() {
use crate::v02::types::request::BroadcastedInvokeTransactionV1;
use crate::types::request::BroadcastedInvokeTransactionV1;

let context = RpcContext::for_tests();
let input = BroadcastedInvokeTransactionV1 {
Expand Down Expand Up @@ -401,7 +401,7 @@ mod tests {
#[ignore = "gateway 429"]
// https://external.integration.starknet.io/feeder_gateway/get_transaction?transactionHash=0x41906f1c314cca5f43170ea75d3b1904196a10101190d2b12a41cc61cfd17c
async fn duplicate_v3_transaction() {
use crate::v02::types::request::BroadcastedInvokeTransactionV3;
use crate::types::request::BroadcastedInvokeTransactionV3;

let context = RpcContext::for_tests_on(pathfinder_common::Chain::SepoliaIntegration);
let input = BroadcastedInvokeTransactionV3 {
Expand Down
1 change: 1 addition & 0 deletions crates/rpc/src/method/block_hash_and_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub struct Output {

crate::error::generate_rpc_error_subset!(Error: NoBlocks);

/// Get the latest block hash and number.
pub async fn block_hash_and_number(context: RpcContext) -> Result<Output, Error> {
let span = tracing::Span::current();

Expand Down
1 change: 1 addition & 0 deletions crates/rpc/src/method/block_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct Output(pathfinder_common::BlockNumber);

crate::error::generate_rpc_error_subset!(Error: NoBlocks);

/// Get the latest block number.
pub async fn block_number(context: RpcContext) -> Result<Output, Error> {
let span = tracing::Span::current();

Expand Down
21 changes: 21 additions & 0 deletions crates/rpc/src/method/chain_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ crate::error::generate_rpc_error_subset!(Error);

pub struct Output(pathfinder_common::ChainId);

/// Get the chain ID.
pub async fn chain_id(context: RpcContext) -> Result<Output, Error> {
Ok(Output(context.chain_id))
}
Expand All @@ -16,3 +17,23 @@ impl crate::dto::serialize::SerializeForVersion for Output {
serializer.serialize(&crate::dto::ChainId(&self.0))
}
}

#[cfg(test)]
mod tests {
use pathfinder_common::ChainId;
use pathfinder_crypto::Felt;

#[tokio::test]
async fn encoding() {
let value = "some_chain_id";
let chain_id = Felt::from_be_slice(value.as_bytes()).unwrap();
let chain_id = ChainId(chain_id);

let encoded = serde_json::to_string(&chain_id).unwrap();

let expected = hex::encode(value);
let expected = format!(r#""0x{expected}""#);

assert_eq!(encoded, expected);
}
}
11 changes: 3 additions & 8 deletions crates/rpc/src/method/estimate_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::de::Error;

use crate::context::RpcContext;
use crate::error::ApplicationError;
use crate::v02::types::request::BroadcastedTransaction;
use crate::types::request::BroadcastedTransaction;

#[derive(Debug, PartialEq, Eq)]
pub struct Input {
Expand Down Expand Up @@ -193,7 +193,7 @@ mod tests {
use pretty_assertions_sorted::assert_eq;

use super::*;
use crate::v02::types::request::{
use crate::types::request::{
BroadcastedDeclareTransaction,
BroadcastedDeclareTransactionV2,
BroadcastedInvokeTransaction,
Expand All @@ -202,12 +202,7 @@ mod tests {
BroadcastedInvokeTransactionV3,
BroadcastedTransaction,
};
use crate::v02::types::{
ContractClass,
DataAvailabilityMode,
ResourceBounds,
SierraContractClass,
};
use crate::types::{ContractClass, DataAvailabilityMode, ResourceBounds, SierraContractClass};

fn declare_transaction(account_contract_address: ContractAddress) -> BroadcastedTransaction {
let sierra_definition = include_bytes!("../../fixtures/contracts/storage_access.json");
Expand Down
3 changes: 2 additions & 1 deletion crates/rpc/src/method/get_block_transaction_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::context::RpcContext;

#[derive(Debug, PartialEq, Eq)]
pub struct Input {
block_id: BlockId,
block_id: pathfinder_common::BlockId,
}

impl crate::dto::DeserializeForVersion for Input {
Expand All @@ -23,6 +23,7 @@ crate::error::generate_rpc_error_subset!(Error: BlockNotFound);
#[derive(Debug)]
pub struct Output(u64);

/// Get the number of transactions in a block.
pub async fn get_block_transaction_count(
context: RpcContext,
input: Input,
Expand Down
7 changes: 4 additions & 3 deletions crates/rpc/src/method/get_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use pathfinder_common::{BlockId, ClassHash};
use crate::context::RpcContext;
use crate::dto;
use crate::dto::serialize::SerializeForVersion;
use crate::v02::types::{CairoContractClass, ContractClass, SierraContractClass};
use crate::types::{CairoContractClass, ContractClass, SierraContractClass};

crate::error::generate_rpc_error_subset!(Error: BlockNotFound, ClassHashNotFound);

#[derive(Debug, PartialEq, Eq)]
pub struct Input {
block_id: BlockId,
class_hash: ClassHash,
block_id: pathfinder_common::BlockId,
class_hash: pathfinder_common::ClassHash,
}

impl crate::dto::DeserializeForVersion for Input {
Expand Down Expand Up @@ -40,6 +40,7 @@ impl From<ContractClass> for Output {
}
}

/// Get a contract class.
pub async fn get_class(context: RpcContext, input: Input) -> Result<Output, Error> {
let span = tracing::Span::current();
let jh = tokio::task::spawn_blocking(move || -> Result<Output, Error> {
Expand Down
7 changes: 4 additions & 3 deletions crates/rpc/src/method/get_class_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use pathfinder_common::{BlockId, ContractAddress};
use crate::context::RpcContext;
use crate::dto;
use crate::dto::serialize::SerializeForVersion;
use crate::v02::types::{CairoContractClass, ContractClass, SierraContractClass};
use crate::types::{CairoContractClass, ContractClass, SierraContractClass};

crate::error::generate_rpc_error_subset!(Error: BlockNotFound, ContractNotFound);

#[derive(Debug, PartialEq, Eq)]
pub struct Input {
block_id: BlockId,
contract_address: ContractAddress,
block_id: pathfinder_common::BlockId,
contract_address: pathfinder_common::ContractAddress,
}

impl crate::dto::DeserializeForVersion for Input {
Expand Down Expand Up @@ -54,6 +54,7 @@ impl SerializeForVersion for Output {
}
}

/// Get a contract class.
pub async fn get_class_at(context: RpcContext, input: Input) -> Result<ContractClass, Error> {
let span = tracing::Span::current();

Expand Down
Loading

0 comments on commit 333ceb3

Please sign in to comment.