ee5b55fab6
* Feature/ephemera compile (#3437) * Include ephemera node code in repo * Upgrade deps * Bump minor version of cosmwasm-std * Include ephemera in nym-api dep and downgrade rusqlite * Fix clippy and ephemera docs code * More clippy on ephemera --------- Co-authored-by: Andrus Salumets <andrus@nymtech.net> * Start ephemera components in nym-api (#3475) * Start ephemera components in nym-api * Pass nyxd client and use common metric structures * Swap url endpoint with contract for sending rewarding messages * Fix build after rebase * Perform ephemera rewards computation before normal nym-api ones * Remove contract mock from ephemera * Take raw rewards from network monitor * Remove ephemera old reward version * Use nym shutdown procedure in ephemera * Temporary fix for some warnings * Umock contract membership of ephemera (#3574) * Pass nyxd client to members provider * Basic ephemera contract * Add register peer tx * Add query all peers * Nyxd ephemera client * Add registration of ephemera peer * Replace epoch http api with actual contract * Merge ephemera config into nym-api config * Load cluster from contract * Guard nym-outfox out of cosmwasm builds (#3650) * Feature/fixes while testing (#3668) * Commit local peer before querying contract * Default to anyonline * Remove string from template * Fix avg computing * Use updated qa env * Fix clippy * Add unit tests for ephemera contract * Upload ephemera contract in CI * Add group check for peer signup * Peer registration unit test * Start ephemera only on monitoring * Remove old MixnodeToReward struct * Move all ephemera config to its file * Skip with serde ephemera config * Fix default value in args * Feature/add ephemera flag (#3727) * Replace unwrap with error handling * Add ephemera enable flag * Fix template * Add json schema to ephemera contract (#3735) * Update lock files * Update changelog --------- Co-authored-by: Andrus Salumets <andrus@nymtech.net>
66 lines
1.9 KiB
Rust
66 lines
1.9 KiB
Rust
//! # Database
|
|
//!
|
|
//! It supports `SqlLite` and `RocksDB`.
|
|
//!
|
|
//! ## `RocksDB`
|
|
//!
|
|
//! `SqlLite` is used by default.
|
|
//!
|
|
//! ## `SqlLite`
|
|
//!
|
|
//! To use `SqlLite`, you need to compile with the `sqlite_storage` feature and with `--no-default-features` flag.
|
|
|
|
use std::collections::HashSet;
|
|
|
|
use thiserror::Error;
|
|
|
|
use crate::block::types::block::Block;
|
|
use crate::peer::PeerId;
|
|
use crate::utilities::crypto::Certificate;
|
|
use crate::utilities::merkle::MerkleTree;
|
|
|
|
#[cfg(feature = "rocksdb_storage")]
|
|
pub(crate) mod rocksdb;
|
|
|
|
#[cfg(feature = "sqlite_storage")]
|
|
pub(crate) mod sqlite;
|
|
|
|
pub(crate) type Result<T> = std::result::Result<T, DatabaseError>;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub(crate) enum DatabaseError {
|
|
//Pessimistically assume that most database errors are fatal and unrecoverable.
|
|
#[error("Database failure: {0}")]
|
|
DatabaseFailure(#[from] anyhow::Error),
|
|
}
|
|
|
|
pub(crate) trait EphemeraDatabase: Send {
|
|
/// Returns block by its id. Block ids are generated by Ephemera
|
|
fn get_block_by_hash(&self, block_hash: &str) -> Result<Option<Block>>;
|
|
|
|
/// Returns last committed/finalised block.
|
|
fn get_last_block(&self) -> Result<Option<Block>>;
|
|
|
|
/// Returns block by its height
|
|
fn get_block_by_height(&self, height: u64) -> Result<Option<Block>>;
|
|
|
|
/// Returns block certificates.
|
|
///
|
|
/// Certificates were created as part of broadcast protocol and signed by peers who participated.
|
|
fn get_block_certificates(&self, block_hash: &str) -> Result<Option<Vec<Certificate>>>;
|
|
|
|
/// Returns peers who participated in block broadcast.
|
|
fn get_block_broadcast_group(&self, block_hash: &str) -> Result<Option<Vec<PeerId>>>;
|
|
|
|
/// Stores block and its signatures
|
|
fn store_block(
|
|
&mut self,
|
|
block: &Block,
|
|
certificates: HashSet<Certificate>,
|
|
members: HashSet<PeerId>,
|
|
) -> Result<()>;
|
|
|
|
/// Returns block merkle tree
|
|
fn get_block_merkle_tree(&self, block_hash: &str) -> Result<Option<MerkleTree>>;
|
|
}
|