Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: starkware-libs/sequencer
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 38d7da875c89b34afc04c6ffa27f53e314146ec8
Choose a base ref
..
head repository: starkware-libs/sequencer
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c2fba981d139eb9b268a701146f5008bc3727e28
Choose a head ref
Showing with 172 additions and 175 deletions.
  1. +1 −0 .github/actions/install_rust/action.yml
  2. +7 −6 crates/blockifier/src/blockifier/transaction_executor_test.rs
  3. +7 −2 crates/blockifier/src/concurrency/versioned_state_test.rs
  4. +2 −1 crates/blockifier/src/concurrency/worker_logic_test.rs
  5. +4 −4 crates/blockifier/src/test_utils/declare.rs
  6. +4 −7 crates/blockifier/src/test_utils/deploy_account.rs
  7. +4 −7 crates/blockifier/src/test_utils/invoke.rs
  8. +4 −2 crates/blockifier/src/test_utils/transfers_generator.rs
  9. +1 −5 crates/blockifier/src/transaction/account_transaction.rs
  10. +4 −2 crates/blockifier/src/transaction/account_transactions_test.rs
  11. +15 −8 crates/blockifier/src/transaction/test_utils.rs
  12. +17 −0 crates/blockifier/src/transaction/transactions.rs
  13. +61 −41 crates/blockifier/src/transaction/transactions_test.rs
  14. +8 −13 crates/native_blockifier/src/py_transaction.rs
  15. +5 −10 crates/sequencing/papyrus_consensus/src/manager_test.rs
  16. +5 −19 crates/sequencing/papyrus_consensus/src/single_height_consensus.rs
  17. +5 −5 crates/sequencing/papyrus_consensus/src/single_height_consensus_test.rs
  18. +1 −6 crates/sequencing/papyrus_consensus/src/test_utils.rs
  19. +1 −6 crates/sequencing/papyrus_consensus/src/types.rs
  20. +1 −6 crates/sequencing/papyrus_consensus_orchestrator/src/papyrus_consensus_context.rs
  21. +8 −18 crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context.rs
  22. +6 −6 crates/sequencing/papyrus_consensus_orchestrator/src/sequencer_consensus_context_test.rs
  23. +1 −1 crates/starknet_sequencer_node/src/test_utils/compilation.rs
1 change: 1 addition & 0 deletions .github/actions/install_rust/action.yml
Original file line number Diff line number Diff line change
@@ -7,3 +7,4 @@ runs:
- uses: moonrepo/setup-rust@v1
with:
cache-base: main(-v[0-9].*)?
inherit-toolchain: true
13 changes: 7 additions & 6 deletions crates/blockifier/src/blockifier/transaction_executor_test.rs
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ use crate::test_utils::{
BALANCE,
DEFAULT_STRK_L1_GAS_PRICE,
};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::errors::TransactionExecutionError;
use crate::transaction::test_utils::{
account_invoke_tx,
@@ -120,7 +121,7 @@ fn test_declare(
let declared_contract = FeatureContract::Empty(cairo_version);
let state = test_state(&block_context.chain_info, BALANCE, &[(account_contract, 1)]);

let tx = declare_tx(
let declare_tx = declare_tx(
declare_tx_args! {
sender_address: account_contract.get_instance_address(0),
class_hash: declared_contract.get_class_hash(),
@@ -129,8 +130,8 @@ fn test_declare(
resource_bounds: l1_resource_bounds(0_u8.into(), DEFAULT_STRK_L1_GAS_PRICE.into()),
},
calculate_class_info_for_testing(declared_contract.get_class()),
)
.into();
);
let tx = AccountTransaction { tx: declare_tx, only_query: false }.into();
tx_executor_test_body(state, block_context, tx, expected_bouncer_weights);
}

@@ -143,15 +144,15 @@ fn test_deploy_account(
let account_contract = FeatureContract::AccountWithoutValidations(cairo_version);
let state = test_state(&block_context.chain_info, BALANCE, &[(account_contract, 0)]);

let tx = deploy_account_tx(
let deploy_account_tx = deploy_account_tx(
deploy_account_tx_args! {
class_hash: account_contract.get_class_hash(),
resource_bounds: l1_resource_bounds(0_u8.into(), DEFAULT_STRK_L1_GAS_PRICE.into()),
version,
},
&mut NonceManager::default(),
)
.into();
);
let tx = AccountTransaction { tx: deploy_account_tx, only_query: false }.into();
let expected_bouncer_weights = BouncerWeights {
state_diff_size: 3,
message_segment_length: 0,
9 changes: 7 additions & 2 deletions crates/blockifier/src/concurrency/versioned_state_test.rs
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ use crate::test_utils::deploy_account::deploy_account_tx;
use crate::test_utils::dict_state_reader::DictStateReader;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{CairoVersion, BALANCE, DEFAULT_STRK_L1_GAS_PRICE};
use crate::transaction::account_transaction::AccountTransaction;
use crate::transaction::objects::HasRelatedFeeType;
use crate::transaction::test_utils::{default_all_resource_bounds, l1_resource_bounds};
use crate::transaction::transactions::ExecutableTransaction;
@@ -225,7 +226,7 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
let mut state_2 = TransactionalState::create_transactional(&mut versioned_state_proxy_2);

// Prepare transactions
let deploy_account_tx_1 = deploy_account_tx(
let tx = deploy_account_tx(
deploy_account_tx_args! {
class_hash: account_without_validation.get_class_hash(),
resource_bounds: l1_resource_bounds(
@@ -235,6 +236,7 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
},
&mut NonceManager::default(),
);
let deploy_account_tx_1 = AccountTransaction { tx, only_query: false };
let enforce_fee = deploy_account_tx_1.enforce_fee();

let class_hash = grindy_account.get_class_hash();
@@ -247,7 +249,10 @@ fn test_run_parallel_txs(default_all_resource_bounds: ValidResourceBounds) {
constructor_calldata: constructor_calldata.clone(),
};
let nonce_manager = &mut NonceManager::default();
let delpoy_account_tx_2 = deploy_account_tx(deploy_tx_args, nonce_manager);
let delpoy_account_tx_2 = AccountTransaction {
tx: deploy_account_tx(deploy_tx_args, nonce_manager),
only_query: false,
};
let account_address = delpoy_account_tx_2.sender_address();
let tx_context = block_context.to_tx_context(&delpoy_account_tx_2);
let fee_type = tx_context.tx_info.fee_type();
3 changes: 2 additions & 1 deletion crates/blockifier/src/concurrency/worker_logic_test.rs
Original file line number Diff line number Diff line change
@@ -549,7 +549,7 @@ fn test_deploy_before_declare(
let test_class_hash = test_contract.get_class_hash();
let test_class_info = calculate_class_info_for_testing(test_contract.get_class());
let test_compiled_class_hash = test_contract.get_compiled_class_hash();
let declare_tx = declare_tx(
let tx = declare_tx(
declare_tx_args! {
sender_address: account_address_0,
resource_bounds: default_all_resource_bounds,
@@ -561,6 +561,7 @@ fn test_deploy_before_declare(
},
test_class_info.clone(),
);
let declare_tx = AccountTransaction { tx, only_query: false };

// Deploy test contract.
let invoke_tx = account_invoke_tx(invoke_tx_args! {
8 changes: 4 additions & 4 deletions crates/blockifier/src/test_utils/declare.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use starknet_api::contract_class::ClassInfo;
use starknet_api::executable_transaction::AccountTransaction as ExecutableTransaction;
use starknet_api::executable_transaction::AccountTransaction;
use starknet_api::test_utils::declare::{executable_declare_tx, DeclareTxArgs};

use crate::transaction::account_transaction::AccountTransaction;

// TODO(AvivG): remove this func & file.
pub fn declare_tx(declare_tx_args: DeclareTxArgs, class_info: ClassInfo) -> AccountTransaction {
// TODO(AvivG): see into making 'executable_declare_tx' ret type AccountTransaction.
let declare_tx = executable_declare_tx(declare_tx_args, class_info);

AccountTransaction { tx: ExecutableTransaction::Declare(declare_tx), only_query: false }
AccountTransaction::Declare(declare_tx)
}
11 changes: 4 additions & 7 deletions crates/blockifier/src/test_utils/deploy_account.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
use starknet_api::executable_transaction::AccountTransaction as ExecutableTransaction;
use starknet_api::executable_transaction::AccountTransaction;
use starknet_api::test_utils::deploy_account::{executable_deploy_account_tx, DeployAccountTxArgs};
use starknet_api::test_utils::NonceManager;

use crate::transaction::account_transaction::AccountTransaction;

// TODO(AvivG): remove this func & file.
pub fn deploy_account_tx(
deploy_tx_args: DeployAccountTxArgs,
nonce_manager: &mut NonceManager,
) -> AccountTransaction {
// TODO(AvivG): see into making 'executable_deploy_account_tx' ret type AccountTransaction.
let deploy_account_tx = executable_deploy_account_tx(deploy_tx_args, nonce_manager);

AccountTransaction {
tx: ExecutableTransaction::DeployAccount(deploy_account_tx),
only_query: false,
}
AccountTransaction::DeployAccount(deploy_account_tx)
}
11 changes: 4 additions & 7 deletions crates/blockifier/src/test_utils/invoke.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use starknet_api::executable_transaction::AccountTransaction as ExecutableTransaction;
use starknet_api::executable_transaction::AccountTransaction;
use starknet_api::test_utils::invoke::{executable_invoke_tx, InvokeTxArgs};

use crate::transaction::account_transaction::AccountTransaction;

// TODO(AvivG): remove this func & file.
pub fn invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction {
let only_query = invoke_args.only_query;
let invoke_tx = ExecutableTransaction::Invoke(executable_invoke_tx(invoke_args));

AccountTransaction { tx: invoke_tx, only_query }
// TODO(AvivG): see into making 'executable_invoke_tx' ret type AccountTransaction.
AccountTransaction::Invoke(executable_invoke_tx(invoke_args))
}
6 changes: 4 additions & 2 deletions crates/blockifier/src/test_utils/transfers_generator.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ use rand::rngs::StdRng;
use rand::{Rng, SeedableRng};
use starknet_api::abi::abi_utils::selector_from_name;
use starknet_api::core::ContractAddress;
use starknet_api::executable_transaction::AccountTransaction as ApiExecutableTransaction;
use starknet_api::test_utils::NonceManager;
use starknet_api::transaction::constants::TRANSFER_ENTRY_POINT_NAME;
use starknet_api::transaction::fields::Fee;
@@ -143,7 +144,8 @@ impl TransfersGenerator {
let recipient_address = self.get_next_recipient();
self.sender_index = (self.sender_index + 1) % self.account_addresses.len();

let account_tx = self.generate_transfer(sender_address, recipient_address);
let tx = self.generate_transfer(sender_address, recipient_address);
let account_tx = AccountTransaction { tx, only_query: false };
txs.push(Transaction::Account(account_tx));
}
let results = self.executor.execute_txs(&txs);
@@ -159,7 +161,7 @@ impl TransfersGenerator {
&mut self,
sender_address: ContractAddress,
recipient_address: ContractAddress,
) -> AccountTransaction {
) -> ApiExecutableTransaction {
let nonce = self.nonce_manager.next(sender_address);

let entry_point_selector = selector_from_name(TRANSFER_ENTRY_POINT_NAME);
6 changes: 1 addition & 5 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
@@ -768,11 +768,7 @@ impl<U: UpdatableState> ExecutableTransaction<U> for AccountTransaction {

impl TransactionInfoCreator for AccountTransaction {
fn create_tx_info(&self) -> TransactionInfo {
match &self.tx {
Transaction::Declare(tx) => tx.create_tx_info(self.only_query),
Transaction::DeployAccount(tx) => tx.create_tx_info(self.only_query),
Transaction::Invoke(tx) => tx.create_tx_info(self.only_query),
}
self.tx.create_tx_info(self.only_query)
}
}

Original file line number Diff line number Diff line change
@@ -190,7 +190,7 @@ fn test_fee_enforcement(
) {
let account = FeatureContract::AccountWithoutValidations(CairoVersion::Cairo0);
let state = &mut test_state(&block_context.chain_info, BALANCE, &[(account, 1)]);
let deploy_account_tx = deploy_account_tx(
let tx = deploy_account_tx(
deploy_account_tx_args! {
class_hash: account.get_class_hash(),
max_fee: Fee(if zero_bounds { 0 } else { MAX_FEE.0 }),
@@ -212,6 +212,7 @@ fn test_fee_enforcement(
},
&mut NonceManager::default(),
);
let deploy_account_tx = AccountTransaction { tx, only_query: false };

let enforce_fee = deploy_account_tx.enforce_fee();
assert_ne!(zero_bounds, enforce_fee);
@@ -451,7 +452,7 @@ fn test_max_fee_limit_validate(
let class_info = calculate_class_info_for_testing(grindy_validate_account.get_class());

// Declare the grindy-validation account.
let account_tx = declare_tx(
let tx = declare_tx(
declare_tx_args! {
class_hash: grindy_class_hash,
sender_address: account_address,
@@ -460,6 +461,7 @@ fn test_max_fee_limit_validate(
},
class_info,
);
let account_tx = AccountTransaction { tx, only_query: false };
account_tx.execute(&mut state, &block_context, true, true).unwrap();

// Deploy grindy account with a lot of grind in the constructor.
23 changes: 15 additions & 8 deletions crates/blockifier/src/transaction/test_utils.rs
Original file line number Diff line number Diff line change
@@ -113,7 +113,10 @@ pub fn deploy_and_fund_account(
deploy_tx_args: DeployAccountTxArgs,
) -> (AccountTransaction, ContractAddress) {
// Deploy an account contract.
let deploy_account_tx = deploy_account_tx(deploy_tx_args, nonce_manager);
let deploy_account_tx = AccountTransaction {
tx: deploy_account_tx(deploy_tx_args, nonce_manager),
only_query: false,
};
let account_address = deploy_account_tx.sender_address();

// Update the balance of the about-to-be deployed account contract in the erc20 contract, so it
@@ -235,7 +238,7 @@ pub fn create_account_tx_for_validate_test(
};
let class_hash = declared_contract.get_class_hash();
let class_info = calculate_class_info_for_testing(declared_contract.get_class());
declare_tx(
let tx = declare_tx(
declare_tx_args! {
max_fee,
resource_bounds,
@@ -247,7 +250,8 @@ pub fn create_account_tx_for_validate_test(
compiled_class_hash: declared_contract.get_compiled_class_hash(),
},
class_info,
)
);
AccountTransaction { tx, only_query: false }
}
TransactionType::DeployAccount => {
// We do not use the sender address here because the transaction generates the actual
@@ -256,7 +260,7 @@ pub fn create_account_tx_for_validate_test(
true => constants::FELT_TRUE,
false => constants::FELT_FALSE,
})];
deploy_account_tx(
let tx = deploy_account_tx(
deploy_account_tx_args! {
max_fee,
resource_bounds,
@@ -267,26 +271,29 @@ pub fn create_account_tx_for_validate_test(
constructor_calldata,
},
nonce_manager,
)
);
AccountTransaction { tx, only_query: false }
}
TransactionType::InvokeFunction => {
let execute_calldata = create_calldata(sender_address, "foo", &[]);
invoke_tx(invoke_tx_args! {
let tx = invoke_tx(invoke_tx_args! {
max_fee,
resource_bounds,
signature,
sender_address,
calldata: execute_calldata,
version: tx_version,
nonce: nonce_manager.next(sender_address),
})
});
AccountTransaction { tx, only_query: false }
}
_ => panic!("{tx_type:?} is not an account transaction."),
}
}

pub fn account_invoke_tx(invoke_args: InvokeTxArgs) -> AccountTransaction {
invoke_tx(invoke_args)
let only_query = invoke_args.only_query;
AccountTransaction { tx: invoke_tx(invoke_args), only_query }
}

pub fn run_invoke_tx(
17 changes: 17 additions & 0 deletions crates/blockifier/src/transaction/transactions.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ use starknet_api::abi::abi_utils::selector_from_name;
use starknet_api::contract_class::EntryPointType;
use starknet_api::core::{ClassHash, CompiledClassHash, ContractAddress};
use starknet_api::executable_transaction::{
AccountTransaction,
DeclareTransaction,
DeployAccountTransaction,
InvokeTransaction,
@@ -179,6 +180,16 @@ impl TransactionInfoCreator for L1HandlerTransaction {
}
}

impl TransactionInfoCreatorInner for AccountTransaction {
fn create_tx_info(&self, only_query: bool) -> TransactionInfo {
match self {
Self::Declare(tx) => tx.create_tx_info(only_query),
Self::DeployAccount(tx) => tx.create_tx_info(only_query),
Self::Invoke(tx) => tx.create_tx_info(only_query),
}
}
}

impl<S: State> Executable<S> for DeclareTransaction {
fn run_execute(
&self,
@@ -393,6 +404,12 @@ impl TransactionInfoCreatorInner for InvokeTransaction {
}
}

/// Determines whether the fee should be enforced for the given transaction.
pub fn enforce_fee(tx: &AccountTransaction, only_query: bool) -> bool {
// TODO(AvivG): Consider implemetation without 'create_tx_info'.
tx.create_tx_info(only_query).enforce_fee()
}

/// Attempts to declare a contract class by setting the contract class in the state with the
/// specified class hash.
fn try_declare<S: State>(
Loading