Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(config): move execution config to default #1828

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions config/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,20 @@
"pointer_target": "collect_metrics",
"privacy": "Public"
},
"rpc.execution_config": {
"description": "Path to the execution configuration file.",
"rpc.execution_config.eth_fee_contract_address": {
"description": "The eth fee token address to receive fees",
"privacy": "Public",
"value": "config/execution/mainnet.json"
"value": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
},
"rpc.execution_config.initial_gas_cost": {
"description": "The initial gas cost for a transaction",
"privacy": "Public",
"value": 10000000000
},
"rpc.execution_config.strk_fee_contract_address": {
"description": "The strk fee token address to receive fees",
"privacy": "Public",
"value": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
},
"rpc.max_events_chunk_size": {
"description": "Maximum chunk size supported by the node in get_events requests.",
Expand Down
5 changes: 0 additions & 5 deletions config/execution/goerli_integration.json

This file was deleted.

5 changes: 0 additions & 5 deletions config/execution/goerli_testnet.json

This file was deleted.

5 changes: 0 additions & 5 deletions config/execution/mainnet.json

This file was deleted.

5 changes: 0 additions & 5 deletions config/execution/sepolia_integration.json

This file was deleted.

5 changes: 0 additions & 5 deletions config/execution/sepolia_testnet.json

This file was deleted.

6 changes: 0 additions & 6 deletions config/presets/goerli_integration.json

This file was deleted.

6 changes: 0 additions & 6 deletions config/presets/goerli_testnet.json

This file was deleted.

6 changes: 0 additions & 6 deletions config/presets/mainnet.json

This file was deleted.

6 changes: 0 additions & 6 deletions config/presets/sepolia_integration.json

This file was deleted.

6 changes: 0 additions & 6 deletions config/presets/sepolia_testnet.json

This file was deleted.

48 changes: 7 additions & 41 deletions crates/papyrus_execution/src/execution_test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// TODO(shahak): Add a test for executing when there's a missing casm that's not required and when
// there's a missing casm that is required.
use std::path::PathBuf;
use std::sync::Arc;

use assert_matches::assert_matches;
use blockifier::abi::abi_utils::get_storage_var_address;
use blockifier::execution::call_info::Retdata;
use blockifier::transaction::errors::TransactionExecutionError as BlockifierTransactionExecutionError;
use blockifier::versioned_constants::VersionedConstants;
use indexmap::indexmap;
use papyrus_storage::test_utils::get_test_storage;
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -51,20 +49,17 @@ use crate::test_utils::{
SEQUENCER_ADDRESS,
TEST_ERC20_CONTRACT_ADDRESS,
};
use crate::testing_instances::test_execution_config;
use crate::testing_instances::get_test_execution_config;
use crate::{
estimate_fee,
execute_call,
get_versioned_constants,
ExecutableTransactionInput,
ExecutionConfig,
ExecutionError,
FeeEstimationResult,
RevertedTransaction,
};

const NUM_OF_PRESET_EXECUTION_CONFIGS: usize = 5;

// Test calling entry points of a deprecated class.
#[test]
fn execute_call_cairo0() {
Expand All @@ -84,7 +79,7 @@ fn execute_call_cairo0() {
&DEPRECATED_CONTRACT_ADDRESS,
selector_from_name("without_arg"),
Calldata::default(),
&test_execution_config(),
&get_test_execution_config(),
true,
)
.unwrap()
Expand All @@ -101,7 +96,7 @@ fn execute_call_cairo0() {
&DEPRECATED_CONTRACT_ADDRESS,
selector_from_name("with_arg"),
Calldata(Arc::new(vec![StarkFelt::from(25u128)])),
&test_execution_config(),
&get_test_execution_config(),
true,
)
.unwrap()
Expand All @@ -118,7 +113,7 @@ fn execute_call_cairo0() {
&DEPRECATED_CONTRACT_ADDRESS,
selector_from_name("return_result"),
Calldata(Arc::new(vec![StarkFelt::from(123u128)])),
&test_execution_config(),
&get_test_execution_config(),
true,
)
.unwrap()
Expand All @@ -135,7 +130,7 @@ fn execute_call_cairo0() {
&DEPRECATED_CONTRACT_ADDRESS,
selector_from_name("test_storage_read_write"),
Calldata(Arc::new(vec![StarkFelt::from(123u128), StarkFelt::from(456u128)])),
&test_execution_config(),
&get_test_execution_config(),
true,
)
.unwrap()
Expand Down Expand Up @@ -163,7 +158,7 @@ fn execute_call_cairo1() {
&CONTRACT_ADDRESS,
selector_from_name("test_storage_read_write"),
calldata,
&test_execution_config(),
&get_test_execution_config(),
true,
)
.unwrap()
Expand Down Expand Up @@ -258,7 +253,7 @@ fn estimate_fees(txs: Vec<ExecutableTransactionInput>) -> FeeEstimationResult {
None,
StateNumber::unchecked_right_after_block(BlockNumber(0)),
BlockNumber(1),
&test_execution_config(),
&get_test_execution_config(),
false,
// TODO(yair): Add test for blob fee estimation.
true,
Expand Down Expand Up @@ -655,35 +650,6 @@ fn simulate_invoke_from_new_account_validate_and_charge() {
assert_matches!(invoke_trace.fee_transfer_invocation, Some(_));
}

/// Test that the execution configs are loaded correctly. Compare the loaded configs to the
/// expected.
#[test]
fn test_preset_execution_configs() {
let mut execution_configs: Vec<ExecutionConfig> = Vec::new();
let preset_files_dir = "../../config/execution";
for path in preset_files_dir.parse::<PathBuf>().unwrap().read_dir().unwrap() {
let path = path.unwrap().path();
let execution_config_file = path.try_into().unwrap();
execution_configs.push(execution_config_file);
}
assert_eq!(execution_configs.len(), NUM_OF_PRESET_EXECUTION_CONFIGS);
for config in execution_configs {
assert_eq!(config, get_default_execution_config());
}
}

fn get_default_execution_config() -> ExecutionConfig {
ExecutionConfig {
strk_fee_contract_address: contract_address!(
"0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
),
eth_fee_contract_address: contract_address!(
"0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
),
initial_gas_cost: 10_u64.pow(8)
* VersionedConstants::latest_constants().gas_cost("step_gas_cost"),
}
}
#[test]
fn induced_state_diff() {
let ((storage_reader, storage_writer), _temp_dir) = get_test_storage();
Expand Down
50 changes: 47 additions & 3 deletions crates/papyrus_execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ mod test_utils;
pub mod testing_instances;

pub mod objects;
use std::collections::BTreeMap;
use std::num::NonZeroU128;
use std::path::Path;
use std::sync::Arc;
Expand Down Expand Up @@ -49,17 +50,20 @@ use objects::{PriceUnit, TransactionSimulationOutput};
use once_cell::sync::Lazy;
use papyrus_common::transaction_hash::get_transaction_hash;
use papyrus_common::TransactionOptions;
use papyrus_config::dumping::{ser_param, SerializeConfig};
use papyrus_config::{ParamPath, ParamPrivacyInput, SerializedParam};
use papyrus_storage::header::HeaderStorageReader;
use papyrus_storage::{StorageError, StorageReader};
use serde::{Deserialize, Serialize};
use starknet_api::block::{BlockNumber, StarknetVersion};
use starknet_api::core::{ChainId, ClassHash, ContractAddress, EntryPointSelector};
use starknet_api::core::{ChainId, ClassHash, ContractAddress, EntryPointSelector, PatriciaKey};
use starknet_api::data_availability::L1DataAvailabilityMode;
// TODO: merge multiple EntryPointType structs in SN_API into one.
use starknet_api::deprecated_contract_class::{
ContractClass as DeprecatedContractClass,
EntryPointType,
};
use starknet_api::hash::StarkHash;
use starknet_api::state::{StateNumber, ThinStateDiff};
use starknet_api::transaction::{
Calldata,
Expand All @@ -75,7 +79,7 @@ use starknet_api::transaction::{
TransactionHash,
TransactionVersion,
};
use starknet_api::StarknetApiError;
use starknet_api::{contract_address, patricia_key, StarknetApiError};
use state_reader::ExecutionStateReader;
use tracing::trace;

Expand All @@ -86,6 +90,11 @@ const GLOBAL_CONTRACT_CACHE_SIZE: usize = 100;

const STARKNET_VERSION_O_13_0: &str = "0.13.0";
const STARKNET_VERSION_O_13_1: &str = "0.13.1";
const STRK_FEE_CONTRACT_ADDRESS: &str =
"0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d";
const ETH_FEE_CONTRACT_ADDRESS: &str =
"0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7";
const INITIAL_GAS_COST: u64 = 10000000000;

/// Result type for execution functions.
pub type ExecutionResult<T> = Result<T, ExecutionError>;
Expand All @@ -104,12 +113,47 @@ static VERSIONED_CONSTANTS_13_1: Lazy<VersionedConstants> = Lazy::new(|| {
pub struct ExecutionConfig {
/// The strk address to receive fees
pub strk_fee_contract_address: ContractAddress,
/// The address to receive fees
/// The eth address to receive fees
pub eth_fee_contract_address: ContractAddress,
/// The initial gas cost for a transaction
pub initial_gas_cost: u64,
}

impl Default for ExecutionConfig {
fn default() -> Self {
ExecutionConfig {
strk_fee_contract_address: contract_address!(STRK_FEE_CONTRACT_ADDRESS),
eth_fee_contract_address: contract_address!(ETH_FEE_CONTRACT_ADDRESS),
initial_gas_cost: INITIAL_GAS_COST,
}
}
}

impl SerializeConfig for ExecutionConfig {
fn dump(&self) -> BTreeMap<ParamPath, SerializedParam> {
BTreeMap::from_iter([
ser_param(
"strk_fee_contract_address",
&self.strk_fee_contract_address,
"The strk fee token address to receive fees",
ParamPrivacyInput::Public,
),
ser_param(
"eth_fee_contract_address",
&self.eth_fee_contract_address,
"The eth fee token address to receive fees",
ParamPrivacyInput::Public,
),
ser_param(
"initial_gas_cost",
&self.initial_gas_cost,
"The initial gas cost for a transaction",
ParamPrivacyInput::Public,
),
])
}
}

#[allow(missing_docs)]
/// The error type for the execution module.
#[derive(thiserror::Error, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions crates/papyrus_execution/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use test_utils::read_json_file;

use crate::execution_utils::selector_from_name;
use crate::objects::{PendingData, TransactionSimulationOutput};
use crate::testing_instances::test_execution_config;
use crate::testing_instances::get_test_execution_config;
use crate::{simulate_transactions, ExecutableTransactionInput, OnlyQuery, SierraSize};

lazy_static! {
Expand Down Expand Up @@ -200,7 +200,7 @@ pub fn execute_simulate_transactions(
maybe_pending_data,
StateNumber::unchecked_right_after_block(BlockNumber(0)),
BlockNumber(1),
&test_execution_config(),
&get_test_execution_config(),
charge_fee,
validate,
// TODO: Consider testing without overriding DA (It's already tested in the RPC)
Expand Down
14 changes: 6 additions & 8 deletions crates/papyrus_execution/src/testing_instances.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![allow(clippy::unwrap_used)]
//! Utilities for generating testing instances of the execution objects.
use std::path::PathBuf;

/// Returns the storage key of a storage variable.
pub use blockifier::abi::abi_utils::get_storage_var_address;
Expand Down Expand Up @@ -32,13 +31,12 @@ use crate::objects::{
use crate::ExecutionConfig;

/// Creates ExecutionConfig for tests.
pub fn test_execution_config() -> ExecutionConfig {
let execution_config_file = PathBuf::from("../../config/execution/mainnet.json");
let execution_config: ExecutionConfig = execution_config_file.try_into().unwrap();
let mut execution_config = execution_config;
execution_config.eth_fee_contract_address = contract_address!("0x1001");
execution_config.strk_fee_contract_address = contract_address!("0x1001");
execution_config
pub fn get_test_execution_config() -> ExecutionConfig {
ExecutionConfig {
strk_fee_contract_address: contract_address!("0x1001"),
eth_fee_contract_address: contract_address!("0x1001"),
initial_gas_cost: 10_u64.pow(10),
}
}

auto_impl_get_test_instance! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,21 @@ expression: dumped_default_config
"value": false,
"privacy": "Public"
},
"rpc.execution_config": {
"description": "Path to the execution configuration file.",
"value": "config/execution/mainnet.json",
"rpc.execution_config.eth_fee_contract_address": {
"description": "The eth fee token address to receive fees",
"value": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"privacy": "Public"
},
"rpc.execution_config.initial_gas_cost": {
"description": "The initial gas cost for a transaction",
"value": {
"$serde_json::private::Number": "10000000000"
},
"privacy": "Public"
},
"rpc.execution_config.strk_fee_contract_address": {
"description": "The strk fee token address to receive fees",
"value": "0x4718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
"privacy": "Public"
},
"rpc.max_events_chunk_size": {
Expand Down
Loading
Loading