Skip to content

Commit 9c57e5b

Browse files
authored
Merge pull request eqlabs#2408 from eqlabs/t00ts/decouple-v06
feat(rpc): Decouple `v07` from `v06` types and methods
2 parents 2e557d7 + 1f56822 commit 9c57e5b

File tree

17 files changed

+2762
-1015
lines changed

17 files changed

+2762
-1015
lines changed

crates/executor/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub struct MsgToL1 {
217217
pub from_address: Felt,
218218
}
219219

220-
#[derive(Debug, Clone)]
220+
#[derive(Default, Debug, Clone)]
221221
pub struct InnerCallExecutionResources {
222222
pub l1_gas: u128,
223223
pub l2_gas: u128,

crates/pathfinder/src/bin/pathfinder/config.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ Examples:
8686
default_value = "v07",
8787
env = "PATHFINDER_RPC_ROOT_VERSION"
8888
)]
89-
rpc_root_version: RpcVersion,
89+
rpc_root_version: RootRpcVersion,
9090

9191
#[arg(
9292
long = "rpc.execution-concurrency",
@@ -334,8 +334,7 @@ impl Color {
334334
}
335335

336336
#[derive(clap::ValueEnum, Debug, Clone, Copy, PartialEq)]
337-
pub enum RpcVersion {
338-
V06,
337+
pub enum RootRpcVersion {
339338
V07,
340339
}
341340

@@ -692,7 +691,7 @@ pub struct Config {
692691
pub ethereum: Ethereum,
693692
pub rpc_address: SocketAddr,
694693
pub rpc_cors_domains: Option<AllowedOrigins>,
695-
pub rpc_root_version: RpcVersion,
694+
pub rpc_root_version: RootRpcVersion,
696695
pub websocket: WebsocketConfig,
697696
pub monitor_address: Option<SocketAddr>,
698697
pub network: Option<NetworkConfig>,

crates/pathfinder/src/bin/pathfinder/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ Hint: This is usually caused by exceeding the file descriptor limit of your syst
247247
};
248248

249249
let default_version = match config.rpc_root_version {
250-
config::RpcVersion::V06 => pathfinder_rpc::RpcVersion::V06,
251-
config::RpcVersion::V07 => pathfinder_rpc::RpcVersion::V07,
250+
config::RootRpcVersion::V07 => pathfinder_rpc::RpcVersion::V07,
252251
};
253252

254253
let rpc_server = pathfinder_rpc::RpcServer::new(config.rpc_address, context, default_version);

crates/rpc/src/dto/simulation.rs

Lines changed: 162 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@ use pathfinder_common::{ContractAddress, ContractNonce};
33
use serde::ser::Error;
44

55
use super::serialize::SerializeStruct;
6+
use super::FeeEstimate;
67
use crate::RpcVersion;
78

89
#[derive(Debug)]
9-
pub struct TransactionTrace<'a> {
10-
pub trace: &'a pathfinder_executor::types::TransactionTrace,
10+
pub struct TransactionTrace {
11+
pub trace: pathfinder_executor::types::TransactionTrace,
1112
pub include_state_diff: bool,
1213
}
1314

14-
impl crate::dto::serialize::SerializeForVersion for TransactionTrace<'_> {
15+
impl crate::dto::serialize::SerializeForVersion for TransactionTrace {
1516
fn serialize(
1617
&self,
1718
serializer: super::serialize::Serializer,
1819
) -> Result<super::serialize::Ok, super::serialize::Error> {
1920
let mut serializer = serializer.serialize_struct()?;
20-
match self.trace {
21+
match &self.trace {
2122
pathfinder_executor::types::TransactionTrace::Declare(trace) => {
2223
serializer.serialize_field("type", &"DECLARE")?;
2324
if let Some(fee_transfer_invocation) = &trace.fee_transfer_invocation {
@@ -120,7 +121,7 @@ impl crate::dto::serialize::SerializeForVersion for TransactionTrace<'_> {
120121
}
121122

122123
#[derive(Debug)]
123-
struct FunctionInvocation<'a>(&'a pathfinder_executor::types::FunctionInvocation);
124+
pub(crate) struct FunctionInvocation<'a>(&'a pathfinder_executor::types::FunctionInvocation);
124125

125126
impl crate::dto::serialize::SerializeForVersion for FunctionInvocation<'_> {
126127
fn serialize(
@@ -519,3 +520,159 @@ impl crate::dto::serialize::SerializeForVersion for ExecuteInvocation<'_> {
519520
}
520521
}
521522
}
523+
524+
#[derive(Clone, Debug, Eq, PartialEq)]
525+
pub enum CallType {
526+
Call,
527+
_LibraryCall,
528+
Delegate,
529+
}
530+
531+
impl From<pathfinder_executor::types::CallType> for CallType {
532+
fn from(value: pathfinder_executor::types::CallType) -> Self {
533+
use pathfinder_executor::types::CallType::*;
534+
match value {
535+
Call => Self::Call,
536+
Delegate => Self::Delegate,
537+
}
538+
}
539+
}
540+
541+
impl crate::dto::serialize::SerializeForVersion for CallType {
542+
fn serialize(
543+
&self,
544+
serializer: super::serialize::Serializer,
545+
) -> Result<super::serialize::Ok, super::serialize::Error> {
546+
match self {
547+
CallType::Call => serializer.serialize_str("CALL"),
548+
CallType::_LibraryCall => serializer.serialize_str("LIBRARY_CALL"),
549+
CallType::Delegate => serializer.serialize_str("DELEGATE"),
550+
}
551+
}
552+
}
553+
554+
#[derive(Debug, Eq, PartialEq)]
555+
pub struct SimulationFlags(pub Vec<SimulationFlag>);
556+
557+
#[derive(Debug, Eq, PartialEq)]
558+
pub enum SimulationFlag {
559+
SkipFeeCharge,
560+
SkipValidate,
561+
}
562+
563+
impl crate::dto::DeserializeForVersion for SimulationFlag {
564+
fn deserialize(value: crate::dto::Value) -> Result<Self, serde_json::Error> {
565+
let value: String = value.deserialize_serde()?;
566+
match value.as_str() {
567+
"SKIP_FEE_CHARGE" => Ok(Self::SkipFeeCharge),
568+
"SKIP_VALIDATE" => Ok(Self::SkipValidate),
569+
_ => Err(serde_json::Error::custom("Invalid simulation flag")),
570+
}
571+
}
572+
}
573+
574+
impl crate::dto::DeserializeForVersion for SimulationFlags {
575+
fn deserialize(value: crate::dto::Value) -> Result<Self, serde_json::Error> {
576+
let array = value.deserialize_array(SimulationFlag::deserialize)?;
577+
Ok(Self(array))
578+
}
579+
}
580+
581+
pub(crate) struct SimulatedTransaction(pub pathfinder_executor::types::TransactionSimulation);
582+
583+
impl crate::dto::serialize::SerializeForVersion for SimulatedTransaction {
584+
fn serialize(
585+
&self,
586+
serializer: super::serialize::Serializer,
587+
) -> Result<super::serialize::Ok, super::serialize::Error> {
588+
let mut serializer = serializer.serialize_struct()?;
589+
serializer.serialize_field("fee_estimation", &FeeEstimate(&self.0.fee_estimation))?;
590+
serializer.serialize_field(
591+
"transaction_trace",
592+
&TransactionTrace {
593+
trace: self.0.trace.clone(),
594+
include_state_diff: false,
595+
},
596+
)?;
597+
serializer.end()
598+
}
599+
}
600+
601+
#[cfg(test)]
602+
mod tests {
603+
604+
use pathfinder_common::macro_prelude::*;
605+
use pathfinder_common::{
606+
felt,
607+
BlockHeader,
608+
BlockId,
609+
CallParam,
610+
ClassHash,
611+
ContractAddress,
612+
EntryPoint,
613+
StarknetVersion,
614+
StorageAddress,
615+
StorageValue,
616+
TransactionVersion,
617+
};
618+
use pathfinder_crypto::Felt;
619+
use pathfinder_storage::Storage;
620+
use starknet_gateway_test_fixtures::class_definitions::{
621+
DUMMY_ACCOUNT_CLASS_HASH,
622+
ERC20_CONTRACT_DEFINITION_CLASS_HASH,
623+
};
624+
625+
use crate::context::RpcContext;
626+
use crate::dto::serialize::{SerializeForVersion, Serializer};
627+
use crate::dto::{
628+
CallType,
629+
ComputationResources,
630+
ExecutionResources,
631+
FeeEstimate,
632+
FunctionInvocation,
633+
SimulatedTransaction,
634+
TransactionTrace,
635+
};
636+
use crate::method::call::FunctionCall;
637+
use crate::method::get_state_update::types::{DeployedContract, Nonce, StateDiff};
638+
use crate::method::simulate_transactions::tests::fixtures;
639+
use crate::types::request::{
640+
BroadcastedDeclareTransaction,
641+
BroadcastedDeclareTransactionV1,
642+
BroadcastedTransaction,
643+
};
644+
use crate::types::ContractClass;
645+
use crate::RpcVersion;
646+
647+
pub(crate) async fn setup_storage_with_starknet_version(
648+
version: StarknetVersion,
649+
) -> (
650+
Storage,
651+
BlockHeader,
652+
ContractAddress,
653+
ContractAddress,
654+
StorageValue,
655+
) {
656+
let test_storage_key = StorageAddress::from_name(b"my_storage_var");
657+
let test_storage_value = storage_value!("0x09");
658+
659+
// set test storage variable
660+
let (storage, last_block_header, account_contract_address, universal_deployer_address) =
661+
crate::test_setup::test_storage(version, |state_update| {
662+
state_update.with_storage_update(
663+
fixtures::DEPLOYED_CONTRACT_ADDRESS,
664+
test_storage_key,
665+
test_storage_value,
666+
)
667+
})
668+
.await;
669+
670+
(
671+
storage,
672+
last_block_header,
673+
account_contract_address,
674+
universal_deployer_address,
675+
test_storage_value,
676+
)
677+
}
678+
}

crates/rpc/src/error.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ impl ApplicationError {
171171
pub fn message(&self, version: RpcVersion) -> String {
172172
match self {
173173
ApplicationError::InsufficientResourcesForValidate => match version {
174-
RpcVersion::V06 | RpcVersion::V07 => "Max fee is smaller than the minimal \
175-
transaction cost (validation plus fee \
176-
transfer)"
174+
RpcVersion::V07 => "Max fee is smaller than the minimal transaction cost \
175+
(validation plus fee transfer)"
177176
.to_string(),
178177
_ => self.to_string(),
179178
},

crates/rpc/src/lib.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod pending;
1212
#[cfg(test)]
1313
mod test_setup;
1414
pub mod types;
15-
pub mod v06;
1615
pub mod v07;
1716
pub mod v08;
1817

@@ -44,7 +43,6 @@ const DEFAULT_MAX_CONNECTIONS: usize = 1024;
4443

4544
#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd)]
4645
pub enum RpcVersion {
47-
V06,
4846
#[default]
4947
V07,
5048
V08,
@@ -54,7 +52,6 @@ pub enum RpcVersion {
5452
impl RpcVersion {
5553
fn to_str(self) -> &'static str {
5654
match self {
57-
RpcVersion::V06 => "v0.6",
5855
RpcVersion::V07 => "v0.7",
5956
RpcVersion::V08 => "v0.8",
6057
RpcVersion::PathfinderV01 => "v0.1",
@@ -164,13 +161,11 @@ impl RpcServer {
164161
}
165162
}
166163

167-
let v06_routes = v06::register_routes().build(self.context.clone());
168164
let v07_routes = v07::register_routes().build(self.context.clone());
169165
let v08_routes = v08::register_routes().build(self.context.clone());
170166
let pathfinder_routes = pathfinder::register_routes().build(self.context.clone());
171167

172168
let default_router = match self.default_version {
173-
RpcVersion::V06 => v06_routes.clone(),
174169
RpcVersion::V07 => v07_routes.clone(),
175170
RpcVersion::V08 => v08_routes.clone(),
176171
RpcVersion::PathfinderV01 => {
@@ -183,8 +178,6 @@ impl RpcServer {
183178
// used by monitoring bots to check service health.
184179
.route("/", get(empty_body).post(rpc_handler))
185180
.with_state(default_router.clone())
186-
.route("/rpc/v0_6", post(rpc_handler))
187-
.with_state(v06_routes.clone())
188181
.route("/rpc/v0_7", post(rpc_handler))
189182
.with_state(v07_routes.clone())
190183
// TODO Uncomment once RPC 0.8 is ready.
@@ -198,8 +191,6 @@ impl RpcServer {
198191
router
199192
.route("/ws", get(websocket_handler))
200193
.with_state(default_router)
201-
.route("/ws/rpc/v0_6", get(websocket_handler))
202-
.with_state(v06_routes)
203194
.route("/ws/rpc/v0_7", get(websocket_handler))
204195
.with_state(v07_routes)
205196
.route("/ws/rpc/pathfinder/v0_1", get(websocket_handler))
@@ -951,16 +942,6 @@ mod tests {
951942
#[case::v0_7_pathfinder("/rpc/v0_7", "pathfinder_rpc_api.json", &["pathfinder_version", "pathfinder_getTransactionStatus"], Api::HttpOnly)]
952943
#[case::v0_7_pathfinder_websocket("/ws/rpc/v0_7", "pathfinder_rpc_api.json", &["pathfinder_version", "pathfinder_getTransactionStatus"], Api::WebsocketOnly)]
953944

954-
#[case::v0_6_api("/rpc/v0_6", "v06/starknet_api_openrpc.json", &[], Api::HttpOnly)]
955-
#[case::v0_6_api_websocket("/ws/rpc/v0_6", "v06/starknet_api_openrpc.json", &[], Api::WebsocketOnly)]
956-
#[case::v0_6_trace("/rpc/v0_6", "v06/starknet_trace_api_openrpc.json", &[], Api::HttpOnly)]
957-
#[case::v0_6_trace_websocket("/ws/rpc/v0_6", "v06/starknet_trace_api_openrpc.json", &[], Api::WebsocketOnly)]
958-
#[case::v0_6_write("/rpc/v0_6", "v06/starknet_write_api.json", &[], Api::HttpOnly)]
959-
#[case::v0_6_write_websocket("/ws/rpc/v0_6", "v06/starknet_write_api.json", &[], Api::WebsocketOnly)]
960-
// get_transaction_status is now part of the official spec, so we are phasing it out.
961-
#[case::v0_6_pathfinder("/rpc/v0_6", "pathfinder_rpc_api.json", &["pathfinder_version", "pathfinder_getTransactionStatus"], Api::HttpOnly)]
962-
#[case::v0_6_pathfinder_websocket("/ws/rpc/v0_6", "pathfinder_rpc_api.json", &["pathfinder_version", "pathfinder_getTransactionStatus"], Api::WebsocketOnly)]
963-
964945
#[case::pathfinder("/rpc/pathfinder/v0.1", "pathfinder_rpc_api.json", &[], Api::HttpOnly)]
965946
#[case::pathfinder("/ws/rpc/pathfinder/v0_1", "pathfinder_rpc_api.json", &[], Api::WebsocketOnly)]
966947

crates/rpc/src/method/call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub struct Input {
7474
pub block_id: BlockId,
7575
}
7676

77-
#[derive(serde::Deserialize, Clone, Debug, PartialEq, Eq)]
77+
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
7878
#[serde(deny_unknown_fields)]
7979
pub struct FunctionCall {
8080
pub contract_address: ContractAddress,

0 commit comments

Comments
 (0)