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

feat: add EIP-4844 transaction when auto-mining #398

Merged
merged 43 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
18740ec
patch(hardhat-core,hardhat-ethers): moved linkBytecode function & lib…
tenchleb Dec 18, 2023
b83176d
feat(hardhat-viem): added support to deployContract & sendDeploymentT…
tenchleb Dec 18, 2023
c9b885c
Revert "patch(hardhat-core,hardhat-ethers): moved linkBytecode functi…
tenchleb Apr 16, 2024
7b078dc
patch: removed "inner" prefix from non-exported function
tenchleb Apr 16, 2024
79c4e09
patch: removed type casting & added Hex type assertion
tenchleb Apr 16, 2024
ec8f20e
patch: applied code review suggestions
tenchleb Apr 16, 2024
dc6840c
perf: constant time checkpointing (#5136)
agostbiro Apr 19, 2024
e6665a5
fix: avoid ecrecover for known sender (#5137)
agostbiro Apr 19, 2024
abb6316
fix: avoid cloning transaction traces (#5138)
agostbiro Apr 19, 2024
6447e80
fix: avoid transferring traces to JS (#5139)
agostbiro Apr 19, 2024
beffe44
Cleanup
schaable Apr 19, 2024
ccb0ace
Add changeset
schaable Apr 19, 2024
fb4ee6e
Add library linking section to readme
schaable Apr 19, 2024
9b0b3f6
Fix typo
CobraLin Apr 20, 2024
8c9106b
Merge pull request #5154 from 0xblackbox/fix-typo
schaable Apr 20, 2024
581ae2b
Add acknowledgement in changeset
schaable Apr 20, 2024
a6324d1
Merge pull request #4695 from Chlebamaticon/feat-4652-viem-library-li…
schaable Apr 21, 2024
9a1ebe9
WIP: feat: add EIP-4844
Wodann Apr 2, 2024
80e04cd
test: add tests for validate_transaction_spec
Wodann Apr 17, 2024
d3e0121
feat: add eth_blobBaseFee RPC method
Wodann Apr 17, 2024
496fa99
feat: mine block with single EIP-4844 transaction when auto-mining
Wodann Apr 17, 2024
6e0f392
fix: clippy warning
Wodann Apr 21, 2024
7faf6dd
Merge remote-tracking branch 'origin/main' into feat/eip4844
Wodann Apr 22, 2024
61ce096
feat: add EIP-4844 pooled transaction
Wodann Apr 23, 2024
1b4d582
refactor: move functions to trait
Wodann Apr 23, 2024
2f62918
fix: RLP encoding
Wodann Apr 23, 2024
26364a1
test: add EIP-4844 integration tests
Wodann Apr 23, 2024
37826ce
test: more tests
Wodann Apr 24, 2024
1de6218
test: stub for blob hash opcode test
Wodann Apr 24, 2024
7b90c5f
test: finish and clean up tests
Wodann Apr 25, 2024
e4cf95d
Merge remote-tracking branch 'origin/main' into feat/eip4844
Wodann Apr 25, 2024
7e2833c
Merge branch 'main' into feat/eip4844
fvictorio Apr 26, 2024
da083ef
Update .changeset/tough-students-compare.md
Wodann Apr 26, 2024
ed16fb6
Update crates/edr_provider/src/error.rs
Wodann Apr 26, 2024
a443b13
misc: apply review suggestions
Wodann Apr 26, 2024
b4c7375
misc: removed leftover changeset from Hardhat
Wodann Apr 26, 2024
102acbc
misc: apply review suggestion
Wodann Apr 29, 2024
dc8b095
refactor: simplify source of truth
Wodann Apr 29, 2024
b69426c
Merge remote-tracking branch 'origin/main' into feat/eip4844
Wodann Apr 29, 2024
3168821
Merge remote-tracking branch 'origin/main' into feat/eip4844
Wodann May 6, 2024
b19a247
misc: add changelog
Wodann May 6, 2024
ebd08b7
test: fix Hardhat tests
Wodann May 6, 2024
68db137
Merge remote-tracking branch 'origin/main' into feat/eip4844
Wodann May 9, 2024
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
5 changes: 5 additions & 0 deletions .changeset/curly-carpets-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nomicfoundation/edr": minor
---

Added support for blob transactions (EIP-4844) when auto-mining is enabled and the mempool is empty
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion book/src/02_development/03_local_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ These are instructions for releasing the [EDR NPM package](../../crates/edr_napi
2. Go to the [edr_napi](../../crates/edr_napi/) directory.
3. Run `pnpm build`.
4. Look for the NAPI binary that was built for your platform. It has the format `edr.<PLATFORM>.node`. For example on Apple Silicon Macs, it's called `edr.darwin-arm64.node`.
5. Move the NAPI binary to the appropriate platform-specifc package in the [npm](../../crates/edr_napi/npm) directory. For example, on Apple Silicon Macs: `mv edr.darwin-arm64.node npm/darwin-arm64`.
5. Move the NAPI binary to the appropriate platform-specific package in the [npm](../../crates/edr_napi/npm) directory. For example, on Apple Silicon Macs: `mv edr.darwin-arm64.node npm/darwin-arm64`.
6. Complete the Verdaccio [publish steps](./02_verdaccio.md#usage) in the [edr_napi](../../crates/edr_napi/) directory. You can ignore the warnings about not finding NAPI binaries for other platforms.
8 changes: 5 additions & 3 deletions crates/edr_eth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.75"
alloy-rlp = { version = "0.3", default-features = false, features = ["derive"] }
c-kzg = { version = "1.0.0", default-features = false }
futures = { version = "0.3.28", default-features = false }
hash-db = { version = "0.15.2", default-features = false }
hash256-std-hasher = { version = "0.15.2", default-features = false }
Expand All @@ -20,9 +21,10 @@ reqwest = { version = "0.11", features = ["blocking", "json"] }
reqwest-middleware = { version = "0.2.4", default-features = false }
reqwest-retry = { version = "0.3.0", default-features = false }
reqwest-tracing = { version = "0.4.7", default-features = false, optional = true }
revm-primitives = { git = "https://github.com/NomicFoundation/revm", rev = "aceb093", version = "3.1", default-features = false, features = ["hashbrown"] }
revm-primitives = { git = "https://github.com/NomicFoundation/revm", rev = "aceb093", version = "3.1", default-features = false, features = ["c-kzg", "hashbrown"] }
serde = { version = "1.0.147", default-features = false, features = ["derive"], optional = true }
serde_json = { version = "1.0.89", optional = true }
sha2 = { version = "0.10.8", default-features = false }
sha3 = { version = "0.10.8", default-features = false }
thiserror = { version = "1.0.37", default-features = false }
tokio = { version = "1.21.2", default-features = false, features = ["fs", "macros", "sync"] }
Expand All @@ -48,7 +50,7 @@ walkdir = { version = "2.3.3", default-features = false }
[features]
default = ["std"]
rand = ["revm-primitives/rand"]
serde = ["dep:serde", "revm-primitives/serde", "serde_json"]
std = ["futures/std", "hash256-std-hasher/std", "hash-db/std", "hex/std", "itertools/use_std", "k256/std", "k256/precomputed-tables", "revm-primitives/std", "serde?/std", "sha3/std", "triehash/std", "uuid/std"]
serde = ["dep:serde", "c-kzg/serde", "revm-primitives/serde", "serde_json"]
std = ["futures/std", "hash256-std-hasher/std", "hash-db/std", "hex/std", "itertools/use_std", "k256/std", "k256/precomputed-tables", "revm-primitives/std", "serde?/std", "sha2/std", "sha3/std", "triehash/std", "uuid/std"]
tracing = ["dep:tracing", "reqwest-tracing"]
test-remote = ["serde"]
2 changes: 1 addition & 1 deletion crates/edr_eth/src/access_list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Part of this code was adapted from ethers-rs and is distributed under their
// licenss:
// license:
// - https://github.com/gakonst/ethers-rs/blob/cba6f071aedafb766e82e4c2f469ed5e4638337d/LICENSE-APACHE
// - https://github.com/gakonst/ethers-rs/blob/cba6f071aedafb766e82e4c2f469ed5e4638337d/LICENSE-MIT
// For the original context see: https://github.com/gakonst/ethers-rs/blob/3d9c3290d42b77c510e5b5d0b6f7a2f72913bfff/ethers-core/src/types/transaction/eip2930.rs
Expand Down
2 changes: 1 addition & 1 deletion crates/edr_eth/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Part of this code was adapted from foundry and is distributed under their
// licenss:
// license:
// - https://github.com/foundry-rs/foundry/blob/01b16238ff87dc7ca8ee3f5f13e389888c2a2ee4/LICENSE-APACHE
// - https://github.com/foundry-rs/foundry/blob/01b16238ff87dc7ca8ee3f5f13e389888c2a2ee4/LICENSE-MIT
// For the original context see: https://github.com/foundry-rs/foundry/blob/01b16238ff87dc7ca8ee3f5f13e389888c2a2ee4/anvil/core/src/eth/proof.rs
Expand Down
19 changes: 15 additions & 4 deletions crates/edr_eth/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod reorg;
mod reward;

use alloy_rlp::{BufMut, Decodable, RlpDecodable, RlpEncodable};
use revm_primitives::{calc_excess_blob_gas, keccak256};
use revm_primitives::{calc_blob_gasprice, calc_excess_blob_gas, keccak256};

use self::difficulty::calculate_ethash_canonical_difficulty;
pub use self::{
Expand Down Expand Up @@ -243,7 +243,7 @@ impl PartialHeader {
base_fee: options.base_fee.or_else(|| {
if spec_id >= SpecId::LONDON {
Some(if let Some(parent) = &parent {
calculate_next_base_fee(parent)
calculate_next_base_fee_per_gas(parent)
} else {
// Initial base fee from https://eips.ethereum.org/EIPS/eip-1559
U256::from(1_000_000_000)
Expand Down Expand Up @@ -338,7 +338,7 @@ impl From<Header> for PartialHeader {
/// # Panics
///
/// Panics if the parent header does not contain a base fee.
pub fn calculate_next_base_fee(parent: &Header) -> U256 {
pub fn calculate_next_base_fee_per_gas(parent: &Header) -> U256 {
let elasticity = 2;
let base_fee_max_change_denominator = U256::from(8);

Expand Down Expand Up @@ -370,6 +370,17 @@ pub fn calculate_next_base_fee(parent: &Header) -> U256 {
}
}

/// Calculates the next base fee per blob gas for a post-Cancun block, given the
/// parent's header.
pub fn calculate_next_base_fee_per_blob_gas(parent: &Header) -> U256 {
parent
.blob_gas
.as_ref()
.map_or(U256::ZERO, |BlobGas { excess_gas, .. }| {
U256::from(calc_blob_gasprice(*excess_gas))
})
}

#[cfg(test)]
mod tests {
use std::str::FromStr;
Expand Down Expand Up @@ -410,7 +421,7 @@ mod tests {

assert_eq!(
U256::from(next_base_fee),
calculate_next_base_fee(&parent_header)
calculate_next_base_fee_per_gas(&parent_header)
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/edr_eth/src/rlp.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub use alloy_rlp::{Decodable, Encodable, Error};
pub use alloy_rlp::{encode, Decodable, Encodable, Error};
63 changes: 60 additions & 3 deletions crates/edr_eth/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,69 @@
//! transaction related data

mod fake_signature;
/// Types for transaction gossip (aka pooled transactions)
pub mod pooled;
mod request;
mod signed;
mod r#type;

pub use revm_primitives::alloy_primitives::TxKind;
use revm_primitives::B256;

pub use self::{request::*, signed::*};
pub use self::{r#type::TransactionType, request::*, signed::*};
use crate::{access_list::AccessListItem, Address, Bytes, U256};

pub trait Transaction {
/// The effective gas price of the transaction, calculated using the
/// provided block base fee.
fn effective_gas_price(&self, block_base_fee: U256) -> U256;

/// The maximum amount of gas the transaction can use.
fn gas_limit(&self) -> u64;

/// The gas price the sender is willing to pay.
fn gas_price(&self) -> U256;

/// The maximum fee per gas the sender is willing to pay. Only applicable
/// for post-EIP-1559 transactions.
fn max_fee_per_gas(&self) -> Option<U256>;

/// The maximum fee per blob gas the sender is willing to pay. Only
/// applicable for EIP-4844 transactions.
fn max_fee_per_blob_gas(&self) -> Option<U256>;

/// The maximum priority fee per gas the sender is willing to pay. Only
/// applicable for post-EIP-1559 transactions.
fn max_priority_fee_per_gas(&self) -> Option<U256>;

/// The transaction's nonce.
fn nonce(&self) -> u64;

/// The address that receives the call, if any.
fn to(&self) -> Option<Address>;

/// The total amount of blob gas used by the transaction. Only applicable
/// for EIP-4844 transactions.
fn total_blob_gas(&self) -> Option<u64>;

/// The hash of the transaction.
fn transaction_hash(&self) -> &B256;

/// The type of the transaction.
fn transaction_type(&self) -> TransactionType;

/// The value of the transaction.
fn value(&self) -> U256;
}

pub fn max_cost(transaction: &impl Transaction) -> U256 {
U256::from(transaction.gas_limit()).saturating_mul(transaction.gas_price())
}

pub fn upfront_cost(transaction: &impl Transaction) -> U256 {
max_cost(transaction).saturating_add(transaction.value())
}

/// Represents _all_ transaction requests received from RPC
#[derive(Clone, Debug, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -50,8 +104,11 @@ pub struct EthTransactionRequest {
#[cfg_attr(feature = "serde", serde(default))]
pub access_list: Option<Vec<AccessListItem>>,
/// EIP-2718 type
#[cfg_attr(feature = "serde", serde(default, rename = "type"))]
pub transaction_type: Option<U256>,
#[cfg_attr(
feature = "serde",
serde(default, rename = "type", with = "crate::serde::optional_u64")
)]
pub transaction_type: Option<u64>,
/// Blobs (EIP-4844)
pub blobs: Option<Vec<Bytes>>,
/// Blob versioned hashes (EIP-4844)
Expand Down
Loading
Loading