Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
sync the code
Browse files Browse the repository at this point in the history
  • Loading branch information
fishseabowl committed May 31, 2024
2 parents 15aa299 + 8f983b2 commit 8825202
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 80 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
## Next release

- dev: make HasherT methods accept iterator rather than &[Felt] as argument

## v0.8.0

- feat: add `TransactionFilter<TxType>` to pallet-starknet `Config`
- chore: remove `ignore` from
`storage_changes_should_revert_on_transaction_revert` test
- dev: Implement tests for new rpc method starknet_getTransactionStatus
- feat: actual estimate_fee added, brought back l1 messages and refactored
simulate tx
- dev: impl get_state_updates using get_transaction_re_execution_state_diff
Expand Down
48 changes: 24 additions & 24 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ incremental = true
authors = ["Abdelhamid Bakhta <@abdelhamidbakhta>"]
edition = "2021"
repository = "https://github.com/keep-starknet-strange/madara/"
version = "0.7.0"
version = "0.8.0"

[workspace.dependencies]
# Substrate frame dependencies
Expand Down
2 changes: 1 addition & 1 deletion crates/client/storage/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Storage overrides readers
//!
//! In order for the client to access on pallets chain data data it has to read from the storage.
//! In order for the client to access on pallets chain data it has to read from the storage.
//! This can be achieve either through the pallet runtime API or by indexing the storage directly.
//! The `OverrideHandle` make it possible to use the later, more efficient way, while keeping the
//! first one as a fallback.
Expand Down
59 changes: 39 additions & 20 deletions crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ use mp_block::{Block as StarknetBlock, Header as StarknetHeader};
use mp_chain_id::MADARA_CHAIN_ID;
use mp_digest_log::MADARA_ENGINE_ID;
use mp_felt::Felt252Wrapper;
use mp_starknet_inherent::{InherentError, InherentType, STARKNET_INHERENT_IDENTIFIER};
use mp_starknet_inherent::{InherentError, InherentType, L1GasPrices, STARKNET_INHERENT_IDENTIFIER};
use mp_storage::{StarknetStorageSchemaVersion, PALLET_STARKNET_SCHEMA};
use mp_transactions::execution::{
execute_l1_handler_transaction, run_non_revertible_transaction, run_revertible_transaction,
execute_l1_handler_transaction, run_non_revertible_transaction, run_revertible_transaction, TransactionFilter,
};
use mp_transactions::{get_transaction_nonce, get_transaction_sender_address};
use sp_runtime::traits::UniqueSaturatedInto;
Expand Down Expand Up @@ -118,7 +118,6 @@ macro_rules! log {

#[frame_support::pallet]
pub mod pallet {
use mp_starknet_inherent::L1GasPrices;

use super::*;

Expand All @@ -132,6 +131,12 @@ pub mod pallet {
pub trait Config: frame_system::Config {
/// The block time
type TimestampProvider: Time;
/// Custom transaction filter for Invoke txs
type InvokeTransactionFilter: TransactionFilter<InvokeTransaction>;
/// Custom transaction filter for Declare txs
type DeclareTransactionFilter: TransactionFilter<DeclareTransaction>;
/// Custom transaction filter for DeployAccount txs
type DeployAccountTransactionFilter: TransactionFilter<DeployAccountTransaction>;
/// A configuration for base priority of unsigned transactions.
///
/// This is exposed so that it can be tuned for particular runtime, when
Expand Down Expand Up @@ -519,10 +524,20 @@ pub mod pallet {

// Execute
let tx_execution_infos = match transaction.tx.version() {
TransactionVersion::ZERO => {
run_non_revertible_transaction(&transaction, &mut state, &block_context, true, charge_fee)
}
_ => run_revertible_transaction(&transaction, &mut state, &block_context, true, charge_fee),
TransactionVersion::ZERO => run_non_revertible_transaction::<_, _, T::InvokeTransactionFilter>(
&transaction,
&mut state,
&block_context,
true,
charge_fee,
),
_ => run_revertible_transaction::<_, _, T::InvokeTransactionFilter>(
&transaction,
&mut state,
&block_context,
true,
charge_fee,
),
}
.map_err(|e| {
log!(error, "Invoke transaction execution failed: {:?}", e);
Expand Down Expand Up @@ -576,12 +591,14 @@ pub mod pallet {
let charge_fee = !<T as Config>::DisableTransactionFee::get();

// Execute
let tx_execution_infos =
run_non_revertible_transaction(&transaction, &mut state, &Self::get_block_context(), true, charge_fee)
.map_err(|e| {
log!(error, "Declare transaction execution failed: {:?}", e);
Error::<T>::TransactionExecutionFailed
})?;
let tx_execution_infos = run_non_revertible_transaction::<_, _, T::DeclareTransactionFilter>(
&transaction,
&mut state,
&Self::get_block_context(),
true,
charge_fee,
)
.map_err(|_| Error::<T>::TransactionExecutionFailed)?;

Self::emit_and_store_tx_and_fees_events(
transaction.tx_hash(),
Expand Down Expand Up @@ -626,12 +643,14 @@ pub mod pallet {
let charge_fee = !<T as Config>::DisableTransactionFee::get();

// Execute
let tx_execution_infos =
run_non_revertible_transaction(&transaction, &mut state, &Self::get_block_context(), true, charge_fee)
.map_err(|e| {
log!(error, "Deploy account transaction execution failed: {:?}", e);
Error::<T>::TransactionExecutionFailed
})?;
let tx_execution_infos = run_non_revertible_transaction::<_, _, T::DeployAccountTransactionFilter>(
&transaction,
&mut state,
&Self::get_block_context(),
true,
charge_fee,
)
.map_err(|_| Error::<T>::TransactionExecutionFailed)?;

Self::emit_and_store_tx_and_fees_events(
transaction.tx_hash,
Expand Down Expand Up @@ -782,7 +801,7 @@ pub mod pallet {
)),
));
}
// Happy path, were the the nonce is the current one,
// Happy path, were the nonce is the current one,
// we validate the tx
_ => {
Self::validate_unsigned_tx(&transaction)?;
Expand Down
22 changes: 12 additions & 10 deletions crates/pallets/starknet/src/simulations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,30 +351,32 @@ impl<T: Config> Pallet<T> {
simulation_flags: &SimulationFlags,
) -> Result<TransactionExecutionInfo, TransactionExecutionError> {
match transaction {
AccountTransaction::Declare(tx) => run_non_revertible_transaction(
tx,
state,
block_context,
simulation_flags.validate,
simulation_flags.charge_fee,
),
AccountTransaction::DeployAccount(tx) => run_non_revertible_transaction(
AccountTransaction::Declare(tx) => run_non_revertible_transaction::<_, _, T::DeclareTransactionFilter>(
tx,
state,
block_context,
simulation_flags.validate,
simulation_flags.charge_fee,
),
AccountTransaction::DeployAccount(tx) => {
run_non_revertible_transaction::<_, _, T::DeployAccountTransactionFilter>(
tx,
state,
block_context,
simulation_flags.validate,
simulation_flags.charge_fee,
)
}
AccountTransaction::Invoke(tx) if tx.tx.version() == TransactionVersion::ZERO => {
run_non_revertible_transaction(
run_non_revertible_transaction::<_, _, T::InvokeTransactionFilter>(
tx,
state,
block_context,
simulation_flags.validate,
simulation_flags.charge_fee,
)
}
AccountTransaction::Invoke(tx) => run_revertible_transaction(
AccountTransaction::Invoke(tx) => run_revertible_transaction::<_, _, T::InvokeTransactionFilter>(
tx,
state,
block_context,
Expand Down
Loading

0 comments on commit 8825202

Please sign in to comment.