Skip to content

Commit

Permalink
adding checks on messages from l2 to l1
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoGiachetta committed Jul 10, 2024
1 parent f9dcc49 commit 3f72820
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
14 changes: 6 additions & 8 deletions rpc-state-reader/src/blockifier_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,21 +637,19 @@ mod tests {
// Impl conversion for easier checking against RPC data
impl From<&CallInfo> for RpcCallInfo {
fn from(value: &CallInfo) -> Self {
dbg!("Msgs num: {}", &value.execution.l2_to_l1_messages);

Self {
retdata: Some(value.execution.retdata.0.clone()),
calldata: Some((*value.call.calldata.0).clone()),
internal_calls: value.inner_calls.iter().map(|ci| ci.into()).collect(),
// We don't have the revert reason string in the trace so we just make sure it doesn't revert
revert_reason: value.execution.failed.then_some("Default String".into()),
events: value.execution.events.iter().map(|e| e.into()).collect(),
// l2_l1_messages: value
// .execution
// .l2_to_l1_messages
// .iter()
// .map(|llm| llm.into())
// .collect(),
messages: value
.execution
.l2_to_l1_messages
.iter()
.map(|llm| llm.into())
.collect(),
}
}
}
Expand Down
40 changes: 21 additions & 19 deletions rpc-state-reader/src/rpc_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ use starknet_api::{
core::{ChainId, ClassHash, ContractAddress, EthAddress},
hash::{StarkFelt, StarkHash},
state::StorageKey,
transaction::{EventContent, EventData, EventKey, L2ToL1Payload, Transaction as SNTransaction, TransactionHash},
transaction::{
EventData, EventKey, L2ToL1Payload, Transaction as SNTransaction,
TransactionHash,
},
};
use std::{collections::HashMap, env, fmt::Display, num::NonZeroU128};

Expand Down Expand Up @@ -127,7 +130,7 @@ impl From<&OrderedEvent> for Event {
Self {
order: value.order,
keys: value.event.keys.clone(),
data: value.event.data.clone()
data: value.event.data.clone(),
}
}
}
Expand Down Expand Up @@ -205,7 +208,7 @@ pub struct RpcCallInfo {
pub internal_calls: Vec<RpcCallInfo>,
pub revert_reason: Option<String>,
pub events: Vec<Event>,
// pub l2_l1_messages: Option<Vec<L2ToL1Msg>>,
pub messages: Vec<L2ToL1Msg>,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -353,32 +356,31 @@ impl<'de> Deserialize<'de> for RpcCallInfo {
for event in events_value.as_array().ok_or(serde::de::Error::custom(
RpcStateError::RpcResponseWrongType("events".to_string()),
))? {
dbg!(event);
events.push(serde_json::from_value(event.clone()).map_err(serde::de::Error::custom)?)
}

// let msg_l1_l2_value = value
// .get("l2_l1_messages")
// .ok_or(serde::de::Error::custom(
// RpcStateError::MissingRpcResponseField("l2_l1_messages".to_string()),
// ))?
// .clone();
// let mut l2_l1_messages = vec![];

// for msg in msg_l1_l2_value.as_array().ok_or(serde::de::Error::custom(
// RpcStateError::RpcResponseWrongType("l2_l1_messages".to_string()),
// ))? {
// l2_l1_messages
// .push(serde_json::from_value(msg.clone()).map_err(serde::de::Error::custom)?)
// }
let messages_value = value
.get("messages")
.ok_or(serde::de::Error::custom(
RpcStateError::MissingRpcResponseField("messages".to_string()),
))?
.clone();
let mut messages = vec![];

for msg in messages_value.as_array().ok_or(serde::de::Error::custom(
RpcStateError::RpcResponseWrongType("messages".to_string()),
))? {
messages
.push(serde_json::from_value(msg.clone()).map_err(serde::de::Error::custom)?)
}

Ok(RpcCallInfo {
retdata,
calldata,
internal_calls,
revert_reason: None,
events,
// l2_l1_messages: l2_l1_messages,
messages,
})
}
}
Expand Down

0 comments on commit 3f72820

Please sign in to comment.