Skip to content

Commit

Permalink
chore: add blob_count and max_blobs to TooManyBlobs err enum (bluea…
Browse files Browse the repository at this point in the history
…lloy#1375)

* add: essential info to `TooManyBlobs` err enum

* fix clippy

* nit: with names

* fix
  • Loading branch information
yash-atreya authored May 4, 2024
1 parent 8f5be0e commit 7f19b98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 6 additions & 2 deletions crates/primitives/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ impl Env {

// ensure the total blob gas spent is at most equal to the limit
// assert blob_gas_used <= MAX_BLOB_GAS_PER_BLOCK
if self.tx.blob_hashes.len() > MAX_BLOB_NUMBER_PER_BLOCK as usize {
return Err(InvalidTransaction::TooManyBlobs);
let num_blobs = self.tx.blob_hashes.len();
if num_blobs > MAX_BLOB_NUMBER_PER_BLOCK as usize {
return Err(InvalidTransaction::TooManyBlobs {
have: num_blobs,
max: MAX_BLOB_NUMBER_PER_BLOCK as usize,
});
}
}
} else {
Expand Down
9 changes: 7 additions & 2 deletions crates/primitives/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ pub enum InvalidTransaction {
/// `to` must be present
BlobCreateTransaction,
/// Transaction has more then [`crate::MAX_BLOB_NUMBER_PER_BLOCK`] blobs
TooManyBlobs,
TooManyBlobs {
max: usize,
have: usize,
},
/// Blob transaction contains a versioned hash with an incorrect version
BlobVersionNotSupported,
/// EOF TxCreate transaction is not supported before Prague hardfork.
Expand Down Expand Up @@ -339,7 +342,9 @@ impl fmt::Display for InvalidTransaction {
}
Self::EmptyBlobs => write!(f, "empty blobs"),
Self::BlobCreateTransaction => write!(f, "blob create transaction"),
Self::TooManyBlobs => write!(f, "too many blobs"),
Self::TooManyBlobs { max, have } => {
write!(f, "too many blobs, have {have}, max {max}")
}
Self::BlobVersionNotSupported => write!(f, "blob version not supported"),
Self::EofInitcodesNotSupported => write!(f, "EOF initcodes not supported"),
Self::EofCrateShouldHaveToAddress => write!(f, "EOF crate should have `to` address"),
Expand Down

0 comments on commit 7f19b98

Please sign in to comment.