Skip to content

Commit

Permalink
Remove load_trusted_setup_from_bytes (paradigmxyz#10719)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
  • Loading branch information
estensen and mattsse authored Sep 5, 2024
1 parent 80d511b commit 2b6b715
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 50 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions bin/reth/src/commands/debug_cmd/build_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ use reth_node_api::{NodeTypesWithDB, NodeTypesWithEngine, PayloadBuilderAttribut
use reth_node_ethereum::EthExecutorProvider;
use reth_payload_builder::database::CachedReads;
use reth_primitives::{
constants::eip4844::LoadKzgSettingsError, revm_primitives::KzgSettings, Address,
BlobTransaction, BlobTransactionSidecar, Bytes, PooledTransactionsElement, SealedBlock,
SealedBlockWithSenders, Transaction, TransactionSigned, TxEip4844, B256, U256,
revm_primitives::KzgSettings, Address, BlobTransaction, BlobTransactionSidecar, Bytes,
PooledTransactionsElement, SealedBlock, SealedBlockWithSenders, Transaction, TransactionSigned,
TxEip4844, B256, U256,
};
use reth_provider::{
providers::BlockchainProvider, BlockHashReader, BlockReader, BlockWriter, ChainSpecProvider,
Expand Down Expand Up @@ -107,7 +107,9 @@ impl<C: ChainSpecParser<ChainSpec = ChainSpec>> Command<C> {
fn kzg_settings(&self) -> eyre::Result<EnvKzgSettings> {
if let Some(ref trusted_setup_file) = self.trusted_setup_file {
let trusted_setup = KzgSettings::load_trusted_setup_file(trusted_setup_file)
.map_err(LoadKzgSettingsError::KzgError)?;
.wrap_err_with(|| {
format!("Failed to load trusted setup file: {:?}", trusted_setup_file)
})?;
Ok(EnvKzgSettings::Custom(Arc::new(trusted_setup)))
} else {
Ok(EnvKzgSettings::Default)
Expand Down
22 changes: 16 additions & 6 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ alloy-eips = { workspace = true, features = ["serde"] }

# optimism
op-alloy-rpc-types = { workspace = true, optional = true }
op-alloy-consensus = { workspace = true, features = ["arbitrary"], optional = true }
op-alloy-consensus = { workspace = true, features = [
"arbitrary",
], optional = true }

# crypto
secp256k1 = { workspace = true, features = [
Expand All @@ -52,8 +54,6 @@ modular-bitfield = { workspace = true, optional = true }
rayon.workspace = true
serde.workspace = true
once_cell.workspace = true
tempfile = { workspace = true, optional = true }
thiserror = { workspace = true, optional = true }
zstd = { workspace = true, features = ["experimental"], optional = true }

# arbitrary utils
Expand Down Expand Up @@ -87,7 +87,7 @@ pprof = { workspace = true, features = [

[features]
default = ["c-kzg", "alloy-compat", "std", "reth-codec", "secp256k1"]
std = ["thiserror", "reth-primitives-traits/std"]
std = ["reth-primitives-traits/std"]
reth-codec = ["dep:reth-codecs", "dep:zstd", "dep:modular-bitfield", "std"]
asm-keccak = ["alloy-primitives/asm-keccak"]
arbitrary = [
Expand All @@ -101,7 +101,12 @@ arbitrary = [
"reth-codec",
]
secp256k1 = ["dep:secp256k1"]
c-kzg = ["dep:c-kzg", "revm-primitives/c-kzg", "dep:tempfile", "alloy-eips/kzg", "alloy-consensus/kzg"]
c-kzg = [
"dep:c-kzg",
"revm-primitives/c-kzg",
"alloy-eips/kzg",
"alloy-consensus/kzg",
]
optimism = [
"reth-chainspec/optimism",
"reth-ethereum-forks/optimism",
Expand All @@ -110,7 +115,12 @@ optimism = [
"dep:reth-optimism-chainspec",
"dep:op-alloy-consensus",
]
alloy-compat = ["reth-primitives-traits/alloy-compat", "dep:alloy-rpc-types", "dep:alloy-serde", "dep:op-alloy-rpc-types"]
alloy-compat = [
"reth-primitives-traits/alloy-compat",
"dep:alloy-rpc-types",
"dep:alloy-serde",
"dep:op-alloy-rpc-types",
]
test-utils = ["reth-primitives-traits/test-utils"]

[[bench]]
Expand Down
38 changes: 0 additions & 38 deletions crates/primitives/src/constants/eip4844.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,7 @@
//! [EIP-4844](https://eips.ethereum.org/EIPS/eip-4844#parameters) protocol constants and utils for shard Blob Transactions.
#[cfg(all(feature = "c-kzg", feature = "std"))]
pub use trusted_setup::*;
pub use alloy_eips::eip4844::{
BLOB_GASPRICE_UPDATE_FRACTION, BLOB_TX_MIN_BLOB_GASPRICE, DATA_GAS_PER_BLOB,
FIELD_ELEMENTS_PER_BLOB, FIELD_ELEMENT_BYTES, MAX_BLOBS_PER_BLOCK, MAX_DATA_GAS_PER_BLOCK,
TARGET_BLOBS_PER_BLOCK, TARGET_DATA_GAS_PER_BLOCK, VERSIONED_HASH_VERSION_KZG,
};

// These 2 to silence unused
#[cfg(all(feature = "c-kzg", not(feature = "std")))]
use tempfile as _;
#[cfg(all(not(feature = "c-kzg"), feature = "std"))]
use thiserror as _;

#[cfg(all(feature = "c-kzg", feature = "std"))]
mod trusted_setup {
use crate::kzg::KzgSettings;
use std::io::Write;

/// Loads the trusted setup parameters from the given bytes and returns the [`KzgSettings`].
///
/// This creates a temp file to store the bytes and then loads the [`KzgSettings`] from the file
/// via [`KzgSettings::load_trusted_setup_file`].
pub fn load_trusted_setup_from_bytes(
bytes: &[u8],
) -> Result<KzgSettings, LoadKzgSettingsError> {
let mut file = tempfile::NamedTempFile::new().map_err(LoadKzgSettingsError::TempFileErr)?;
file.write_all(bytes).map_err(LoadKzgSettingsError::TempFileErr)?;
KzgSettings::load_trusted_setup_file(file.path()).map_err(LoadKzgSettingsError::KzgError)
}

/// Error type for loading the trusted setup.
#[derive(Debug, thiserror::Error)]
pub enum LoadKzgSettingsError {
/// Failed to create temp file to store bytes for loading [`KzgSettings`] via
/// [`KzgSettings::load_trusted_setup_file`].
#[error("failed to setup temp file: {0}")]
TempFileErr(#[from] std::io::Error),
/// Kzg error
#[error("KZG error: {0:?}")]
KzgError(#[from] c_kzg::Error),
}
}

0 comments on commit 2b6b715

Please sign in to comment.