fuel_core_database/
lib.rs

1//! The crate `fuel-core-storage` contains storage types, primitives, tables used by `fuel-core`.
2//! This crate doesn't contain the actual implementation of the storage. It works around the
3//! `Database` and is used by services to provide a default implementation. Primitives
4//! defined here are used by services but are flexible enough to customize the
5//! logic when the `Database` is known.
6
7#![deny(clippy::arithmetic_side_effects)]
8#![deny(clippy::cast_possible_truncation)]
9#![deny(missing_docs)]
10#![deny(unused_crate_dependencies)]
11#![deny(warnings)]
12#![deny(unused_variables)]
13
14use fuel_core_storage::{
15    Error as StorageError,
16    transactional::ReferenceBytesKey,
17};
18use fuel_core_types::services::executor::Error as ExecutorError;
19
20/// The error occurred during work with any of databases.
21#[derive(Debug, derive_more::Display, derive_more::From)]
22#[non_exhaustive]
23#[allow(missing_docs)]
24pub enum Error {
25    /// Error occurred during serialization or deserialization of the entity.
26    #[display(fmt = "error performing serialization or deserialization")]
27    Codec,
28    /// The version of database or data is invalid (possibly not migrated).
29    #[display(fmt = "Invalid database version, expected {expected:#x}, found {found:#x}")]
30    InvalidDatabaseVersion {
31        /// the current database version
32        found: u32,
33        /// the database version expected by this build of fuel-core
34        expected: u32,
35    },
36    /// Multiple heights found in the commit to the database.
37    #[display(fmt = "Multiple heights found in the commit {heights:?}")]
38    MultipleHeightsInCommit {
39        /// List of heights found in the commit.
40        heights: Vec<u64>,
41    },
42    /// Failed to advance the height.
43    #[display(fmt = "Failed to advance the height")]
44    FailedToAdvanceHeight,
45    /// The new and old heights are not linked.
46    #[display(
47        fmt = "New and old heights are not linked: prev_height: {prev_height:#x}, new_height: {new_height:#x}"
48    )]
49    HeightsAreNotLinked {
50        /// The old height.
51        prev_height: u64,
52        /// The new height.
53        new_height: u64,
54    },
55    /// The new height is not found, but the old height is set.
56    #[display(
57        fmt = "The new height is not found, but the old height is set: prev_height: {prev_height:#x}"
58    )]
59    NewHeightIsNotSet {
60        /// The old height known by the database.
61        prev_height: u64,
62    },
63    #[display(
64        fmt = "The historical database doesn't have history for the requested height {requested_height:#x}"
65    )]
66    NoHistoryForRequestedHeight { requested_height: u64 },
67    #[display(fmt = "Reached the end of the history")]
68    ReachedEndOfHistory,
69
70    #[cfg(feature = "backup")]
71    #[display(fmt = "BackupEngine initialization error: {}", _0)]
72    BackupEngineInitError(anyhow::Error),
73
74    #[cfg(feature = "backup")]
75    #[display(fmt = "Backup error: {}", _0)]
76    BackupError(anyhow::Error),
77
78    #[cfg(feature = "backup")]
79    #[display(fmt = "Restore error: {}", _0)]
80    RestoreError(anyhow::Error),
81
82    #[display(fmt = "During committing of the changes found conflicting \
83        modifications at column {column} for the key {key:?}")]
84    ConflictingChanges { column: u32, key: ReferenceBytesKey },
85
86    /// Not related to database error.
87    #[from]
88    Other(anyhow::Error),
89}
90
91#[cfg(feature = "test-helpers")]
92impl PartialEq for Error {
93    fn eq(&self, other: &Self) -> bool {
94        self.to_string().eq(&other.to_string())
95    }
96}
97
98impl From<Error> for anyhow::Error {
99    fn from(error: Error) -> Self {
100        anyhow::Error::msg(error)
101    }
102}
103
104impl From<Error> for StorageError {
105    fn from(e: Error) -> Self {
106        StorageError::DatabaseError(Box::new(e))
107    }
108}
109
110impl From<Error> for ExecutorError {
111    fn from(e: Error) -> Self {
112        ExecutorError::StorageError(format!("{}", StorageError::from(e)))
113    }
114}
115
116#[cfg(test)]
117fuel_core_trace::enable_tracing!();