Skip to content

Commit

Permalink
fix: bypass block gas limit if disabled (foundry-rs#8111)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Jun 7, 2024
1 parent e0785cf commit 0b03a58
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crates/anvil/src/eth/backend/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ impl<'a, 'b, DB: Db + ?Sized, Validator: TransactionValidator> Iterator
};
let env = self.env_for(&transaction.pending_transaction);

// check that we comply with the block's gas limit
// check that we comply with the block's gas limit, if not disabled
let max_gas = self.gas_used.saturating_add(env.tx.gas_limit as u128);
if max_gas > env.block.gas_limit.to::<u128>() {
if !env.cfg.disable_block_gas_limit && max_gas > env.block.gas_limit.to::<u128>() {
return Some(TransactionExecutionOutcome::Exhausted(transaction))
}

Expand Down
22 changes: 22 additions & 0 deletions crates/anvil/tests/it/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,28 @@ async fn can_reject_too_high_gas_limits() {
let _ = pending.unwrap();
}

// <https://github.com/foundry-rs/foundry/issues/8094>
#[tokio::test(flavor = "multi_thread")]
async fn can_mine_large_gas_limit() {
let (api, handle) = spawn(NodeConfig::test().disable_block_gas_limit(true)).await;
let provider = handle.http_provider();

let accounts = handle.dev_wallets().collect::<Vec<_>>();
let from = accounts[0].address();
let to = accounts[1].address();

let gas_limit = api.gas_limit().to::<u128>();
let amount = handle.genesis_balance().checked_div(U256::from(3u64)).unwrap();

let tx =
TransactionRequest::default().to(to).value(amount).from(from).with_gas_limit(gas_limit * 3);

// send transaction with higher gas limit
let pending = provider.send_transaction(WithOtherFields::new(tx)).await.unwrap();

let _resp = pending.get_receipt().await.unwrap();
}

#[tokio::test(flavor = "multi_thread")]
async fn can_reject_underpriced_replacement() {
let (api, handle) = spawn(NodeConfig::test()).await;
Expand Down

0 comments on commit 0b03a58

Please sign in to comment.