From dc4155047d1d761b6c30807a1863cca6cc6b5571 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Tue, 16 Apr 2024 17:22:44 +0300 Subject: [PATCH] chore: rename fee related fields to resource bounds --- crates/gateway/src/errors.rs | 2 +- .../src/stateless_transaction_validator.rs | 22 +++++++++---------- .../stateless_transaction_validator_test.rs | 8 +++---- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/crates/gateway/src/errors.rs b/crates/gateway/src/errors.rs index 10759bef..a2d55158 100644 --- a/crates/gateway/src/errors.rs +++ b/crates/gateway/src/errors.rs @@ -18,7 +18,7 @@ pub enum GatewayError { #[cfg_attr(test, derive(PartialEq))] pub enum TransactionValidatorError { #[error("Expected a positive amount of {resource:?}. Got {resource_bounds:?}.")] - ZeroFee { + ZeroResourceBounds { resource: Resource, resource_bounds: ResourceBounds, }, diff --git a/crates/gateway/src/stateless_transaction_validator.rs b/crates/gateway/src/stateless_transaction_validator.rs index 5ca5e6dc..e17dd337 100644 --- a/crates/gateway/src/stateless_transaction_validator.rs +++ b/crates/gateway/src/stateless_transaction_validator.rs @@ -28,13 +28,13 @@ impl StatelessTransactionValidator { // TODO(Arni, 1/5/2024): Add a mechanism that validate the sender address is not blocked. // TODO(Arni, 1/5/2024): Validate transaction version. - self.validate_fee(tx)?; + self.validate_resource_bounds(tx)?; self.validate_tx_size(tx)?; Ok(()) } - fn validate_fee(&self, tx: &ExternalTransaction) -> TransactionValidatorResult<()> { + fn validate_resource_bounds(&self, tx: &ExternalTransaction) -> TransactionValidatorResult<()> { let resource_bounds_mapping = match tx { ExternalTransaction::Declare(ExternalDeclareTransaction::V3(tx)) => &tx.resource_bounds, ExternalTransaction::DeployAccount(ExternalDeployAccountTransaction::V3(tx)) => { @@ -44,10 +44,10 @@ impl StatelessTransactionValidator { }; if self.config.validate_non_zero_l1_gas_fee { - validate_resource_bounds(resource_bounds_mapping, Resource::L1Gas)?; + validate_resource_is_non_zero(resource_bounds_mapping, Resource::L1Gas)?; } if self.config.validate_non_zero_l2_gas_fee { - validate_resource_bounds(resource_bounds_mapping, Resource::L2Gas)?; + validate_resource_is_non_zero(resource_bounds_mapping, Resource::L2Gas)?; } Ok(()) @@ -70,12 +70,10 @@ impl StatelessTransactionValidator { // Declare transaction has no calldata. return Ok(()); } - ExternalTransaction::DeployAccount(tx) => match tx { - ExternalDeployAccountTransaction::V3(tx) => &tx.constructor_calldata, - }, - ExternalTransaction::Invoke(tx) => match tx { - ExternalInvokeTransaction::V3(tx) => &tx.calldata, - }, + ExternalTransaction::DeployAccount(ExternalDeployAccountTransaction::V3(tx)) => { + &tx.constructor_calldata + } + ExternalTransaction::Invoke(ExternalInvokeTransaction::V3(tx)) => &tx.calldata, }; let calldata_length = calldata.0.len(); @@ -92,13 +90,13 @@ impl StatelessTransactionValidator { // Utilities. -fn validate_resource_bounds( +fn validate_resource_is_non_zero( resource_bounds_mapping: &ResourceBoundsMapping, resource: Resource, ) -> TransactionValidatorResult<()> { if let Some(resource_bounds) = resource_bounds_mapping.0.get(&resource) { if resource_bounds.max_amount == 0 || resource_bounds.max_price_per_unit == 0 { - return Err(TransactionValidatorError::ZeroFee { + return Err(TransactionValidatorError::ZeroResourceBounds { resource, resource_bounds: *resource_bounds, }); diff --git a/crates/gateway/src/stateless_transaction_validator_test.rs b/crates/gateway/src/stateless_transaction_validator_test.rs index 96f03e42..d6fffb8c 100644 --- a/crates/gateway/src/stateless_transaction_validator_test.rs +++ b/crates/gateway/src/stateless_transaction_validator_test.rs @@ -55,7 +55,7 @@ const DEFAULT_VALIDATOR_CONFIG_FOR_TESTING: StatelessTransactionValidatorConfig #[case::zero_l1_gas_resource_bounds( DEFAULT_VALIDATOR_CONFIG_FOR_TESTING, create_external_invoke_tx_for_testing(zero_resource_bounds_mapping(), calldata![]), - Err(TransactionValidatorError::ZeroFee{ + Err(TransactionValidatorError::ZeroResourceBounds{ resource: Resource::L1Gas, resource_bounds: ResourceBounds::default() }) )] @@ -65,7 +65,7 @@ const DEFAULT_VALIDATOR_CONFIG_FOR_TESTING: StatelessTransactionValidatorConfig create_resource_bounds_mapping(NON_EMPTY_RESOURCE_BOUNDS, ResourceBounds::default()), calldata![] ), - Err(TransactionValidatorError::ZeroFee{ + Err(TransactionValidatorError::ZeroResourceBounds{ resource: Resource::L2Gas, resource_bounds: ResourceBounds::default() }) )] @@ -86,7 +86,7 @@ const DEFAULT_VALIDATOR_CONFIG_FOR_TESTING: StatelessTransactionValidatorConfig DEFAULT_VALIDATOR_CONFIG_FOR_TESTING, create_external_deploy_account_tx_for_testing( non_zero_resource_bounds_mapping(), - calldata![StarkFelt::from_u128(1),StarkFelt::from_u128(2)], + calldata![StarkFelt::from_u128(1), StarkFelt::from_u128(2)], ), Err(TransactionValidatorError::CalldataTooLong { calldata_length: 2, max_calldata_length: 1 }) )] @@ -94,7 +94,7 @@ const DEFAULT_VALIDATOR_CONFIG_FOR_TESTING: StatelessTransactionValidatorConfig DEFAULT_VALIDATOR_CONFIG_FOR_TESTING, create_external_invoke_tx_for_testing( non_zero_resource_bounds_mapping(), - calldata![StarkFelt::from_u128(1),StarkFelt::from_u128(2)], + calldata![StarkFelt::from_u128(1), StarkFelt::from_u128(2)], ), Err(TransactionValidatorError::CalldataTooLong { calldata_length: 2, max_calldata_length: 1 }) )]