-
Notifications
You must be signed in to change notification settings - Fork 234
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
fix: ensure max_fee_per_blob_gas
field handles Some(0)
gracefully
#1389
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cd9f247
max_fee_per_blob_gas with Some(0) will always fail because it is belo…
zerosnacks c3c266d
add basic EIP-4844 test without defining max_fee_per_blob_gas
zerosnacks c551138
test both cases, explicit Some(0) and implicit Some(0) / None
zerosnacks 3318c9f
fix clippy
zerosnacks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ use crate::{ | |
utils::Eip1559Estimation, | ||
Provider, | ||
}; | ||
use alloy_eips::eip4844::BLOB_TX_MIN_BLOB_GASPRICE; | ||
use alloy_json_rpc::RpcError; | ||
use alloy_network::{Network, TransactionBuilder, TransactionBuilder4844}; | ||
use alloy_network_primitives::{BlockResponse, HeaderResponse}; | ||
|
@@ -196,8 +197,11 @@ where | |
type Fillable = u128; | ||
|
||
fn status(&self, tx: &<N as Network>::TransactionRequest) -> FillerControlFlow { | ||
// nothing to fill if non-eip4844 tx or max_fee_per_blob_gas is already set | ||
if tx.blob_sidecar().is_none() || tx.max_fee_per_blob_gas().is_some() { | ||
// Nothing to fill if non-eip4844 tx or `max_fee_per_blob_gas` is already set to a valid | ||
// value. | ||
if tx.blob_sidecar().is_none() | ||
|| tx.max_fee_per_blob_gas().is_some_and(|gas| gas >= BLOB_TX_MIN_BLOB_GASPRICE) | ||
{ | ||
return FillerControlFlow::Finished; | ||
} | ||
|
||
|
@@ -216,8 +220,11 @@ where | |
T: Transport + Clone, | ||
{ | ||
if let Some(max_fee_per_blob_gas) = tx.max_fee_per_blob_gas() { | ||
return Ok(max_fee_per_blob_gas); | ||
if max_fee_per_blob_gas >= BLOB_TX_MIN_BLOB_GASPRICE { | ||
return Ok(max_fee_per_blob_gas); | ||
} | ||
} | ||
|
||
provider | ||
.get_block_by_number(BlockNumberOrTag::Latest, false) | ||
.await? | ||
|
@@ -244,17 +251,24 @@ where | |
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::{ProviderBuilder, WalletProvider}; | ||
use crate::ProviderBuilder; | ||
use alloy_consensus::{SidecarBuilder, SimpleCoder}; | ||
use alloy_eips::eip4844::DATA_GAS_PER_BLOB; | ||
use alloy_primitives::{address, U256}; | ||
use alloy_rpc_types_eth::TransactionRequest; | ||
|
||
fn init_tracing() { | ||
let _ = tracing_subscriber::fmt::try_init(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn no_gas_price_or_limit() { | ||
init_tracing(); | ||
|
||
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); | ||
let from = provider.default_signer_address(); | ||
|
||
// GasEstimationLayer requires chain_id to be set to handle EIP-1559 tx | ||
let tx = TransactionRequest { | ||
from: Some(from), | ||
value: Some(U256::from(100)), | ||
to: Some(address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").into()), | ||
chain_id: Some(31337), | ||
|
@@ -263,21 +277,20 @@ mod tests { | |
|
||
let tx = provider.send_transaction(tx).await.unwrap(); | ||
|
||
let tx = tx.get_receipt().await.unwrap(); | ||
let receipt = tx.get_receipt().await.unwrap(); | ||
|
||
assert_eq!(tx.effective_gas_price, 0x3b9aca01); | ||
assert_eq!(tx.gas_used, 0x5208); | ||
assert_eq!(receipt.effective_gas_price, 1_000_000_001); | ||
assert_eq!(receipt.gas_used, 21000); | ||
} | ||
|
||
#[tokio::test] | ||
async fn no_gas_limit() { | ||
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); | ||
init_tracing(); | ||
|
||
let from = provider.default_signer_address(); | ||
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); | ||
|
||
let gas_price = provider.get_gas_price().await.unwrap(); | ||
let tx = TransactionRequest { | ||
from: Some(from), | ||
value: Some(U256::from(100)), | ||
to: Some(address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").into()), | ||
gas_price: Some(gas_price), | ||
|
@@ -288,6 +301,65 @@ mod tests { | |
|
||
let receipt = tx.get_receipt().await.unwrap(); | ||
|
||
assert_eq!(receipt.gas_used, 0x5208); | ||
assert_eq!(receipt.gas_used, 21000); | ||
} | ||
|
||
#[tokio::test] | ||
async fn no_max_fee_per_blob_gas() { | ||
init_tracing(); | ||
|
||
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); | ||
|
||
let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice(b"Hello World"); | ||
let sidecar = sidecar.build().unwrap(); | ||
|
||
let tx = TransactionRequest { | ||
to: Some(address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").into()), | ||
sidecar: Some(sidecar), | ||
..Default::default() | ||
Comment on lines
+317
to
+319
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests both cases, implicit |
||
}; | ||
|
||
let tx = provider.send_transaction(tx).await.unwrap(); | ||
|
||
let receipt = tx.get_receipt().await.unwrap(); | ||
|
||
let tx = provider.get_transaction_by_hash(receipt.transaction_hash).await.unwrap().unwrap(); | ||
|
||
assert!(tx.max_fee_per_blob_gas.unwrap() >= BLOB_TX_MIN_BLOB_GASPRICE); | ||
assert_eq!(receipt.gas_used, 21000); | ||
assert_eq!( | ||
receipt.blob_gas_used.expect("Expected to be EIP-4844 transaction"), | ||
DATA_GAS_PER_BLOB as u128 | ||
); | ||
} | ||
|
||
#[tokio::test] | ||
async fn zero_max_fee_per_blob_gas() { | ||
init_tracing(); | ||
|
||
let provider = ProviderBuilder::new().with_recommended_fillers().on_anvil_with_wallet(); | ||
|
||
let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice(b"Hello World"); | ||
let sidecar = sidecar.build().unwrap(); | ||
|
||
let tx = TransactionRequest { | ||
to: Some(address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").into()), | ||
max_fee_per_blob_gas: Some(0), | ||
sidecar: Some(sidecar), | ||
..Default::default() | ||
}; | ||
|
||
let tx = provider.send_transaction(tx).await.unwrap(); | ||
|
||
let receipt = tx.get_receipt().await.unwrap(); | ||
|
||
let tx = provider.get_transaction_by_hash(receipt.transaction_hash).await.unwrap().unwrap(); | ||
|
||
assert!(tx.max_fee_per_blob_gas.unwrap() >= BLOB_TX_MIN_BLOB_GASPRICE); | ||
assert_eq!(receipt.gas_used, 21000); | ||
assert_eq!( | ||
receipt.blob_gas_used.expect("Expected to be EIP-4844 transaction"), | ||
DATA_GAS_PER_BLOB as u128 | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the field is set to
Some(0)
(which happens because of serialization) we force setting it to.next_block_blob_fee()
as 0 is always invalid as it is less thanBLOB_TX_MIN_BLOB_GASPRICE
(1).