reth_transaction_pool/blobstore/
converter.rs

1use alloy_consensus::{BlobTransactionSidecar, EnvKzgSettings};
2use alloy_eips::eip7594::BlobTransactionSidecarEip7594;
3use tokio::sync::Semaphore;
4
5// We allow up to 5 concurrent conversions to avoid excessive memory usage.
6static SEMAPHORE: Semaphore = Semaphore::const_new(5);
7
8/// A simple semaphore-based blob sidecar converter.
9#[derive(Debug, Clone, Default)]
10#[non_exhaustive]
11pub struct BlobSidecarConverter;
12
13impl BlobSidecarConverter {
14    /// Creates a new blob sidecar converter.
15    pub const fn new() -> Self {
16        Self
17    }
18
19    /// Converts the blob sidecar to the EIP-7594 format.
20    pub async fn convert(
21        &self,
22        sidecar: BlobTransactionSidecar,
23    ) -> Option<BlobTransactionSidecarEip7594> {
24        let _permit = SEMAPHORE.acquire().await.ok()?;
25        tokio::task::spawn_blocking(move || sidecar.try_into_7594(EnvKzgSettings::Default.get()))
26            .await
27            .ok()?
28            .ok()
29    }
30}