vls_frontend/external_persist/
mod.rs

1//! see lss.proto in lightning_storage_server for more details
2
3pub mod lss;
4
5use async_trait::async_trait;
6use bitcoin::secp256k1::PublicKey;
7use lightning_signer::bitcoin;
8use lightning_signer::persist::Mutations;
9use std::fmt::Display;
10
11#[derive(Debug)]
12pub enum Error {
13    /// There was a put conflict for one or more keys
14    Conflicts(Vec<(String, u64)>),
15    /// There is no consensus among the quorum of backend servers
16    NoConsensus,
17    /// A quorum could not be reached or returned an error
18    NotAvailable,
19    /// Client was not authorized (e.g. HMAC was invalid)
20    NotAuthorized,
21}
22
23impl Display for Error {
24    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
25        core::fmt::Debug::fmt(self, f)
26    }
27}
28
29impl std::error::Error for Error {}
30
31pub struct Auth {
32    pub client_id: PublicKey,
33    pub token: Vec<u8>,
34}
35
36/// External persister information
37pub struct Info {
38    /// The version
39    pub version: String,
40    /// The persister's public key (for calculating HMACs)
41    pub pubkey: PublicKey,
42}
43
44/// External persister.
45///
46/// This trait is used to store the mutations in one or more external storage
47/// backends. The backend can be, for example, an LSS implementation (see
48/// lightning-storage-server).
49#[async_trait]
50pub trait ExternalPersist: Send + Sync {
51    /// Store the mutations.
52    ///
53    /// Returns the server hmac, proving that the mutation was persisted.
54    async fn put(&self, mutations: Mutations, client_hmac: &[u8]) -> Result<Vec<u8>, Error>;
55
56    /// Get the full state.
57    ///
58    /// In the future, there will be multiple server support, and if there is no
59    /// consensus among the servers, an error will be returned.
60    async fn get(&self, key_prefix: String, nonce: &[u8]) -> Result<(Mutations, Vec<u8>), Error>;
61
62    /// Return server information, including public key and version.
63    async fn info(&self) -> Result<Info, Error>;
64}