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

chore: rename fee related fields to resource bounds #54

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
2 changes: 1 addition & 1 deletion crates/gateway/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
22 changes: 10 additions & 12 deletions crates/gateway/src/stateless_transaction_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) => {
Expand All @@ -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(())
Expand All @@ -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();
Expand All @@ -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,
});
Expand Down
8 changes: 4 additions & 4 deletions crates/gateway/src/stateless_transaction_validator_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
)]
Expand All @@ -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()
})
)]
Expand All @@ -86,15 +86,15 @@ 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 })
)]
#[case::invoke_calldata_too_long(
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 })
)]
Expand Down
Loading