From 33fbd3b1fbafe8b1538f28c37f6b650cbb0c6f38 Mon Sep 17 00:00:00 2001 From: Afri <58883403+q9f@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:13:58 +0100 Subject: [PATCH] eth/tx: only enforce block gas limit on mainnet (#299) * eth/tx: only enforce block gas limit on mainnet * eth/tx: only enforce block gas limit on mainnet --- lib/eth/tx.rb | 4 +++- spec/eth/tx/eip1559_spec.rb | 1 + spec/eth/tx/eip2930_spec.rb | 1 + spec/eth/tx/legacy_spec.rb | 9 +++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/eth/tx.rb b/lib/eth/tx.rb index 500255f3..765e91f9 100644 --- a/lib/eth/tx.rb +++ b/lib/eth/tx.rb @@ -210,7 +210,9 @@ def validate_params(fields) if fields[:nonce].nil? or fields[:nonce] < 0 raise ParameterError, "Invalid signer nonce #{fields[:nonce]}!" end - if fields[:gas_limit].nil? or fields[:gas_limit] < DEFAULT_GAS_LIMIT or fields[:gas_limit] > BLOCK_GAS_LIMIT + if fields[:gas_limit].nil? or + fields[:gas_limit] < DEFAULT_GAS_LIMIT or + (fields[:gas_limit] > BLOCK_GAS_LIMIT and fields[:chain_id] == Chain::ETHEREUM) raise ParameterError, "Invalid gas limit #{fields[:gas_limit]}!" end unless fields[:value] >= 0 diff --git a/spec/eth/tx/eip1559_spec.rb b/spec/eth/tx/eip1559_spec.rb index 58dc5b6d..a83bd05b 100644 --- a/spec/eth/tx/eip1559_spec.rb +++ b/spec/eth/tx/eip1559_spec.rb @@ -102,6 +102,7 @@ priority_fee: 0, max_gas_fee: Unit::GWEI, gas_limit: Tx::BLOCK_GAS_LIMIT + 1, + chain_id: Chain::ETHEREUM, }) }.to raise_error Tx::ParameterError, "Invalid gas limit 30000001!" expect { diff --git a/spec/eth/tx/eip2930_spec.rb b/spec/eth/tx/eip2930_spec.rb index 4eefb7e1..8ae81466 100644 --- a/spec/eth/tx/eip2930_spec.rb +++ b/spec/eth/tx/eip2930_spec.rb @@ -101,6 +101,7 @@ nonce: 0, gas_price: Unit::GWEI, gas_limit: Tx::BLOCK_GAS_LIMIT + 1, + chain_id: Chain::ETHEREUM, }) }.to raise_error Tx::ParameterError, "Invalid gas limit 30000001!" expect { diff --git a/spec/eth/tx/legacy_spec.rb b/spec/eth/tx/legacy_spec.rb index 72459804..3a7795f7 100644 --- a/spec/eth/tx/legacy_spec.rb +++ b/spec/eth/tx/legacy_spec.rb @@ -128,8 +128,17 @@ nonce: 0, gas_price: Unit::GWEI, gas_limit: Tx::BLOCK_GAS_LIMIT + 1, + chain_id: Chain::ETHEREUM, }) }.to raise_error Tx::ParameterError, "Invalid gas limit 30000001!" + expect { + Tx.new({ + nonce: 0, + gas_price: Unit::GWEI, + gas_limit: Tx::BLOCK_GAS_LIMIT + 1, + chain_id: Chain::OPTIMISM, + }) + }.not_to raise_error # Block gas limit is only enforced in Ethereum mainnet expect { Tx.new({ nonce: -1,