Skip to content

Commit

Permalink
fix: ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jbcaron committed Nov 29, 2024
1 parent 82e599d commit ca4977e
Show file tree
Hide file tree
Showing 29 changed files with 319 additions and 240 deletions.
10 changes: 8 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ paste = "1.0.15"
anyhow = "1.0"
assert_matches = "1.5"
async-trait = "0.1"
base64 = "0.22"
sha3 = "0.10"
bitvec = { version = "1.0", default-features = false, features = ["std"] }
clap = { version = "4.4" }
Expand Down
8 changes: 7 additions & 1 deletion crates/client/rpc/src/providers/forward_to_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ impl AddTransactionProvider for ForwardToProvider {
&self,
declare_transaction: BroadcastedDeclareTxn<Felt>,
) -> RpcResult<ClassAndTxnHash<Felt>> {
let sequencer_response = match self.provider.add_declare_transaction(declare_transaction.into()).await {
let sequencer_response = match self
.provider
.add_declare_transaction(
declare_transaction.try_into().map_err(|_| StarknetRpcApiError::InvalidContractClass)?,
)
.await
{
Ok(response) => response,
Err(SequencerError::StarknetError(e)) => {
return Err(StarknetRpcApiError::from(e).into());
Expand Down
2 changes: 1 addition & 1 deletion crates/client/rpc/src/versions/admin/v0_1_0/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ pub trait MadaraWriteRpcApi {
#[method(name = "addDeclareV0Transaction")]
async fn add_declare_v0_transaction(
&self,
_declare_v0_transaction: BroadcastedDeclareTransactionV0,
declare_v0_transaction: BroadcastedDeclareTransactionV0,
) -> RpcResult<ClassAndTxnHash<Felt>>;
}
36 changes: 12 additions & 24 deletions crates/client/rpc/src/versions/user/v0_7_1/api.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use jsonrpsee::core::RpcResult;
use m_proc_macros::versioned_rpc;
use mp_block::BlockId;
use mp_transactions::BroadcastedDeclareTransactionV0;
use starknet_types_core::felt::Felt;
use starknet_types_rpc::{
AddInvokeTransactionResult, BlockHashAndNumber, BroadcastedDeclareTxn, BroadcastedDeployAccountTxn,
BroadcastedInvokeTxn, BroadcastedTxn, ClassAndTxnHash, ContractAndTxnHash, EstimateFeeParams,
EventFilterWithPageRequest, EventsChunk, FeeEstimate, FunctionCall, GetTransactionByBlockIdAndIndexParams,
MaybeDeprecatedContractClass, MaybePendingBlockWithTxHashes, MaybePendingBlockWithTxs, MaybePendingStateUpdate,
MsgFromL1, SimulateTransactionsResult, SimulationFlag, StarknetGetBlockWithTxsAndReceiptsResult, SyncingStatus,
TraceBlockTransactionsResult, TxnFinalityAndExecutionStatus, TxnReceiptWithBlockInfo, TxnWithHash,
BroadcastedInvokeTxn, BroadcastedTxn, ClassAndTxnHash, ContractAndTxnHash, EventFilterWithPageRequest, EventsChunk,
FeeEstimate, FunctionCall, MaybeDeprecatedContractClass, MaybePendingBlockWithTxHashes, MaybePendingBlockWithTxs,
MaybePendingStateUpdate, MsgFromL1, SimulateTransactionsResult, SimulationFlag, SimulationFlagForEstimateFee,
StarknetGetBlockWithTxsAndReceiptsResult, SyncingStatus, TraceBlockTransactionsResult,
TxnFinalityAndExecutionStatus, TxnReceiptWithBlockInfo, TxnWithHash,
};

// Starknet RPC API trait and types
Expand All @@ -18,19 +17,6 @@ use starknet_types_rpc::{
// using the openRPC specification.
// This crate uses `jsonrpsee` to define such an API in Rust terms.

/// Starknet write rpc interface.
///
#[versioned_rpc("V0_7_1", "madara")]
pub trait MadaraWriteRpcApi {
/// Submit a new class v0 declaration transaction
#[method(name = "addDeclareV0Transaction", and_versions = ["V0_8_0"])]
async fn add_declare_v0_transaction(
&self,
declare_transaction_v0: BroadcastedDeclareTransactionV0,
) -> RpcResult<ClassAndTxnHash<Felt>>;
}

#[versioned_rpc("V0_7_1", "starknet")]
pub trait StarknetWriteRpcApi {
/// Submit a new transaction to be added to the chain
Expand Down Expand Up @@ -83,7 +69,12 @@ pub trait StarknetReadRpcApi {

/// Estimate the fee associated with transaction
#[method(name = "estimateFee", and_versions = ["V0_8_0"])]
async fn estimate_fee(&self, params: EstimateFeeParams<Felt>) -> RpcResult<Vec<FeeEstimate<Felt>>>;
async fn estimate_fee(
&self,
request: Vec<BroadcastedTxn<Felt>>,
simulation_flags: Vec<SimulationFlagForEstimateFee>,
block_id: BlockId,
) -> RpcResult<Vec<FeeEstimate<Felt>>>;

/// Estimate the L2 fee of a message sent on L1
#[method(name = "estimateMessageFee", and_versions = ["V0_8_0"])]
Expand Down Expand Up @@ -131,10 +122,7 @@ pub trait StarknetReadRpcApi {

/// Get the details of a transaction by a given block id and index
#[method(name = "getTransactionByBlockIdAndIndex", and_versions = ["V0_8_0"])]
fn get_transaction_by_block_id_and_index(
&self,
req: GetTransactionByBlockIdAndIndexParams<Felt>,
) -> RpcResult<TxnWithHash<Felt>>;
fn get_transaction_by_block_id_and_index(&self, block_id: BlockId, index: u64) -> RpcResult<TxnWithHash<Felt>>;

/// Returns the information about a transaction by transaction hash.
#[method(name = "getTransactionByHash", and_versions = ["V0_8_0"])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn estimate_fee(
.collect::<Result<Vec<_>, _>>()
.or_internal_server_error("Failed to convert BroadcastedTransaction to AccountTransaction")?;

let validate = !simulation_flags.contains(&"SKIP_VALIDATE".to_string());
let validate = !simulation_flags.contains(&SimulationFlagForEstimateFee::SkipValidate);

let execution_results = exec_context.re_execute_transactions([], transactions, true, validate)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn get_transaction_status(
};

let finality_status = match block.info {
MadaraMaybePendingBlockInfo::Pending(_) => TxnStatus::Received,
MadaraMaybePendingBlockInfo::Pending(_) => TxnStatus::AcceptedOnL2,
MadaraMaybePendingBlockInfo::NotPending(block) => {
if block.header.block_number <= starknet.get_l1_last_confirmed_block()? {
TxnStatus::AcceptedOnL1
Expand Down
25 changes: 14 additions & 11 deletions crates/client/rpc/src/versions/user/v0_7_1/methods/read/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use mp_block::BlockId;
use mp_chain_config::RpcVersion;
use starknet_types_core::felt::Felt;
use starknet_types_rpc::{
BlockHashAndNumber, EstimateFeeParams, EventFilterWithPageRequest, EventsChunk, FeeEstimate, FunctionCall,
GetTransactionByBlockIdAndIndexParams, MaybeDeprecatedContractClass, MaybePendingBlockWithTxHashes,
MaybePendingBlockWithTxs, MaybePendingStateUpdate, MsgFromL1, StarknetGetBlockWithTxsAndReceiptsResult,
SyncingStatus, TxnFinalityAndExecutionStatus, TxnReceiptWithBlockInfo, TxnWithHash,
BlockHashAndNumber, EventFilterWithPageRequest, EventsChunk, FeeEstimate, FunctionCall,
MaybeDeprecatedContractClass, MaybePendingBlockWithTxHashes, MaybePendingBlockWithTxs, MaybePendingStateUpdate,
MsgFromL1, StarknetGetBlockWithTxsAndReceiptsResult, SyncingStatus, TxnFinalityAndExecutionStatus,
TxnReceiptWithBlockInfo, TxnWithHash,
};
use starknet_types_rpc::{BroadcastedTxn, SimulationFlagForEstimateFee};

use super::block_hash_and_number::*;
use super::call::*;
Expand Down Expand Up @@ -59,8 +60,13 @@ impl StarknetReadRpcApiV0_7_1Server for Starknet {
Ok(get_block_transaction_count(self, block_id)?)
}

async fn estimate_fee(&self, params: EstimateFeeParams<Felt>) -> RpcResult<Vec<FeeEstimate<Felt>>> {
Ok(estimate_fee(self, params.request, params.simulation_flags, params.block_id).await?)
async fn estimate_fee(
&self,
request: Vec<BroadcastedTxn<Felt>>,
simulation_flags: Vec<SimulationFlagForEstimateFee>,
block_id: BlockId,
) -> RpcResult<Vec<FeeEstimate<Felt>>> {
Ok(estimate_fee(self, request, simulation_flags, block_id).await?)
}

async fn estimate_message_fee(&self, message: MsgFromL1<Felt>, block_id: BlockId) -> RpcResult<FeeEstimate<Felt>> {
Expand Down Expand Up @@ -106,11 +112,8 @@ impl StarknetReadRpcApiV0_7_1Server for Starknet {
Ok(get_storage_at(self, contract_address, key, block_id)?)
}

fn get_transaction_by_block_id_and_index(
&self,
req: GetTransactionByBlockIdAndIndexParams<Felt>,
) -> RpcResult<TxnWithHash<Felt>> {
Ok(get_transaction_by_block_id_and_index(self, req.block_id, req.index)?)
fn get_transaction_by_block_id_and_index(&self, block_id: BlockId, index: u64) -> RpcResult<TxnWithHash<Felt>> {
Ok(get_transaction_by_block_id_and_index(self, block_id, index)?)
}

fn get_transaction_by_hash(&self, transaction_hash: Felt) -> RpcResult<TxnWithHash<Felt>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ pub async fn simulate_transactions(
}
let exec_context = ExecutionContext::new_in_block(Arc::clone(&starknet.backend), &block_info)?;

let charge_fee = simulation_flags.contains(&SimulationFlag::FeeCharge);
let validate = simulation_flags.contains(&SimulationFlag::Validate);
let charge_fee = !simulation_flags.contains(&SimulationFlag::SkipFeeCharge);
let validate = !simulation_flags.contains(&SimulationFlag::SkipValidate);

let user_transactions = transactions
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion crates/client/sync/test-data/block_0.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/client/sync/test-data/block_724130.json

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions crates/primitives/block/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,6 @@ impl From<L1DataAvailabilityMode> for starknet_types_rpc::L1DaMode {
}
}

// impl From<starknet_core::types::L1DataAvailabilityMode> for L1DataAvailabilityMode {
// fn from(value: starknet_core::types::L1DataAvailabilityMode) -> Self {
// match value {
// starknet_core::types::L1DataAvailabilityMode::Calldata => Self::Calldata,
// starknet_core::types::L1DataAvailabilityMode::Blob => Self::Blob,
// }
// }
// }

#[derive(thiserror::Error, Debug)]
pub enum BlockFormatError {
#[error("The block is a pending block")]
Expand Down
6 changes: 5 additions & 1 deletion crates/primitives/block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ impl From<MadaraBlockInfo> for starknet_types_rpc::BlockHeader<Felt> {
new_root,
parent_hash,
sequencer_address,
starknet_version: protocol_version.to_string(),
starknet_version: if protocol_version < StarknetVersion::V0_9_1 {
"".to_string()
} else {
protocol_version.to_string()
},
timestamp,
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/primitives/class/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ starknet-types-core = { workspace = true }
starknet-types-rpc = { workspace = true }

# Other
base64 = { workspace = true }
flate2 = { workspace = true }
lazy_static = { workspace = true }
num-bigint = { workspace = true }
Expand Down
13 changes: 6 additions & 7 deletions crates/primitives/class/src/class_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use starknet_types_core::{
};

use crate::{
convert::ParseCompressedLegacyClassError, CompressedLegacyContractClass, ContractClass, FlattenedSierraClass,
SierraEntryPoint,
convert::{parse_compressed_legacy_class, ParseCompressedLegacyClassError},
CompressedLegacyContractClass, ContractClass, FlattenedSierraClass, SierraEntryPoint,
};
use starknet_core::types::contract::ComputeClassHashError as StarknetComputeClassHashError;

Expand Down Expand Up @@ -54,18 +54,17 @@ impl FlattenedSierraClass {
}

fn compute_hash_entries_point(entry_points: &[SierraEntryPoint]) -> Felt {
let entry_pointfalten: Vec<_> = entry_points
let entry_point_flatten: Vec<_> = entry_points
.iter()
.flat_map(|SierraEntryPoint { selector, function_idx }| [*selector, Felt::from(*function_idx)].into_iter())
.collect();
Poseidon::hash_array(&entry_pointfalten)
Poseidon::hash_array(&entry_point_flatten)
}

impl CompressedLegacyContractClass {
pub fn compute_class_hash(&self) -> Result<Felt, ComputeClassHashError> {
unimplemented!()
// let legacy_contract_class = parse_compressed_legacy_class(self.clone().into())?;
// legacy_contract_class.class_hash().map_err(ComputeClassHashError::from)
let legacy_contract_class = parse_compressed_legacy_class(self.clone().into())?;
legacy_contract_class.class_hash().map_err(ComputeClassHashError::from)
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/primitives/class/src/into_starknet_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl From<SierraEntryPoint> for starknet_core::types::SierraEntryPoint {
impl From<starknet_core::types::CompressedLegacyContractClass> for CompressedLegacyContractClass {
fn from(compressed_legacy_contract_class: starknet_core::types::CompressedLegacyContractClass) -> Self {
CompressedLegacyContractClass {
program: String::from_utf8(compressed_legacy_contract_class.program).expect("Invalid utf8"),
program: compressed_legacy_contract_class.program,
entry_points_by_type: compressed_legacy_contract_class.entry_points_by_type.into(),
abi: compressed_legacy_contract_class
.abi
Expand All @@ -129,7 +129,7 @@ impl From<starknet_core::types::CompressedLegacyContractClass> for CompressedLeg
impl From<CompressedLegacyContractClass> for starknet_core::types::CompressedLegacyContractClass {
fn from(compressed_legacy_contract_class: CompressedLegacyContractClass) -> Self {
starknet_core::types::CompressedLegacyContractClass {
program: compressed_legacy_contract_class.program.as_bytes().to_vec(),
program: compressed_legacy_contract_class.program,
entry_points_by_type: compressed_legacy_contract_class.entry_points_by_type.into(),
abi: compressed_legacy_contract_class
.abi
Expand Down Expand Up @@ -422,7 +422,7 @@ mod tests {
#[test]
fn test_legacy_contract_class_conversion() {
let legacy_contract_class = CompressedLegacyContractClass {
program: "program".to_string(),
program: "program".as_bytes().to_vec(),
entry_points_by_type: LegacyEntryPointsByType {
constructor: vec![LegacyContractEntryPoint { offset: 0, selector: Felt::from(1) }],
external: vec![LegacyContractEntryPoint { offset: 1, selector: Felt::from(2) }],
Expand Down
Loading

0 comments on commit ca4977e

Please sign in to comment.