Skip to content

Commit 59dd6fe

Browse files
authored
feat: blob cache (#5)
* feat: blob cache * feat: decoding methods * feat: coder abstraction * refactor: improve constants * refactor: improve mod and test layout
1 parent cc13df1 commit 59dd6fe

File tree

9 files changed

+551
-207
lines changed

9 files changed

+551
-207
lines changed

README.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,32 @@
33
A collection of components for building the Signet node. These components
44
implement core node functionality, but are potentially indepedently useful.
55

6-
### What's new in Signet?
6+
## What's in the Components?
7+
8+
- **signet-node-types** - Shim types wrapping reth's internal node types
9+
system to make it more usable in Signet.
10+
- **signet-blobber** - Blob retrieval and parsing, using blob explorers,
11+
Signet's Pylon, and the local node transaction API.
12+
- **signet-rpc** - An Ethereum JSON-RPC Server for Signet nodes. Makes heavy
13+
use of reth internals.
14+
- **signet-db** - An extension of reth's database, providing a Signet-specific
15+
database schema and utilities for working with Signet blocks and transactions.
16+
17+
### Contributing to the Node Components
18+
19+
Please see [CONTRIBUTING.md](CONTRIBUTING.md).
20+
21+
[Signet docs]: https://docs.signet.sh
22+
23+
## Note on Semver
24+
25+
This repo is UNPUBLISHED and may NOT respect semantic versioning between tagged
26+
versions. In general, it is versioned to match the signet-sdk version with
27+
which it is compatible. I.e. `[email protected]` is expected to be
28+
compatible with any signet-sdk `0.8.x` version. However, a release of
29+
`[email protected]` may have breaking changes from `[email protected]`.
30+
31+
## What's new in Signet?
732

833
Signet is a pragmatic Ethereum rollup that offers a new set of ideas and aims
934
to radically modernize rollup technology.
@@ -22,20 +47,3 @@ knowledge. Signet does not have a native token.
2247
Signet is just a rollup.
2348

2449
See the [Signet docs] for more info.
25-
26-
### What's in the Components?
27-
28-
- **signet-node-types** - Shim types wrapping reth's internal node types
29-
system to make it more usable in Signet.
30-
- **signet-blobber** - Blob retrieval and parsing, using blob explorers,
31-
Signet's Pylon, and the local node transaction API.
32-
- **signet-rpc** - An Ethereum JSON-RPC Server for Signet nodes. Makes heavy
33-
use of reth internals.
34-
- **signet-db** - An extension of reth's database, providing a Signet-specific
35-
database schema and utilities for working with Signet blocks and transactions.
36-
37-
### Contributing to the Node Components
38-
39-
Please see [CONTRIBUTING.md](CONTRIBUTING.md).
40-
41-
[Signet docs]: https://docs.signet.sh

crates/blobber/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Block Extractor
22

3-
The [`BlockExtractor`] retrieves blobs from host chain blocks and parses them
3+
The [`BlobFetcher`] retrieves blobs from host chain blocks and parses them
44
into [`ZenithBlock`]s. It is used by the node during notification processing
55
when a [`Zenith::BlockSubmitted`] event is extracted from a host chain block.
66

7+
The [`BlobCacher`] is a wrapper around the [`BlobFetcher`] that caches
8+
blobs in an in-memory cache. It is used to avoid fetching the same blob and to
9+
manage retry logic during fetching.
10+
711
## Data Sources
812

913
The following sources can be configured:

crates/blobber/src/builder.rs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::{BlockExtractorConfig, block_data::BlockExtractor};
1+
use crate::{BlobCacher, BlobFetcher, BlobFetcherConfig};
22
use init4_bin_base::utils::calc::SlotCalculator;
33
use reth::transaction_pool::TransactionPool;
44
use url::Url;
55

6-
/// Errors that can occur while building the [`BlockExtractor`] with a
7-
/// [`BlockExtractorBuilder`].
6+
/// Errors that can occur while building the [`BlobFetcher`] with a
7+
/// [`BlobFetcherBuilder`].
88
#[derive(Debug, thiserror::Error)]
99
pub enum BuilderError {
1010
/// The transaction pool was not provided.
@@ -27,9 +27,9 @@ pub enum BuilderError {
2727
MissingSlotCalculator,
2828
}
2929

30-
/// Builder for the [`BlockExtractor`].
30+
/// Builder for the [`BlobFetcher`].
3131
#[derive(Debug, Default, Clone)]
32-
pub struct BlockExtractorBuilder<Pool> {
32+
pub struct BlobFetcherBuilder<Pool> {
3333
pool: Option<Pool>,
3434
explorer_url: Option<String>,
3535
client: Option<reqwest::Client>,
@@ -38,10 +38,10 @@ pub struct BlockExtractorBuilder<Pool> {
3838
slot_calculator: Option<SlotCalculator>,
3939
}
4040

41-
impl<Pool> BlockExtractorBuilder<Pool> {
41+
impl<Pool> BlobFetcherBuilder<Pool> {
4242
/// Set the transaction pool to use for the extractor.
43-
pub fn with_pool<P2>(self, pool: P2) -> BlockExtractorBuilder<P2> {
44-
BlockExtractorBuilder {
43+
pub fn with_pool<P2>(self, pool: P2) -> BlobFetcherBuilder<P2> {
44+
BlobFetcherBuilder {
4545
pool: Some(pool),
4646
explorer_url: self.explorer_url,
4747
client: self.client,
@@ -53,15 +53,13 @@ impl<Pool> BlockExtractorBuilder<Pool> {
5353

5454
/// Set the transaction pool to use a mock test pool.
5555
#[cfg(feature = "test-utils")]
56-
pub fn with_test_pool(
57-
self,
58-
) -> BlockExtractorBuilder<reth_transaction_pool::test_utils::TestPool> {
56+
pub fn with_test_pool(self) -> BlobFetcherBuilder<reth_transaction_pool::test_utils::TestPool> {
5957
self.with_pool(reth_transaction_pool::test_utils::testing_pool())
6058
}
6159

6260
/// Set the configuration for the CL url, pylon url, from the provided
63-
/// [`BlockExtractorConfig`].
64-
pub fn with_config(self, config: &BlockExtractorConfig) -> Result<Self, BuilderError> {
61+
/// [`BlobFetcherConfig`].
62+
pub fn with_config(self, config: &BlobFetcherConfig) -> Result<Self, BuilderError> {
6563
let this = self.with_explorer_url(config.blob_explorer_url());
6664
let this =
6765
if let Some(cl_url) = config.cl_url() { this.with_cl_url(cl_url)? } else { this };
@@ -114,22 +112,22 @@ impl<Pool> BlockExtractorBuilder<Pool> {
114112
pub const fn with_slot_calculator(
115113
mut self,
116114
slot_calculator: SlotCalculator,
117-
) -> BlockExtractorBuilder<Pool> {
115+
) -> BlobFetcherBuilder<Pool> {
118116
self.slot_calculator = Some(slot_calculator);
119117
self
120118
}
121119

122120
/// Set the slot calculator to use for the extractor, using the Pecornino
123121
/// host configuration.
124-
pub const fn with_pecornino_slots(mut self) -> BlockExtractorBuilder<Pool> {
122+
pub const fn with_pecornino_slots(mut self) -> BlobFetcherBuilder<Pool> {
125123
self.slot_calculator = Some(SlotCalculator::pecorino_host());
126124
self
127125
}
128126
}
129127

130-
impl<Pool: TransactionPool> BlockExtractorBuilder<Pool> {
131-
/// Build the [`BlockExtractor`] with the provided parameters.
132-
pub fn build(self) -> Result<BlockExtractor<Pool>, BuilderError> {
128+
impl<Pool: TransactionPool> BlobFetcherBuilder<Pool> {
129+
/// Build the [`BlobFetcher`] with the provided parameters.
130+
pub fn build(self) -> Result<BlobFetcher<Pool>, BuilderError> {
133131
let pool = self.pool.ok_or(BuilderError::MissingPool)?;
134132

135133
let explorer_url = self.explorer_url.ok_or(BuilderError::MissingExplorerUrl)?;
@@ -145,7 +143,16 @@ impl<Pool: TransactionPool> BlockExtractorBuilder<Pool> {
145143

146144
let slot_calculator = self.slot_calculator.ok_or(BuilderError::MissingSlotCalculator)?;
147145

148-
Ok(BlockExtractor::new(pool, explorer, client, cl_url, pylon_url, slot_calculator))
146+
Ok(BlobFetcher::new(pool, explorer, client, cl_url, pylon_url, slot_calculator))
147+
}
148+
149+
/// Build a [`BlobCacher`] with the provided parameters.
150+
pub fn build_cache(self) -> Result<BlobCacher<Pool>, BuilderError>
151+
where
152+
Pool: 'static,
153+
{
154+
let fetcher = self.build()?;
155+
Ok(BlobCacher::new(fetcher))
149156
}
150157
}
151158

0 commit comments

Comments
 (0)