mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-28 08:37:59 -05:00
feat(cli): allow overriding kzg trusted setup (#4335)
This commit is contained in:
committed by
GitHub
parent
82fb0eedb3
commit
3ffcae360e
@@ -301,4 +301,13 @@ mod tests {
|
||||
let log_dir = reth.logs.log_directory;
|
||||
assert!(log_dir.as_ref().ends_with("reth/logs/sepolia"), "{:?}", log_dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn override_trusted_setup_file() {
|
||||
// We already have a test that asserts that this has been initialized,
|
||||
// so we cheat a little bit and check that loading a random file errors.
|
||||
let reth = Cli::<()>::try_parse_from(["reth", "node", "--trusted-setup-file", "README.md"])
|
||||
.unwrap();
|
||||
assert!(reth.run().is_err());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +44,10 @@ use reth_interfaces::{
|
||||
use reth_network::{error::NetworkError, NetworkConfig, NetworkHandle, NetworkManager};
|
||||
use reth_network_api::NetworkInfo;
|
||||
use reth_primitives::{
|
||||
stage::StageId, BlockHashOrNumber, BlockNumber, ChainSpec, DisplayHardforks, Head,
|
||||
SealedHeader, H256,
|
||||
constants::eip4844::{LoadKzgSettingsError, MAINNET_KZG_TRUSTED_SETUP},
|
||||
kzg::KzgSettings,
|
||||
stage::StageId,
|
||||
BlockHashOrNumber, BlockNumber, ChainSpec, DisplayHardforks, Head, SealedHeader, H256,
|
||||
};
|
||||
use reth_provider::{
|
||||
providers::BlockchainProvider, BlockHashReader, BlockReader, CanonStateSubscriptions,
|
||||
@@ -122,6 +124,10 @@ pub struct NodeCommand<Ext: RethCliExt = ()> {
|
||||
#[arg(long, value_name = "SOCKET", value_parser = parse_socket_address, help_heading = "Metrics")]
|
||||
pub metrics: Option<SocketAddr>,
|
||||
|
||||
/// Overrides the KZG trusted setup by reading from the supplied file.
|
||||
#[arg(long, value_name = "PATH")]
|
||||
trusted_setup_file: Option<PathBuf>,
|
||||
|
||||
/// All networking related arguments
|
||||
#[clap(flatten)]
|
||||
pub network: NetworkArgs,
|
||||
@@ -167,6 +173,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
config,
|
||||
chain,
|
||||
metrics,
|
||||
trusted_setup_file,
|
||||
network,
|
||||
rpc,
|
||||
txpool,
|
||||
@@ -182,6 +189,7 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
config,
|
||||
chain,
|
||||
metrics,
|
||||
trusted_setup_file,
|
||||
network,
|
||||
rpc,
|
||||
txpool,
|
||||
@@ -262,19 +270,14 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
// setup the blockchain provider
|
||||
let factory = ProviderFactory::new(Arc::clone(&db), Arc::clone(&self.chain));
|
||||
let blockchain_db = BlockchainProvider::new(factory, blockchain_tree.clone())?;
|
||||
|
||||
let blob_store = InMemoryBlobStore::default();
|
||||
let transaction_pool = reth_transaction_pool::Pool::eth_pool(
|
||||
TransactionValidationTaskExecutor::eth_with_additional_tasks(
|
||||
blockchain_db.clone(),
|
||||
Arc::clone(&self.chain),
|
||||
blob_store.clone(),
|
||||
ctx.task_executor.clone(),
|
||||
1,
|
||||
),
|
||||
blob_store,
|
||||
self.txpool.pool_config(),
|
||||
);
|
||||
let validator = TransactionValidationTaskExecutor::eth_builder(Arc::clone(&self.chain))
|
||||
.kzg_settings(self.kzg_settings()?)
|
||||
.with_additional_tasks(1)
|
||||
.build_with_tasks(blockchain_db.clone(), ctx.task_executor.clone(), blob_store.clone());
|
||||
|
||||
let transaction_pool =
|
||||
reth_transaction_pool::Pool::eth_pool(validator, blob_store, self.txpool.pool_config());
|
||||
info!(target: "reth::cli", "Transaction pool initialized");
|
||||
|
||||
// spawn txpool maintenance task
|
||||
@@ -566,6 +569,18 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
|
||||
.wrap_err_with(|| format!("Could not load config file {:?}", config_path))
|
||||
}
|
||||
|
||||
/// Loads the trusted setup params from a given file path or falls back to
|
||||
/// `MAINNET_KZG_TRUSTED_SETUP`.
|
||||
fn kzg_settings(&self) -> eyre::Result<Arc<KzgSettings>> {
|
||||
if let Some(ref trusted_setup_file) = self.trusted_setup_file {
|
||||
let trusted_setup = KzgSettings::load_trusted_setup_file(trusted_setup_file.into())
|
||||
.map_err(LoadKzgSettingsError::KzgError)?;
|
||||
Ok(Arc::new(trusted_setup))
|
||||
} else {
|
||||
Ok(Arc::clone(&MAINNET_KZG_TRUSTED_SETUP))
|
||||
}
|
||||
}
|
||||
|
||||
fn init_trusted_nodes(&self, config: &mut Config) {
|
||||
config.peers.connect_trusted_nodes_only = self.network.trusted_only;
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ pub const VERSIONED_HASH_VERSION_KZG: u8 = 0x01;
|
||||
const TRUSTED_SETUP_RAW: &[u8] = include_bytes!("../../res/eip4844/trusted_setup.txt");
|
||||
|
||||
/// KZG trusted setup
|
||||
pub static KZG_TRUSTED_SETUP: Lazy<Arc<KzgSettings>> = Lazy::new(|| {
|
||||
pub static MAINNET_KZG_TRUSTED_SETUP: Lazy<Arc<KzgSettings>> = Lazy::new(|| {
|
||||
Arc::new(
|
||||
load_trusted_setup_from_bytes(TRUSTED_SETUP_RAW).expect("Failed to load trusted setup"),
|
||||
)
|
||||
@@ -69,6 +69,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn ensure_load_kzg_settings() {
|
||||
let _settings = Arc::clone(&KZG_TRUSTED_SETUP);
|
||||
let _settings = Arc::clone(&MAINNET_KZG_TRUSTED_SETUP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use crate::{
|
||||
TransactionValidationTaskExecutor, TransactionValidator,
|
||||
};
|
||||
use reth_primitives::{
|
||||
constants::{eip4844::KZG_TRUSTED_SETUP, ETHEREUM_BLOCK_GAS_LIMIT},
|
||||
constants::{eip4844::MAINNET_KZG_TRUSTED_SETUP, ETHEREUM_BLOCK_GAS_LIMIT},
|
||||
kzg::KzgSettings,
|
||||
ChainSpec, InvalidTransactionError, SealedBlock, EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID,
|
||||
EIP4844_TX_TYPE_ID, LEGACY_TX_TYPE_ID,
|
||||
@@ -356,7 +356,7 @@ impl EthTransactionValidatorBuilder {
|
||||
additional_tasks: 1,
|
||||
// default to true, can potentially take this as a param in the future
|
||||
propagate_local_transactions: true,
|
||||
kzg_settings: Arc::clone(&KZG_TRUSTED_SETUP),
|
||||
kzg_settings: Arc::clone(&MAINNET_KZG_TRUSTED_SETUP),
|
||||
|
||||
// by default all transaction types are allowed
|
||||
eip2718: true,
|
||||
|
||||
Reference in New Issue
Block a user