cuprate_database/constants.rs
1//! General constants used throughout `cuprate-blockchain`.
2
3//---------------------------------------------------------------------------------------------------- Import
4use cfg_if::cfg_if;
5
6//---------------------------------------------------------------------------------------------------- Error Messages
7/// Corrupt database error message.
8///
9/// The error message shown to end-users in panic
10/// messages if we think the database is corrupted.
11///
12/// This is meant to be user-friendly.
13pub const DATABASE_CORRUPT_MSG: &str = r"`cuprated` has encountered a fatal error. The database may be corrupted.
14
15If `cuprated` continues to crash with the current database,
16you may have to delete the database file and re-sync from scratch.
17
18See <https://user.cuprate.org/resources/disk.html>
19for more information on where database files are.
20
21If this happens frequently, consider using the `Safe` sync mode.";
22
23//---------------------------------------------------------------------------------------------------- Misc
24/// Static string of the `crate` being used as the database backend.
25///
26/// | Backend | Value |
27/// |---------|-------|
28/// | `heed` | `"heed"`
29/// | `redb` | `"redb"`
30pub const DATABASE_BACKEND: &str = {
31 cfg_if! {
32 if #[cfg(all(feature = "redb", not(feature = "heed")))] {
33 "redb"
34 } else {
35 "heed"
36 }
37 }
38};
39
40/// Cuprate's database filename.
41///
42/// Used in [`Config::db_file`](crate::config::Config::db_file).
43///
44/// | Backend | Value |
45/// |---------|-------|
46/// | `heed` | `"data.mdb"`
47/// | `redb` | `"data.redb"`
48pub const DATABASE_DATA_FILENAME: &str = {
49 cfg_if! {
50 if #[cfg(all(feature = "redb", not(feature = "heed")))] {
51 "data.redb"
52 } else {
53 "data.mdb"
54 }
55 }
56};
57
58/// Cuprate's database lock filename.
59///
60/// | Backend | Value |
61/// |---------|-------|
62/// | `heed` | `Some("lock.mdb")`
63/// | `redb` | `None` (redb doesn't use a file lock)
64pub const DATABASE_LOCK_FILENAME: Option<&str> = {
65 cfg_if! {
66 if #[cfg(all(feature = "redb", not(feature = "heed")))] {
67 None
68 } else {
69 Some("lock.mdb")
70 }
71 }
72};
73
74//---------------------------------------------------------------------------------------------------- Tests
75#[cfg(test)]
76mod test {}