Skip to main content

signet_cold/
request.rs

1//! Request and response types for the cold storage task.
2//!
3//! These types define the messages sent over channels to the cold storage task.
4//! Reads and writes use separate channels with their own request types.
5
6use crate::{
7    BlockData, ColdReceipt, ColdStorageError, Confirmed, Filter, HeaderSpecifier, LogStream,
8    ReceiptSpecifier, RpcLog, SignetEventsSpecifier, TransactionSpecifier, ZenithHeaderSpecifier,
9};
10use alloy::primitives::BlockNumber;
11use signet_storage_types::{DbSignetEvent, DbZenithHeader, RecoveredTx, SealedHeader};
12use std::time::Duration;
13use tokio::sync::oneshot;
14
15/// Response sender type alias that propagates Result types.
16pub type Responder<T, E = ColdStorageError> = oneshot::Sender<Result<T, E>>;
17
18/// Block append request data (wrapper struct).
19#[derive(Debug)]
20pub struct AppendBlockRequest {
21    /// The block data to append.
22    pub data: BlockData,
23    /// The response channel.
24    pub resp: Responder<()>,
25}
26
27/// Read requests for cold storage.
28///
29/// These requests are processed concurrently (up to 64 in flight).
30#[derive(Debug)]
31pub enum ColdReadRequest {
32    // --- Headers ---
33    /// Get a single header by specifier.
34    GetHeader {
35        /// The header specifier.
36        spec: HeaderSpecifier,
37        /// The response channel.
38        resp: Responder<Option<SealedHeader>>,
39    },
40    /// Get multiple headers by specifiers.
41    GetHeaders {
42        /// The header specifiers.
43        specs: Vec<HeaderSpecifier>,
44        /// The response channel.
45        resp: Responder<Vec<Option<SealedHeader>>>,
46    },
47
48    // --- Transactions ---
49    /// Get a single transaction by specifier.
50    GetTransaction {
51        /// The transaction specifier.
52        spec: TransactionSpecifier,
53        /// The response channel.
54        resp: Responder<Option<Confirmed<RecoveredTx>>>,
55    },
56    /// Get all transactions in a block.
57    GetTransactionsInBlock {
58        /// The block number.
59        block: BlockNumber,
60        /// The response channel.
61        resp: Responder<Vec<RecoveredTx>>,
62    },
63    /// Get the transaction count for a block.
64    GetTransactionCount {
65        /// The block number.
66        block: BlockNumber,
67        /// The response channel.
68        resp: Responder<u64>,
69    },
70
71    // --- Receipts ---
72    /// Get a single receipt by specifier.
73    GetReceipt {
74        /// The receipt specifier.
75        spec: ReceiptSpecifier,
76        /// The response channel.
77        resp: Responder<Option<ColdReceipt>>,
78    },
79    /// Get all receipts in a block.
80    GetReceiptsInBlock {
81        /// The block number.
82        block: BlockNumber,
83        /// The response channel.
84        resp: Responder<Vec<ColdReceipt>>,
85    },
86
87    // --- SignetEvents ---
88    /// Get signet events by specifier.
89    GetSignetEvents {
90        /// The signet events specifier.
91        spec: SignetEventsSpecifier,
92        /// The response channel.
93        resp: Responder<Vec<DbSignetEvent>>,
94    },
95
96    // --- ZenithHeaders ---
97    /// Get a single zenith header by specifier.
98    GetZenithHeader {
99        /// The zenith header specifier.
100        spec: ZenithHeaderSpecifier,
101        /// The response channel.
102        resp: Responder<Option<DbZenithHeader>>,
103    },
104    /// Get multiple zenith headers by specifier.
105    GetZenithHeaders {
106        /// The zenith header specifier.
107        spec: ZenithHeaderSpecifier,
108        /// The response channel.
109        resp: Responder<Vec<DbZenithHeader>>,
110    },
111
112    // --- Logs ---
113    /// Filter logs by block range, address, and topics.
114    GetLogs {
115        /// The log filter.
116        filter: Box<Filter>,
117        /// Maximum number of logs to return.
118        max_logs: usize,
119        /// The response channel.
120        resp: Responder<Vec<RpcLog>>,
121    },
122    /// Stream logs matching a filter.
123    StreamLogs {
124        /// The log filter.
125        filter: Box<Filter>,
126        /// Maximum number of logs to stream.
127        max_logs: usize,
128        /// Requested stream deadline (clamped to the task's max).
129        deadline: Duration,
130        /// Response channel returning the log stream.
131        resp: Responder<LogStream>,
132    },
133
134    // --- Metadata ---
135    /// Get the latest block number.
136    GetLatestBlock {
137        /// The response channel.
138        resp: Responder<Option<BlockNumber>>,
139    },
140}
141
142/// Write requests for cold storage.
143///
144/// These requests are processed sequentially to maintain ordering.
145#[derive(Debug)]
146pub enum ColdWriteRequest {
147    /// Append a single block.
148    AppendBlock(Box<AppendBlockRequest>),
149    /// Append multiple blocks.
150    AppendBlocks {
151        /// The block data to append.
152        data: Vec<BlockData>,
153        /// The response channel.
154        resp: Responder<()>,
155    },
156    /// Truncate all data above the given block.
157    TruncateAbove {
158        /// The block number to truncate above.
159        block: BlockNumber,
160        /// The response channel.
161        resp: Responder<()>,
162    },
163}