Skip to content

Commit a71eb8f

Browse files
committed
apollo_gateway: add config for min_gas_price_precentage for threshold
1 parent 0bcb723 commit a71eb8f

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

config/sequencer/default_config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,11 @@
12441244
"privacy": "Public",
12451245
"value": "0x1"
12461246
},
1247+
"gateway_config.stateful_tx_validator_config.min_gas_price_percentage": {
1248+
"description": "Minimum gas price as percentage of threshold to accept transactions.",
1249+
"privacy": "Public",
1250+
"value": 80
1251+
},
12471252
"gateway_config.stateful_tx_validator_config.reject_future_declare_txs": {
12481253
"description": "If true, rejects declare transactions with future nonces.",
12491254
"privacy": "Public",

crates/apollo_deployments/resources/base_app_config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
"gateway_config.block_declare": false,
119119
"gateway_config.stateful_tx_validator_config.max_allowed_nonce_gap": 50,
120120
"gateway_config.stateful_tx_validator_config.max_nonce_for_validation_skip": "0x1",
121+
"gateway_config.stateful_tx_validator_config.min_gas_price_percentage": 80,
121122
"gateway_config.stateful_tx_validator_config.reject_future_declare_txs": true,
122123
"gateway_config.stateless_tx_validator_config.max_calldata_length": 5000,
123124
"gateway_config.stateless_tx_validator_config.max_contract_bytecode_size": 81920,

crates/apollo_gateway/src/config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ pub struct StatefulTransactionValidatorConfig {
172172
pub reject_future_declare_txs: bool,
173173
pub max_nonce_for_validation_skip: Nonce,
174174
pub versioned_constants_overrides: VersionedConstantsOverrides,
175+
// Minimum gas price as percentage of threshold to accept transactions.
176+
pub min_gas_price_percentage: u8, // E.g., 80 to require 80% of threshold.
175177
}
176178

177179
impl Default for StatefulTransactionValidatorConfig {
@@ -180,6 +182,7 @@ impl Default for StatefulTransactionValidatorConfig {
180182
max_allowed_nonce_gap: 50,
181183
reject_future_declare_txs: true,
182184
max_nonce_for_validation_skip: Nonce(Felt::ONE),
185+
min_gas_price_percentage: 80,
183186
versioned_constants_overrides: VersionedConstantsOverrides::default(),
184187
}
185188
}
@@ -206,6 +209,12 @@ impl SerializeConfig for StatefulTransactionValidatorConfig {
206209
"If true, rejects declare transactions with future nonces.",
207210
ParamPrivacyInput::Public,
208211
),
212+
ser_param(
213+
"min_gas_price_percentage",
214+
&self.min_gas_price_percentage,
215+
"Minimum gas price as percentage of threshold to accept transactions.",
216+
ParamPrivacyInput::Public,
217+
),
209218
]);
210219
dump.append(&mut prepend_sub_config_name(
211220
self.versioned_constants_overrides.dump(),

crates/apollo_gateway/src/gateway.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ use crate::sync_state_reader::SyncStateReaderFactory;
4949
#[path = "gateway_test.rs"]
5050
pub mod gateway_test;
5151

52-
// TODO(Arni): Move to a config.
53-
// Minimum gas price as percentage of threshold to accept transactions.
54-
const MIN_GAS_PRICE_PRECENTAGE: u8 = 80; // E.g., 80 to require 80% of threshold.
55-
5652
#[derive(Clone)]
5753
pub struct Gateway {
5854
pub config: Arc<GatewayConfig>,
@@ -218,6 +214,7 @@ impl ProcessTxBlockingTask {
218214
validate_tx_l2_gas_price_within_threshold(
219215
executable_tx.resource_bounds(),
220216
previous_block_l2_gas_price,
217+
self.stateful_tx_validator.config.min_gas_price_percentage,
221218
)?;
222219
}
223220

@@ -244,12 +241,13 @@ impl ProcessTxBlockingTask {
244241
fn validate_tx_l2_gas_price_within_threshold(
245242
tx_resource_bounds: ValidResourceBounds,
246243
previous_block_l2_gas_price: NonzeroGasPrice,
244+
min_gas_price_percentage: u8,
247245
) -> GatewayResult<()> {
248246
match tx_resource_bounds {
249247
ValidResourceBounds::AllResources(tx_resource_bounds) => {
250248
let tx_l2_gas_price = tx_resource_bounds.l2_gas.max_price_per_unit;
251249
let gas_price_threshold_multiplier =
252-
Ratio::new(MIN_GAS_PRICE_PRECENTAGE.into(), 100_u128);
250+
Ratio::new(min_gas_price_percentage.into(), 100_u128);
253251
let threshold =
254252
(gas_price_threshold_multiplier * previous_block_l2_gas_price.get().0).to_integer();
255253
if tx_l2_gas_price.0 < threshold {

0 commit comments

Comments
 (0)