Skip to main content

witness_store/
lib.rs

1//! Storage for the validation archive.
2//!
3//! The archive is written in segments. The current segment is an append-only
4//! journal. A closed segment is compressed and gets a seal that includes the
5//! hash of the previous seal, so a segment cannot be replaced or dropped from
6//! the middle without it showing.
7//!
8//! We store the original: the raw signed validation exactly as the network
9//! sent it, plus the receive time and the ledger index for navigation.
10//! Everything else is derived from the original.
11
12pub mod journal;
13pub mod record;
14pub mod seal;
15pub mod segment;
16
17pub use record::Record;
18pub use seal::Seal;
19pub use segment::{SegmentConfig, SegmentWriter};
20
21/// Storage errors.
22#[derive(Debug)]
23pub enum Error {
24    Io(std::io::Error),
25    Json(serde_json::Error),
26    /// The file is not in our format, or is damaged where damage is not tolerated.
27    Format(String),
28}
29
30impl std::fmt::Display for Error {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        match self {
33            Error::Io(e) => write!(f, "i/o: {e}"),
34            Error::Json(e) => write!(f, "json: {e}"),
35            Error::Format(e) => write!(f, "format: {e}"),
36        }
37    }
38}
39
40impl std::error::Error for Error {}
41
42impl From<std::io::Error> for Error {
43    fn from(e: std::io::Error) -> Self {
44        Error::Io(e)
45    }
46}
47
48impl From<serde_json::Error> for Error {
49    fn from(e: serde_json::Error) -> Self {
50        Error::Json(e)
51    }
52}
53
54pub type Result<T> = std::result::Result<T, Error>;