signet-cold 0.7.2

Append-only cold storage for historical blockchain data
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
//! Ergonomic handles for interacting with cold storage.
//!
//! This module provides two handle types:
//!
//! - [`ColdStorageHandle`]: Full access (reads and writes)
//! - [`ColdStorageReadHandle`]: Read-only access
//!
//! Both handles can be cloned and shared across tasks. They use separate
//! channels for reads and writes, allowing concurrent read processing while
//! maintaining sequential write ordering.

use crate::{
    AppendBlockRequest, BlockData, ColdReadRequest, ColdReceipt, ColdResult, ColdStorageError,
    ColdWriteRequest, Confirmed, Filter, HeaderSpecifier, LogStream, ReceiptSpecifier, RpcLog,
    SignetEventsSpecifier, TransactionSpecifier, ZenithHeaderSpecifier,
};
use alloy::primitives::{B256, BlockNumber};
use signet_storage_types::{DbSignetEvent, DbZenithHeader, RecoveredTx, SealedHeader};
use std::time::Duration;
use tokio::sync::{mpsc, oneshot};

/// Map a [`mpsc::error::TrySendError`] to the appropriate
/// [`ColdStorageError`] variant.
fn map_dispatch_error<T>(e: mpsc::error::TrySendError<T>) -> ColdStorageError {
    match e {
        mpsc::error::TrySendError::Full(_) => ColdStorageError::Backpressure,
        mpsc::error::TrySendError::Closed(_) => ColdStorageError::TaskTerminated,
    }
}

/// Read-only handle for interacting with the cold storage task.
///
/// This handle provides read access only and cannot perform write operations.
/// It shares the read channel with [`ColdStorageHandle`], allowing multiple
/// readers to coexist without affecting write throughput.
///
/// # Usage
///
/// Obtain a read handle via [`ColdStorageHandle::reader`]:
///
/// ```ignore
/// let handle = ColdStorageTask::spawn(backend, cancel);
/// let reader = handle.reader();
///
/// // Use reader for queries
/// let header = reader.get_header_by_number(100).await?;
/// ```
///
/// # Thread Safety
///
/// This handle is `Clone + Send + Sync` and can be shared across tasks.
/// Multiple readers can query concurrently without blocking writes.
#[derive(Clone, Debug)]
pub struct ColdStorageReadHandle {
    sender: mpsc::Sender<ColdReadRequest>,
}

impl ColdStorageReadHandle {
    /// Create a new read-only handle with the given sender.
    pub(crate) const fn new(sender: mpsc::Sender<ColdReadRequest>) -> Self {
        Self { sender }
    }

    /// Send a read request and wait for the response.
    async fn send<T>(
        &self,
        req: ColdReadRequest,
        rx: oneshot::Receiver<ColdResult<T>>,
    ) -> ColdResult<T> {
        self.sender.send(req).await.map_err(|_| ColdStorageError::Cancelled)?;
        rx.await.map_err(|_| ColdStorageError::Cancelled)?
    }

    // ==========================================================================
    // Headers
    // ==========================================================================

    /// Get a header by specifier.
    pub async fn get_header(&self, spec: HeaderSpecifier) -> ColdResult<Option<SealedHeader>> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetHeader { spec, resp }, rx).await
    }

    /// Get a header by block number.
    pub async fn get_header_by_number(
        &self,
        block: BlockNumber,
    ) -> ColdResult<Option<SealedHeader>> {
        self.get_header(HeaderSpecifier::Number(block)).await
    }

    /// Get a header by block hash.
    pub async fn get_header_by_hash(&self, hash: B256) -> ColdResult<Option<SealedHeader>> {
        self.get_header(HeaderSpecifier::Hash(hash)).await
    }

    /// Get multiple headers by specifiers.
    pub async fn get_headers(
        &self,
        specs: Vec<HeaderSpecifier>,
    ) -> ColdResult<Vec<Option<SealedHeader>>> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetHeaders { specs, resp }, rx).await
    }

    // ==========================================================================
    // Transactions
    // ==========================================================================

    /// Get a transaction by specifier, with block confirmation metadata.
    pub async fn get_transaction(
        &self,
        spec: TransactionSpecifier,
    ) -> ColdResult<Option<Confirmed<RecoveredTx>>> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetTransaction { spec, resp }, rx).await
    }

    /// Get a transaction by hash.
    pub async fn get_tx_by_hash(&self, hash: B256) -> ColdResult<Option<Confirmed<RecoveredTx>>> {
        self.get_transaction(TransactionSpecifier::Hash(hash)).await
    }

    /// Get a transaction by block number and index.
    pub async fn get_tx_by_block_and_index(
        &self,
        block: BlockNumber,
        index: u64,
    ) -> ColdResult<Option<Confirmed<RecoveredTx>>> {
        self.get_transaction(TransactionSpecifier::BlockAndIndex { block, index }).await
    }

    /// Get a transaction by block hash and index.
    pub async fn get_tx_by_block_hash_and_index(
        &self,
        block_hash: B256,
        index: u64,
    ) -> ColdResult<Option<Confirmed<RecoveredTx>>> {
        self.get_transaction(TransactionSpecifier::BlockHashAndIndex { block_hash, index }).await
    }

    /// Get all transactions in a block.
    pub async fn get_transactions_in_block(
        &self,
        block: BlockNumber,
    ) -> ColdResult<Vec<RecoveredTx>> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetTransactionsInBlock { block, resp }, rx).await
    }

    /// Get the transaction count for a block.
    pub async fn get_transaction_count(&self, block: BlockNumber) -> ColdResult<u64> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetTransactionCount { block, resp }, rx).await
    }

    // ==========================================================================
    // Receipts
    // ==========================================================================

    /// Get a receipt by specifier.
    pub async fn get_receipt(&self, spec: ReceiptSpecifier) -> ColdResult<Option<ColdReceipt>> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetReceipt { spec, resp }, rx).await
    }

    /// Get a receipt by transaction hash.
    pub async fn get_receipt_by_tx_hash(&self, hash: B256) -> ColdResult<Option<ColdReceipt>> {
        self.get_receipt(ReceiptSpecifier::TxHash(hash)).await
    }

    /// Get a receipt by block number and index.
    pub async fn get_receipt_by_block_and_index(
        &self,
        block: BlockNumber,
        index: u64,
    ) -> ColdResult<Option<ColdReceipt>> {
        self.get_receipt(ReceiptSpecifier::BlockAndIndex { block, index }).await
    }

    /// Get all receipts in a block.
    pub async fn get_receipts_in_block(&self, block: BlockNumber) -> ColdResult<Vec<ColdReceipt>> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetReceiptsInBlock { block, resp }, rx).await
    }

    // ==========================================================================
    // SignetEvents
    // ==========================================================================

    /// Get signet events by specifier.
    pub async fn get_signet_events(
        &self,
        spec: SignetEventsSpecifier,
    ) -> ColdResult<Vec<DbSignetEvent>> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetSignetEvents { spec, resp }, rx).await
    }

    /// Get signet events in a block.
    pub async fn get_signet_events_in_block(
        &self,
        block: BlockNumber,
    ) -> ColdResult<Vec<DbSignetEvent>> {
        self.get_signet_events(SignetEventsSpecifier::Block(block)).await
    }

    /// Get signet events in a range of blocks.
    pub async fn get_signet_events_in_range(
        &self,
        start: BlockNumber,
        end: BlockNumber,
    ) -> ColdResult<Vec<DbSignetEvent>> {
        self.get_signet_events(SignetEventsSpecifier::BlockRange { start, end }).await
    }

    // ==========================================================================
    // ZenithHeaders
    // ==========================================================================

    /// Get a zenith header by block number.
    pub async fn get_zenith_header(
        &self,
        block: BlockNumber,
    ) -> ColdResult<Option<DbZenithHeader>> {
        let (resp, rx) = oneshot::channel();
        self.send(
            ColdReadRequest::GetZenithHeader { spec: ZenithHeaderSpecifier::Number(block), resp },
            rx,
        )
        .await
    }

    /// Get zenith headers by specifier.
    pub async fn get_zenith_headers(
        &self,
        spec: ZenithHeaderSpecifier,
    ) -> ColdResult<Vec<DbZenithHeader>> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetZenithHeaders { spec, resp }, rx).await
    }

    /// Get zenith headers in a range of blocks.
    pub async fn get_zenith_headers_in_range(
        &self,
        start: BlockNumber,
        end: BlockNumber,
    ) -> ColdResult<Vec<DbZenithHeader>> {
        self.get_zenith_headers(ZenithHeaderSpecifier::Range { start, end }).await
    }

    // ==========================================================================
    // Logs
    // ==========================================================================

    /// Filter logs by block range, address, and topics.
    ///
    /// Follows `eth_getLogs` semantics. Returns matching logs ordered by
    /// `(block_number, tx_index, log_index)`.
    ///
    /// # Errors
    ///
    /// Returns [`ColdStorageError::TooManyLogs`] if the query would produce
    /// more than `max_logs` results.
    pub async fn get_logs(&self, filter: Filter, max_logs: usize) -> ColdResult<Vec<RpcLog>> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetLogs { filter: Box::new(filter), max_logs, resp }, rx).await
    }

    /// Stream logs matching a filter.
    ///
    /// Returns a [`LogStream`] that yields matching logs in order.
    /// Consume with `StreamExt::next()` until `None`. If the last item
    /// is `Err(...)`, an error occurred (deadline, too many logs, etc.).
    ///
    /// The `deadline` is clamped to the task's configured maximum.
    ///
    /// # Partial Delivery
    ///
    /// One or more `Ok(log)` items may be delivered before a terminal
    /// `Err(...)`. Consumers must be prepared for partial results — for
    /// example, a reorg or deadline expiry can interrupt a stream that
    /// has already yielded some logs.
    ///
    /// # Resource Management
    ///
    /// The stream holds a backend concurrency permit. Dropping the
    /// stream releases the permit. Drop early if results are no
    /// longer needed.
    pub async fn stream_logs(
        &self,
        filter: Filter,
        max_logs: usize,
        deadline: Duration,
    ) -> ColdResult<LogStream> {
        let (resp, rx) = oneshot::channel();
        self.send(
            ColdReadRequest::StreamLogs { filter: Box::new(filter), max_logs, deadline, resp },
            rx,
        )
        .await
    }

    // ==========================================================================
    // Metadata
    // ==========================================================================

    /// Get the latest block number in storage.
    pub async fn get_latest_block(&self) -> ColdResult<Option<BlockNumber>> {
        let (resp, rx) = oneshot::channel();
        self.send(ColdReadRequest::GetLatestBlock { resp }, rx).await
    }
}

/// Handle for interacting with the cold storage task.
///
/// This handle provides full access to both read and write operations.
/// It can be cloned and shared across tasks.
///
/// # Channel Separation
///
/// Internally, this handle uses separate channels for reads and writes:
///
/// - **Read channel**: Shared with [`ColdStorageReadHandle`]. Reads are
///   processed concurrently (up to 64 in flight).
/// - **Write channel**: Exclusive to this handle. Writes are processed
///   sequentially to maintain ordering.
///
/// This design allows read-heavy workloads to proceed without being blocked
/// by write operations, while ensuring write ordering is preserved.
///
/// # Read Access
///
/// All read methods from [`ColdStorageReadHandle`] are also available
/// directly on this handle.
///
/// # Usage
///
/// ```ignore
/// let handle = ColdStorageTask::spawn(backend, cancel);
///
/// // Full access: reads and writes
/// handle.append_block(data).await?;
/// let header = handle.get_header_by_number(100).await?;
///
/// // Get a read-only handle for query-only use cases
/// let reader = handle.reader();
/// ```
///
/// # Thread Safety
///
/// This handle is `Clone + Send + Sync` and can be shared across tasks.
#[derive(Clone, Debug)]
pub struct ColdStorageHandle {
    reader: ColdStorageReadHandle,
    write_sender: mpsc::Sender<ColdWriteRequest>,
}

impl ColdStorageHandle {
    /// Create a new handle with the given senders.
    pub(crate) const fn new(
        read_sender: mpsc::Sender<ColdReadRequest>,
        write_sender: mpsc::Sender<ColdWriteRequest>,
    ) -> Self {
        Self { reader: ColdStorageReadHandle::new(read_sender), write_sender }
    }

    /// Get a read-only handle that shares the read channel.
    ///
    /// The returned handle can only perform read operations and cannot
    /// modify storage. Multiple read handles can coexist and query
    /// concurrently without affecting write throughput.
    pub fn reader(&self) -> ColdStorageReadHandle {
        self.reader.clone()
    }

    /// Send a write request and wait for the response.
    async fn send_write<T>(
        &self,
        req: ColdWriteRequest,
        rx: oneshot::Receiver<ColdResult<T>>,
    ) -> ColdResult<T> {
        self.write_sender.send(req).await.map_err(|_| ColdStorageError::Cancelled)?;
        rx.await.map_err(|_| ColdStorageError::Cancelled)?
    }

    // ==========================================================================
    // Write Operations
    // ==========================================================================

    /// Append a single block to cold storage.
    pub async fn append_block(&self, data: BlockData) -> ColdResult<()> {
        let (resp, rx) = oneshot::channel();
        self.send_write(
            ColdWriteRequest::AppendBlock(Box::new(AppendBlockRequest { data, resp })),
            rx,
        )
        .await
    }

    /// Append multiple blocks to cold storage.
    pub async fn append_blocks(&self, data: Vec<BlockData>) -> ColdResult<()> {
        let (resp, rx) = oneshot::channel();
        self.send_write(ColdWriteRequest::AppendBlocks { data, resp }, rx).await
    }

    /// Truncate all data above the given block number.
    ///
    /// This removes block N+1 and higher from all tables.
    pub async fn truncate_above(&self, block: BlockNumber) -> ColdResult<()> {
        let (resp, rx) = oneshot::channel();
        self.send_write(ColdWriteRequest::TruncateAbove { block, resp }, rx).await
    }

    // ==========================================================================
    // Synchronous Fire-and-Forget Dispatch
    // ==========================================================================

    /// Dispatch append blocks without waiting for response (non-blocking).
    ///
    /// Unlike [`append_blocks`](Self::append_blocks), this method returns
    /// immediately without waiting for the write to complete. The write
    /// result is discarded.
    ///
    /// # Errors
    ///
    /// - [`ColdStorageError::Backpressure`]: Channel is full. The task is alive
    ///   but cannot keep up. Transient; may retry or accept the gap.
    /// - [`ColdStorageError::TaskTerminated`]: Channel is closed. The task has
    ///   stopped and must be restarted.
    ///
    /// In both cases, hot storage already contains the data and remains
    /// authoritative.
    pub fn dispatch_append_blocks(&self, data: Vec<BlockData>) -> ColdResult<()> {
        let (resp, _rx) = oneshot::channel();
        self.write_sender
            .try_send(ColdWriteRequest::AppendBlocks { data, resp })
            .map_err(map_dispatch_error)
    }

    /// Read and remove all blocks above the given block number.
    ///
    /// Returns receipts for each block above `block` in ascending order,
    /// then truncates. Index 0 = block+1, index 1 = block+2, etc.
    pub async fn drain_above(&self, block: BlockNumber) -> ColdResult<Vec<Vec<ColdReceipt>>> {
        let (resp, rx) = oneshot::channel();
        self.send_write(ColdWriteRequest::DrainAbove { block, resp }, rx).await
    }

    /// Dispatch truncate without waiting for response (non-blocking).
    ///
    /// Unlike [`truncate_above`](Self::truncate_above), this method returns
    /// immediately without waiting for the truncate to complete. The result
    /// is discarded.
    ///
    /// # Errors
    ///
    /// Same as [`dispatch_append_blocks`](Self::dispatch_append_blocks). If
    /// cold storage falls behind during a reorg, it may temporarily contain
    /// stale data until the truncate is processed or replayed.
    pub fn dispatch_truncate_above(&self, block: BlockNumber) -> ColdResult<()> {
        let (resp, _rx) = oneshot::channel();
        self.write_sender
            .try_send(ColdWriteRequest::TruncateAbove { block, resp })
            .map_err(map_dispatch_error)
    }

    // ==========================================================================
    // Read Operations (delegated to ColdStorageReadHandle)
    // ==========================================================================

    /// Get a header by specifier.
    pub async fn get_header(&self, spec: HeaderSpecifier) -> ColdResult<Option<SealedHeader>> {
        self.reader.get_header(spec).await
    }

    /// Get a header by block number.
    pub async fn get_header_by_number(
        &self,
        block: BlockNumber,
    ) -> ColdResult<Option<SealedHeader>> {
        self.reader.get_header_by_number(block).await
    }

    /// Get a header by block hash.
    pub async fn get_header_by_hash(&self, hash: B256) -> ColdResult<Option<SealedHeader>> {
        self.reader.get_header_by_hash(hash).await
    }

    /// Get multiple headers by specifiers.
    pub async fn get_headers(
        &self,
        specs: Vec<HeaderSpecifier>,
    ) -> ColdResult<Vec<Option<SealedHeader>>> {
        self.reader.get_headers(specs).await
    }

    /// Get a transaction by specifier, with block confirmation metadata.
    pub async fn get_transaction(
        &self,
        spec: TransactionSpecifier,
    ) -> ColdResult<Option<Confirmed<RecoveredTx>>> {
        self.reader.get_transaction(spec).await
    }

    /// Get a transaction by hash.
    pub async fn get_tx_by_hash(&self, hash: B256) -> ColdResult<Option<Confirmed<RecoveredTx>>> {
        self.reader.get_tx_by_hash(hash).await
    }

    /// Get a transaction by block number and index.
    pub async fn get_tx_by_block_and_index(
        &self,
        block: BlockNumber,
        index: u64,
    ) -> ColdResult<Option<Confirmed<RecoveredTx>>> {
        self.reader.get_tx_by_block_and_index(block, index).await
    }

    /// Get a transaction by block hash and index.
    pub async fn get_tx_by_block_hash_and_index(
        &self,
        block_hash: B256,
        index: u64,
    ) -> ColdResult<Option<Confirmed<RecoveredTx>>> {
        self.reader.get_tx_by_block_hash_and_index(block_hash, index).await
    }

    /// Get all transactions in a block.
    pub async fn get_transactions_in_block(
        &self,
        block: BlockNumber,
    ) -> ColdResult<Vec<RecoveredTx>> {
        self.reader.get_transactions_in_block(block).await
    }

    /// Get the transaction count for a block.
    pub async fn get_transaction_count(&self, block: BlockNumber) -> ColdResult<u64> {
        self.reader.get_transaction_count(block).await
    }

    /// Get a receipt by specifier.
    pub async fn get_receipt(&self, spec: ReceiptSpecifier) -> ColdResult<Option<ColdReceipt>> {
        self.reader.get_receipt(spec).await
    }

    /// Get a receipt by transaction hash.
    pub async fn get_receipt_by_tx_hash(&self, hash: B256) -> ColdResult<Option<ColdReceipt>> {
        self.reader.get_receipt_by_tx_hash(hash).await
    }

    /// Get a receipt by block number and index.
    pub async fn get_receipt_by_block_and_index(
        &self,
        block: BlockNumber,
        index: u64,
    ) -> ColdResult<Option<ColdReceipt>> {
        self.reader.get_receipt_by_block_and_index(block, index).await
    }

    /// Get all receipts in a block.
    pub async fn get_receipts_in_block(&self, block: BlockNumber) -> ColdResult<Vec<ColdReceipt>> {
        self.reader.get_receipts_in_block(block).await
    }

    /// Get signet events by specifier.
    pub async fn get_signet_events(
        &self,
        spec: SignetEventsSpecifier,
    ) -> ColdResult<Vec<DbSignetEvent>> {
        self.reader.get_signet_events(spec).await
    }

    /// Get signet events in a block.
    pub async fn get_signet_events_in_block(
        &self,
        block: BlockNumber,
    ) -> ColdResult<Vec<DbSignetEvent>> {
        self.reader.get_signet_events_in_block(block).await
    }

    /// Get signet events in a range of blocks.
    pub async fn get_signet_events_in_range(
        &self,
        start: BlockNumber,
        end: BlockNumber,
    ) -> ColdResult<Vec<DbSignetEvent>> {
        self.reader.get_signet_events_in_range(start, end).await
    }

    /// Get a zenith header by block number.
    pub async fn get_zenith_header(
        &self,
        block: BlockNumber,
    ) -> ColdResult<Option<DbZenithHeader>> {
        self.reader.get_zenith_header(block).await
    }

    /// Get zenith headers by specifier.
    pub async fn get_zenith_headers(
        &self,
        spec: ZenithHeaderSpecifier,
    ) -> ColdResult<Vec<DbZenithHeader>> {
        self.reader.get_zenith_headers(spec).await
    }

    /// Get zenith headers in a range of blocks.
    pub async fn get_zenith_headers_in_range(
        &self,
        start: BlockNumber,
        end: BlockNumber,
    ) -> ColdResult<Vec<DbZenithHeader>> {
        self.reader.get_zenith_headers_in_range(start, end).await
    }

    /// Filter logs by block range, address, and topics.
    ///
    /// Follows `eth_getLogs` semantics. Returns matching logs ordered by
    /// `(block_number, tx_index, log_index)`.
    ///
    /// # Errors
    ///
    /// Returns [`ColdStorageError::TooManyLogs`] if the query would produce
    /// more than `max_logs` results.
    pub async fn get_logs(&self, filter: Filter, max_logs: usize) -> ColdResult<Vec<RpcLog>> {
        self.reader.get_logs(filter, max_logs).await
    }

    /// Stream logs matching a filter.
    ///
    /// See [`ColdStorageReadHandle::stream_logs`] for full documentation.
    pub async fn stream_logs(
        &self,
        filter: Filter,
        max_logs: usize,
        deadline: Duration,
    ) -> ColdResult<LogStream> {
        self.reader.stream_logs(filter, max_logs, deadline).await
    }

    /// Get the latest block number in storage.
    pub async fn get_latest_block(&self) -> ColdResult<Option<BlockNumber>> {
        self.reader.get_latest_block().await
    }
}