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"Cuprate has encountered a fatal error. The database may be corrupted.
14
15TODO: instructions on:
161. What to do
172. How to fix (re-sync, recover, etc)
183. General advice for preventing corruption
194. etc";
20
21//---------------------------------------------------------------------------------------------------- Misc
22/// Static string of the `crate` being used as the database backend.
23///
24/// | Backend | Value |
25/// |---------|-------|
26/// | `heed` | `"heed"`
27/// | `redb` | `"redb"`
28pub const DATABASE_BACKEND: &str = {
29 cfg_if! {
30 if #[cfg(all(feature = "redb", not(feature = "heed")))] {
31 "redb"
32 } else {
33 "heed"
34 }
35 }
36};
37
38/// Cuprate's database filename.
39///
40/// Used in [`Config::db_file`](crate::config::Config::db_file).
41///
42/// | Backend | Value |
43/// |---------|-------|
44/// | `heed` | `"data.mdb"`
45/// | `redb` | `"data.redb"`
46pub const DATABASE_DATA_FILENAME: &str = {
47 cfg_if! {
48 if #[cfg(all(feature = "redb", not(feature = "heed")))] {
49 "data.redb"
50 } else {
51 "data.mdb"
52 }
53 }
54};
55
56/// Cuprate's database lock filename.
57///
58/// | Backend | Value |
59/// |---------|-------|
60/// | `heed` | `Some("lock.mdb")`
61/// | `redb` | `None` (redb doesn't use a file lock)
62pub const DATABASE_LOCK_FILENAME: Option<&str> = {
63 cfg_if! {
64 if #[cfg(all(feature = "redb", not(feature = "heed")))] {
65 None
66 } else {
67 Some("lock.mdb")
68 }
69 }
70};
71
72//---------------------------------------------------------------------------------------------------- Tests
73#[cfg(test)]
74mod test {}