|
1 | | -//! Sled-based proof storage. |
2 | | -
|
3 | | -use std::fmt::Debug; |
4 | | - |
5 | | -use strata_asm_proof_types::{AsmProof, L1Range, MohoProof, ProofId, RemoteProofId}; |
6 | | -use strata_identifiers::L1BlockCommitment; |
7 | | -use zkaleido::RemoteProofStatus; |
8 | | - |
| 1 | +//! Persistence layer for ASM and Moho proofs. |
| 2 | +//! |
| 3 | +//! This crate defines three storage traits that together cover the full |
| 4 | +//! lifecycle of a proof — from submission to a remote prover, through status |
| 5 | +//! tracking, to final local storage: |
| 6 | +//! |
| 7 | +//! - [`ProofDb`] — stores and retrieves finalised ASM step proofs and Moho recursive proofs, keyed |
| 8 | +//! by their L1 block range or commitment. |
| 9 | +//! - [`RemoteProofMappingDb`] — maintains a bidirectional mapping between local |
| 10 | +//! [`ProofId`](strata_asm_proof_types::ProofId)s and opaque |
| 11 | +//! [`RemoteProofId`](strata_asm_proof_types::RemoteProofId)s assigned by the remote prover |
| 12 | +//! service. |
| 13 | +//! - [`RemoteProofStatusDb`] — tracks the execution status of in-flight remote proof jobs until |
| 14 | +//! their results are retrieved and stored locally. |
| 15 | +//! |
| 16 | +//! A sled-backed implementation ([`SledProofDb`]) is provided out of the box. |
| 17 | +
|
| 18 | +mod proof_db; |
| 19 | +mod remote_mapping; |
| 20 | +mod remote_status; |
9 | 21 | mod sled; |
10 | 22 |
|
11 | | -pub use self::sled::{RemoteProofMappingError, RemoteProofStatusError, SledProofDb}; |
12 | | - |
13 | | -/// Persistence interface for proof storage. |
14 | | -pub trait ProofDb { |
15 | | - /// The error type returned by the database operations. |
16 | | - type Error: Debug; |
17 | | - |
18 | | - /// Stores an ASM step proof for the given L1 range. |
19 | | - fn store_asm_proof( |
20 | | - &self, |
21 | | - range: L1Range, |
22 | | - proof: AsmProof, |
23 | | - ) -> impl Future<Output = Result<(), Self::Error>> + Send; |
24 | | - |
25 | | - /// Retrieves an ASM step proof for the given L1 range, if one exists. |
26 | | - fn get_asm_proof( |
27 | | - &self, |
28 | | - range: L1Range, |
29 | | - ) -> impl Future<Output = Result<Option<AsmProof>, Self::Error>> + Send; |
30 | | - |
31 | | - /// Stores a Moho recursive proof anchored at the given L1 block commitment. |
32 | | - fn store_moho_proof( |
33 | | - &self, |
34 | | - l1ref: L1BlockCommitment, |
35 | | - proof: MohoProof, |
36 | | - ) -> impl Future<Output = Result<(), Self::Error>> + Send; |
37 | | - |
38 | | - /// Retrieves a Moho proof for the given L1 block commitment, if one exists. |
39 | | - fn get_moho_proof( |
40 | | - &self, |
41 | | - l1ref: L1BlockCommitment, |
42 | | - ) -> impl Future<Output = Result<Option<MohoProof>, Self::Error>> + Send; |
43 | | - |
44 | | - /// Retrieves the latest (highest height) Moho proof and its L1 block commitment. |
45 | | - /// |
46 | | - /// Returns `None` if no Moho proofs have been stored yet. |
47 | | - /// |
48 | | - /// NOTE: Multiple proofs can exist at the same height (e.g. due to reorgs). |
49 | | - /// In that case, the returned entry is determined by the underlying key |
50 | | - /// ordering (height, then blkid bytes), which may be arbitrary. Callers that |
51 | | - /// need the proof for a specific canonical block should use |
52 | | - /// [`get_moho_proof`](Self::get_moho_proof) with the exact commitment. |
53 | | - fn get_latest_moho_proof( |
54 | | - &self, |
55 | | - ) -> impl Future<Output = Result<Option<(L1BlockCommitment, MohoProof)>, Self::Error>> + Send; |
56 | | - |
57 | | - /// Prunes all proofs (both ASM and Moho) for blocks before the given height. |
58 | | - /// |
59 | | - /// Deletes all entries with height strictly less than `before_height`. |
60 | | - fn prune(&self, before_height: u32) -> impl Future<Output = Result<(), Self::Error>> + Send; |
61 | | -} |
62 | | - |
63 | | -/// Persistent bidirectional mapping between local [`ProofId`]s and |
64 | | -/// [`RemoteProofId`]s assigned by the remote prover service. |
65 | | -/// |
66 | | -/// Used to prevent duplicate proof submissions and to recover the association |
67 | | -/// between local and remote identifiers after restarts. |
68 | | -pub trait RemoteProofMappingDb { |
69 | | - /// The error type returned by database operations. |
70 | | - type Error: Debug; |
71 | | - |
72 | | - /// Returns the remote proof ID associated with the given local proof ID, if one exists. |
73 | | - fn get_remote_proof_id( |
74 | | - &self, |
75 | | - id: ProofId, |
76 | | - ) -> impl Future<Output = Result<Option<RemoteProofId>, Self::Error>> + Send; |
77 | | - |
78 | | - /// Returns the local proof ID associated with the given remote proof ID, if one exists. |
79 | | - fn get_proof_id( |
80 | | - &self, |
81 | | - remote_id: &RemoteProofId, |
82 | | - ) -> impl Future<Output = Result<Option<ProofId>, Self::Error>> + Send; |
83 | | - |
84 | | - /// Stores a mapping between a local proof ID and a remote proof ID. |
85 | | - /// |
86 | | - /// A single [`ProofId`] may be associated with multiple [`RemoteProofId`]s |
87 | | - /// (e.g. when a proof is resubmitted), so calling this with the same |
88 | | - /// `id` but a different `remote_id` is allowed — only the forward lookup |
89 | | - /// (`ProofId → RemoteProofId`) is updated to point to the latest remote ID. |
90 | | - /// |
91 | | - /// However, a [`RemoteProofId`] must map to exactly one [`ProofId`]. |
92 | | - /// If `remote_id` is already associated with a **different** proof ID, |
93 | | - /// this method returns an error. |
94 | | - fn put_remote_proof_id( |
95 | | - &self, |
96 | | - id: ProofId, |
97 | | - remote_id: RemoteProofId, |
98 | | - ) -> impl Future<Output = Result<(), Self::Error>> + Send; |
99 | | -} |
100 | | - |
101 | | -/// Persistent store for the execution status of remote proof jobs. |
102 | | -/// |
103 | | -/// Tracks only proofs whose results have **not yet been retrieved and stored |
104 | | -/// locally**. Once a proof is stored via [`ProofDb`], the corresponding status |
105 | | -/// entry should be removed. |
106 | | -pub trait RemoteProofStatusDb { |
107 | | - /// The error type returned by database operations. |
108 | | - type Error: Debug; |
109 | | - |
110 | | - /// Inserts a new status entry for the given remote proof ID. |
111 | | - /// |
112 | | - /// Returns an error if an entry already exists for this ID. |
113 | | - fn put_status( |
114 | | - &self, |
115 | | - remote_id: &RemoteProofId, |
116 | | - status: RemoteProofStatus, |
117 | | - ) -> impl Future<Output = Result<(), Self::Error>> + Send; |
118 | | - |
119 | | - /// Updates the status of an existing remote proof entry. |
120 | | - /// |
121 | | - /// Returns an error if no entry exists for this ID. |
122 | | - fn update_status( |
123 | | - &self, |
124 | | - remote_id: &RemoteProofId, |
125 | | - status: RemoteProofStatus, |
126 | | - ) -> impl Future<Output = Result<(), Self::Error>> + Send; |
127 | | - |
128 | | - /// Returns the current status of the given remote proof, if tracked. |
129 | | - fn get_status( |
130 | | - &self, |
131 | | - remote_id: &RemoteProofId, |
132 | | - ) -> impl Future<Output = Result<Option<RemoteProofStatus>, Self::Error>> + Send; |
133 | | - |
134 | | - /// Returns all remote proofs that are currently active (i.e. `Requested` or `InProgress`). |
135 | | - fn get_all_in_progress( |
136 | | - &self, |
137 | | - ) -> impl Future<Output = Result<Vec<(RemoteProofId, RemoteProofStatus)>, Self::Error>> + Send; |
138 | | - |
139 | | - /// Removes the status entry for the given remote proof ID. |
140 | | - fn remove( |
141 | | - &self, |
142 | | - remote_id: &RemoteProofId, |
143 | | - ) -> impl Future<Output = Result<(), Self::Error>> + Send; |
144 | | -} |
| 23 | +pub use self::{ |
| 24 | + proof_db::ProofDb, |
| 25 | + remote_mapping::RemoteProofMappingDb, |
| 26 | + remote_status::RemoteProofStatusDb, |
| 27 | + sled::{RemoteProofMappingError, RemoteProofStatusError, SledProofDb}, |
| 28 | +}; |
0 commit comments