mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
refactor: Reduce unnecessary LoC
By claude code
This commit is contained in:
@ -69,32 +69,22 @@ mod rlp {
|
||||
|
||||
impl<'a> From<&'a HlNewBlock> for HlNewBlockHelper<'a> {
|
||||
fn from(value: &'a HlNewBlock) -> Self {
|
||||
let HlNewBlock(NewBlock {
|
||||
block:
|
||||
HlBlock {
|
||||
header,
|
||||
body:
|
||||
HlBlockBody {
|
||||
inner: BlockBody { transactions, ommers, withdrawals },
|
||||
sidecars,
|
||||
read_precompile_calls,
|
||||
highest_precompile_address,
|
||||
},
|
||||
},
|
||||
td,
|
||||
}) = value;
|
||||
|
||||
let b = &value.0.block;
|
||||
Self {
|
||||
block: BlockHelper {
|
||||
header: Cow::Borrowed(header),
|
||||
transactions: Cow::Borrowed(transactions),
|
||||
ommers: Cow::Borrowed(ommers),
|
||||
withdrawals: withdrawals.as_ref().map(Cow::Borrowed),
|
||||
header: Cow::Borrowed(&b.header),
|
||||
transactions: Cow::Borrowed(&b.body.inner.transactions),
|
||||
ommers: Cow::Borrowed(&b.body.inner.ommers),
|
||||
withdrawals: b.body.inner.withdrawals.as_ref().map(Cow::Borrowed),
|
||||
},
|
||||
td: *td,
|
||||
sidecars: sidecars.as_ref().map(Cow::Borrowed),
|
||||
read_precompile_calls: read_precompile_calls.as_ref().map(Cow::Borrowed),
|
||||
highest_precompile_address: highest_precompile_address.as_ref().map(Cow::Borrowed),
|
||||
td: value.0.td,
|
||||
sidecars: b.body.sidecars.as_ref().map(Cow::Borrowed),
|
||||
read_precompile_calls: b.body.read_precompile_calls.as_ref().map(Cow::Borrowed),
|
||||
highest_precompile_address: b
|
||||
.body
|
||||
.highest_precompile_address
|
||||
.as_ref()
|
||||
.map(Cow::Borrowed),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -111,30 +101,24 @@ mod rlp {
|
||||
|
||||
impl Decodable for HlNewBlock {
|
||||
fn decode(buf: &mut &[u8]) -> alloy_rlp::Result<Self> {
|
||||
let HlNewBlockHelper {
|
||||
block: BlockHelper { header, transactions, ommers, withdrawals },
|
||||
td,
|
||||
sidecars,
|
||||
read_precompile_calls,
|
||||
highest_precompile_address,
|
||||
} = HlNewBlockHelper::decode(buf)?;
|
||||
|
||||
let h = HlNewBlockHelper::decode(buf)?;
|
||||
Ok(HlNewBlock(NewBlock {
|
||||
block: HlBlock {
|
||||
header: header.into_owned(),
|
||||
header: h.block.header.into_owned(),
|
||||
body: HlBlockBody {
|
||||
inner: BlockBody {
|
||||
transactions: transactions.into_owned(),
|
||||
ommers: ommers.into_owned(),
|
||||
withdrawals: withdrawals.map(|w| w.into_owned()),
|
||||
transactions: h.block.transactions.into_owned(),
|
||||
ommers: h.block.ommers.into_owned(),
|
||||
withdrawals: h.block.withdrawals.map(|w| w.into_owned()),
|
||||
},
|
||||
sidecars: sidecars.map(|s| s.into_owned()),
|
||||
read_precompile_calls: read_precompile_calls.map(|s| s.into_owned()),
|
||||
highest_precompile_address: highest_precompile_address
|
||||
sidecars: h.sidecars.map(|s| s.into_owned()),
|
||||
read_precompile_calls: h.read_precompile_calls.map(|s| s.into_owned()),
|
||||
highest_precompile_address: h
|
||||
.highest_precompile_address
|
||||
.map(|s| s.into_owned()),
|
||||
},
|
||||
},
|
||||
td,
|
||||
td: h.td,
|
||||
}))
|
||||
}
|
||||
}
|
||||
@ -172,41 +156,32 @@ impl HlNetworkBuilder {
|
||||
where
|
||||
Node: FullNodeTypes<Types = HlNode>,
|
||||
{
|
||||
let Self { engine_handle_rx, .. } = self;
|
||||
|
||||
let network_builder = ctx.network_config_builder()?;
|
||||
|
||||
let (to_import, from_network) = mpsc::unbounded_channel();
|
||||
let (to_network, import_outcome) = mpsc::unbounded_channel();
|
||||
|
||||
let handle = ImportHandle::new(to_import, import_outcome);
|
||||
let consensus = Arc::new(HlConsensus { provider: ctx.provider().clone() });
|
||||
|
||||
ctx.task_executor().spawn_critical("block import", async move {
|
||||
let handle = engine_handle_rx
|
||||
let handle = self
|
||||
.engine_handle_rx
|
||||
.lock()
|
||||
.await
|
||||
.take()
|
||||
.expect("node should only be launched once")
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
ImportService::new(consensus, handle, from_network, to_network).await.unwrap();
|
||||
});
|
||||
|
||||
let network_builder = network_builder
|
||||
.disable_dns_discovery()
|
||||
.disable_nat()
|
||||
.boot_nodes(boot_nodes())
|
||||
.set_head(ctx.head())
|
||||
.with_pow()
|
||||
.block_import(Box::new(HlBlockImport::new(handle)));
|
||||
// .discovery(discv4)
|
||||
// .eth_rlpx_handshake(Arc::new(HlHandshake::default()));
|
||||
|
||||
let network_config = ctx.build_network_config(network_builder);
|
||||
|
||||
Ok(network_config)
|
||||
Ok(ctx.build_network_config(
|
||||
ctx.network_config_builder()?
|
||||
.disable_dns_discovery()
|
||||
.disable_nat()
|
||||
.boot_nodes(boot_nodes())
|
||||
.set_head(ctx.head())
|
||||
.with_pow()
|
||||
.block_import(Box::new(HlBlockImport::new(handle))),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,11 +204,9 @@ where
|
||||
pool: Pool,
|
||||
) -> eyre::Result<Self::Network> {
|
||||
let block_source_config = self.block_source_config.clone();
|
||||
let network_config = self.network_config(ctx)?;
|
||||
let network = NetworkManager::builder(network_config).await?;
|
||||
let handle = ctx.start_network(network, pool);
|
||||
let handle =
|
||||
ctx.start_network(NetworkManager::builder(self.network_config(ctx)?).await?, pool);
|
||||
let local_node_record = handle.local_node_record();
|
||||
let chain_spec = ctx.chain_spec();
|
||||
info!(target: "reth::cli", enode=%local_node_record, "P2P networking initialized");
|
||||
|
||||
let next_block_number = ctx
|
||||
@ -243,12 +216,17 @@ where
|
||||
.block_number +
|
||||
1;
|
||||
|
||||
let chain_spec = ctx.chain_spec();
|
||||
ctx.task_executor().spawn_critical("pseudo peer", async move {
|
||||
let block_source =
|
||||
block_source_config.create_cached_block_source((&*chain_spec).clone(), next_block_number).await;
|
||||
start_pseudo_peer(chain_spec, local_node_record.to_string(), block_source)
|
||||
.await
|
||||
.unwrap();
|
||||
start_pseudo_peer(
|
||||
chain_spec.clone(),
|
||||
local_node_record.to_string(),
|
||||
block_source_config
|
||||
.create_cached_block_source((*chain_spec).clone(), next_block_number)
|
||||
.await,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
Ok(handle)
|
||||
|
||||
Reference in New Issue
Block a user