Skip to content

Commit 08cdaab

Browse files
committed
switch heed
1 parent 85d87b2 commit 08cdaab

File tree

28 files changed

+1360
-1296
lines changed

28 files changed

+1360
-1296
lines changed

Cargo.lock

Lines changed: 99 additions & 320 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ futures = { version = "0.3", default-features = false }
193193
hex = { version = "0.4", default-features = false }
194194
hex-literal = { version = "1", default-features = false }
195195
indexmap = { version = "2", default-features = false }
196+
itertools = { version = "0.14", default-features = false, features = ["use_std"] }
196197
memmap2 = { version = "0.9", default-features = false }
197198
monero-address = { git = "https://github.com/monero-oxide/monero-oxide.git", rev = "7c288b058ae7f1e3d36600a2af11b3176102bcfc", default-features = false }
198199
monero-oxide = { git = "https://github.com/monero-oxide/monero-oxide.git", rev = "7c288b058ae7f1e3d36600a2af11b3176102bcfc", default-features = false, features = ["std"] }

binaries/cuprated/src/blockchain/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use tower::util::MapErr;
22

3-
use cuprate_blockchain::{cuprate_database::RuntimeError, service::BlockchainReadHandle};
3+
use cuprate_database::RuntimeError;
4+
use cuprate_blockchain:: service::BlockchainReadHandle;
45

56
/// The [`BlockchainReadHandle`] with the [`tower::Service::Error`] mapped to conform to what the consensus crate requires.
67
pub type ConsensusBlockchainReadHandle =

binaries/cuprated/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl Config {
299299
cuprate_blockchain::config::ConfigBuilder::default()
300300
.network(self.network)
301301
.data_directory(self.fs.data_directory.clone())
302-
.sync_mode(blockchain.sync_mode)
302+
// .sync_mode(blockchain.sync_mode)
303303
.build()
304304
}
305305

storage/blockchain/Cargo.toml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ keywords = ["cuprate", "blockchain", "database"]
1212
default = ["heed"]
1313
# default = ["redb", "service"]
1414
# default = ["redb-memory", "service"]
15-
heed = ["cuprate-database/heed"]
16-
redb = ["cuprate-database/redb"]
17-
redb-memory = ["cuprate-database/redb-memory"]
18-
serde = ["dep:serde", "cuprate-database/serde", "cuprate-database-service/serde", "cuprate-helper/serde"]
15+
heed = []
16+
redb = []
17+
redb-memory = []
18+
serde = ["dep:serde", "cuprate-database-service/serde", "cuprate-helper/serde"]
1919

2020
[dependencies]
21-
cuprate-database = { workspace = true }
21+
# cuprate-database = { workspace = true }
2222
cuprate-database-service = { workspace = true }
2323
cuprate-helper = { workspace = true, features = ["fs", "map", "crypto", "tx", "thread"] }
2424
cuprate-types = { workspace = true, features = ["blockchain"] }
@@ -31,11 +31,15 @@ rand = { workspace = true, features = ["std", "std_rng"] }
3131
monero-oxide = { workspace = true, features = ["std"] }
3232
serde = { workspace = true, optional = true }
3333

34-
indexmap = { workspace = true, features = ["rayon"] }
34+
heed = { git = "https://github.com/Boog900/heed.git", branch = "wip" }
35+
36+
itertools = { workspace = true }
37+
indexmap = { workspace = true, features = ["rayon", "std"] }
3538
tower = { workspace = true }
3639
thread_local = { workspace = true }
3740
rayon = { workspace = true }
3841
bytes = { workspace = true }
42+
thiserror = { workspace = true, features = ["std"] }
3943

4044
[dev-dependencies]
4145
cuprate-constants = { workspace = true }

storage/blockchain/src/config.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use std::{borrow::Cow, path::PathBuf};
4646
#[cfg(feature = "serde")]
4747
use serde::{Deserialize, Serialize};
4848

49-
use cuprate_database::{config::SyncMode, resize::ResizeAlgorithm};
5049
use cuprate_helper::{
5150
fs::{blockchain_path, CUPRATE_DATA_DIR},
5251
network::Network,
@@ -71,9 +70,6 @@ pub struct ConfigBuilder {
7170

7271
data_dir: Option<PathBuf>,
7372

74-
/// [`Config::cuprate_database_config`].
75-
db_config: cuprate_database::config::ConfigBuilder,
76-
7773
/// [`Config::reader_threads`].
7874
reader_threads: Option<ReaderThreads>,
7975
}
@@ -87,10 +83,6 @@ impl ConfigBuilder {
8783
Self {
8884
network: Network::default(),
8985
data_dir: None,
90-
db_config: cuprate_database::config::ConfigBuilder::new(Cow::Owned(blockchain_path(
91-
&CUPRATE_DATA_DIR,
92-
Network::Mainnet,
93-
))),
9486
reader_threads: None,
9587
}
9688
}
@@ -110,14 +102,9 @@ impl ConfigBuilder {
110102
.unwrap_or_else(|| CUPRATE_DATA_DIR.to_path_buf());
111103

112104
let reader_threads = self.reader_threads.unwrap_or_default();
113-
let db_config = self
114-
.db_config
115-
.db_directory(Cow::Owned(blockchain_path(&data_dir, self.network)))
116-
.reader_threads(reader_threads.as_threads())
117-
.build();
118105

119106
Config {
120-
db_config,
107+
data_dir: blockchain_path(&data_dir, self.network),
121108
blob_data_dir: None,
122109
reader_threads,
123110
}
@@ -137,20 +124,6 @@ impl ConfigBuilder {
137124
self
138125
}
139126

140-
/// Calls [`cuprate_database::config::ConfigBuilder::sync_mode`].
141-
#[must_use]
142-
pub fn sync_mode(mut self, sync_mode: SyncMode) -> Self {
143-
self.db_config = self.db_config.sync_mode(sync_mode);
144-
self
145-
}
146-
147-
/// Calls [`cuprate_database::config::ConfigBuilder::resize_algorithm`].
148-
#[must_use]
149-
pub fn resize_algorithm(mut self, resize_algorithm: ResizeAlgorithm) -> Self {
150-
self.db_config = self.db_config.resize_algorithm(resize_algorithm);
151-
self
152-
}
153-
154127
/// Set a custom [`ReaderThreads`].
155128
#[must_use]
156129
pub const fn reader_threads(mut self, reader_threads: ReaderThreads) -> Self {
@@ -164,8 +137,6 @@ impl ConfigBuilder {
164137
/// Good default for testing, and resource-available machines.
165138
#[must_use]
166139
pub fn fast(mut self) -> Self {
167-
self.db_config = self.db_config.fast();
168-
169140
self.reader_threads = Some(ReaderThreads::OnePerThread);
170141
self
171142
}
@@ -176,8 +147,6 @@ impl ConfigBuilder {
176147
/// Good default for resource-limited machines, e.g. a cheap VPS.
177148
#[must_use]
178149
pub fn low_power(mut self) -> Self {
179-
self.db_config = self.db_config.low_power();
180-
181150
self.reader_threads = Some(ReaderThreads::One);
182151
self
183152
}
@@ -187,11 +156,7 @@ impl Default for ConfigBuilder {
187156
fn default() -> Self {
188157
Self {
189158
network: Network::default(),
190-
data_dir: Some(CUPRATE_DATA_DIR.to_path_buf()),
191-
db_config: cuprate_database::config::ConfigBuilder::new(Cow::Owned(blockchain_path(
192-
&CUPRATE_DATA_DIR,
193-
Network::default(),
194-
))),
159+
data_dir: Some(blockchain_path(&CUPRATE_DATA_DIR, Network::default())),
195160
reader_threads: Some(ReaderThreads::default()),
196161
}
197162
}
@@ -208,8 +173,7 @@ impl Default for ConfigBuilder {
208173
#[derive(Debug, Clone, PartialEq, PartialOrd)]
209174
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
210175
pub struct Config {
211-
/// The database configuration.
212-
pub db_config: cuprate_database::config::Config,
176+
pub data_dir: PathBuf,
213177

214178
/// The directory to store block/tx blobs.
215179
pub blob_data_dir: Option<PathBuf>,

storage/blockchain/src/database.rs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
use crate::config::Config;
2-
use cuprate_database::ConcreteEnv;
2+
use crate::types::{
3+
AltBlockHeight, AltChainInfo, AltTransactionInfo, Amount, AmountIndices, BlockHash,
4+
BlockHeight, CompactAltBlockInfo, Hash32Bytes, HeedAmountIndices, HeedUsize, KeyImage, Output,
5+
PreRctOutputId, RawChainId, StorableHeed, TxHash, TxId, ZeroKey,
6+
};
37
use cuprate_linear_tapes::{Advice, LinearTapes, Tape};
8+
use heed::types::U64;
9+
use heed::{DefaultComparator, IntegerComparator};
410
use std::iter::{once, Once};
11+
use std::sync::OnceLock;
512

613
/// The name of the ringCT outputs tape.
714
pub const RCT_OUTPUTS: &str = "rct_outputs";
@@ -25,7 +32,47 @@ pub const TX_INFOS: &str = "tx_infos";
2532
/// The name of the block infos tape.
2633
pub const BLOCK_INFOS: &str = "block_infos";
2734

28-
pub struct Database {
29-
pub(crate) dynamic_tables: ConcreteEnv,
35+
pub static BLOCK_HEIGHTS: OnceLock<heed::Database<Hash32Bytes, HeedUsize>> = OnceLock::new();
36+
37+
pub static KEY_IMAGES: OnceLock<heed::Database<ZeroKey, Hash32Bytes>> = OnceLock::new();
38+
39+
pub static PRE_RCT_OUTPUTS: OnceLock<
40+
heed::Database<
41+
U64<heed::byteorder::NativeEndian>,
42+
Output,
43+
IntegerComparator,
44+
IntegerComparator,
45+
>,
46+
> = OnceLock::new();
47+
48+
pub static TX_IDS: OnceLock<heed::Database<Hash32Bytes, HeedUsize>> = OnceLock::new();
49+
50+
pub static TX_OUTPUTS: OnceLock<heed::Database<HeedUsize, HeedAmountIndices, IntegerComparator>> =
51+
OnceLock::new();
52+
53+
pub static ALT_CHAIN_INFOS: OnceLock<
54+
heed::Database<StorableHeed<RawChainId>, StorableHeed<AltChainInfo>>,
55+
> = OnceLock::new();
56+
57+
pub static ALT_BLOCK_HEIGHTS: OnceLock<heed::Database<Hash32Bytes, StorableHeed<AltBlockHeight>>> =
58+
OnceLock::new();
59+
60+
pub static ALT_BLOCKS_INFO: OnceLock<
61+
heed::Database<StorableHeed<AltBlockHeight>, StorableHeed<CompactAltBlockInfo>>,
62+
> = OnceLock::new();
63+
64+
pub static ALT_BLOCK_BLOBS: OnceLock<
65+
heed::Database<StorableHeed<AltBlockHeight>, heed::types::Bytes>,
66+
> = OnceLock::new();
67+
68+
pub static ALT_TRANSACTION_BLOBS: OnceLock<heed::Database<Hash32Bytes, heed::types::Bytes>> =
69+
OnceLock::new();
70+
71+
pub static ALT_TRANSACTION_INFOS: OnceLock<
72+
heed::Database<Hash32Bytes, StorableHeed<AltTransactionInfo>>,
73+
> = OnceLock::new();
74+
75+
pub struct Blockchain {
76+
pub(crate) dynamic_tables: heed::Env,
3077
pub(crate) linear_tapes: LinearTapes,
3178
}

storage/blockchain/src/error.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub type DbResult<T> = Result<T, BlockchainError>;
2+
3+
#[derive(thiserror::Error, Debug)]
4+
pub enum BlockchainError {
5+
#[error(transparent)]
6+
Heed(#[from] heed::Error),
7+
#[error(transparent)]
8+
IO(#[from] std::io::Error),
9+
#[error("not found")]
10+
NotFound,
11+
}

0 commit comments

Comments
 (0)