Skip to content

Commit

Permalink
Merge branch 'tomas/fix-all-features-build' (#2457)
Browse files Browse the repository at this point in the history
* origin/tomas/fix-all-features-build:
  use forked rocksdb that doesn't use jemalloc on windows
  sdk: fix unused import (in conditional compilation) warn
  core/token: add `#[must_use]` on token checked arith
  • Loading branch information
brentstone committed Jan 29, 2024
2 parents 065ac1a + f4c030a commit f4e042d
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 44 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ regex = "1.4.5"
reqwest = "0.11.4"
ripemd = "0.1"
rlimit = "0.5.4"
rocksdb = {version = "0.21.0", features = ['zstd'], default-features = false}
# rocksdb = {version = "0.21.0", features = ['zstd'], default-features = false}
# TEMP branch "tomas/no-jemalloc-win", replace once upstreamed
rocksdb = {git = "https://github.com/heliaxdev/rust-rocksdb", rev = "20f158ade557eea2d62baece0a5b5b55a34f4915", features = ['zstd'], default-features = false}
rpassword = "5.0.1"
serde = {version = "1.0.125", features = ["derive"]}
serde_bytes = "0.11.5"
Expand Down
19 changes: 3 additions & 16 deletions crates/apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,15 @@ name = "namadar"
path = "src/bin/namada-relayer/main.rs"

[features]
default = ["no_jemalloc"]
default = []
mainnet = [
"namada/mainnet",
]
# for integration tests and test utilities
testing = ["namada_test_utils"]
benches = ["testing", "namada_test_utils"]
integration = []

# RocksDB's "jemalloc" disabled by default as it takes a long time to build.
# Note that only exactly one of these features has to be enabled at a time.
# Jemalloc is enabled in `make build-release`.
no_jemalloc = ["dep:rocksdb"]
jemalloc = ["rocksdb_with_jemalloc"]
jemalloc = ["rocksdb/jemalloc"]

[dependencies]
namada = {path = "../namada", features = ["multicore", "http-client", "tendermint-rpc", "std"]}
Expand Down Expand Up @@ -121,6 +116,7 @@ regex.workspace = true
reqwest.workspace = true
ripemd.workspace = true
rlimit.workspace = true
rocksdb.workspace = true
rpassword.workspace = true
serde_bytes.workspace = true
serde_json = {workspace = true, features = ["raw_value"]}
Expand All @@ -146,15 +142,6 @@ zeroize.workspace = true
warp = "0.3.2"
bytes = "1.1.0"

[target.'cfg(not(windows))'.dependencies]
rocksdb = { workspace = true, optional = true }
rocksdb_with_jemalloc = { package = "rocksdb", version = "0.21.0", default-features = false, features = ['zstd', 'jemalloc'], optional = true }

[target.'cfg(windows)'.dependencies]
rocksdb = { workspace = true, optional = true }
# jemalloc is not supported on windows
rocksdb_with_jemalloc = { package = "rocksdb", version = "0.21.0", default-features = false, features = ['zstd'], optional = true }

[dev-dependencies]
assert_matches = "1.5.0"
namada = {path = "../namada", default-features = false, features = ["testing", "wasm-runtime"]}
Expand Down
7 changes: 0 additions & 7 deletions crates/apps/src/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,3 @@ pub mod facade {
pub use tower_abci::BoxError;
}
}

#[cfg(all(feature = "no_jemalloc", feature = "jemalloc"))]
compile_error!("`jemalloc` and `no_jemalloc` may not be used at the same time");
#[cfg(feature = "no_jemalloc")]
pub use rocksdb;
#[cfg(feature = "jemalloc")]
pub use rocksdb_with_jemalloc as rocksdb;
5 changes: 2 additions & 3 deletions crates/apps/src/lib/node/ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,8 @@ fn start_abci_broadcaster_shell(
};

// Setup DB cache, it must outlive the DB instance that's in the shell
let db_cache = crate::rocksdb::Cache::new_lru_cache(
db_block_cache_size_bytes as usize,
);
let db_cache =
rocksdb::Cache::new_lru_cache(db_block_cache_size_bytes as usize);

// Construct our ABCI application.
let tendermint_mode = config.shell.tendermint_mode.clone();
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/node/ledger/shims/abcipp_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl AbcippShim {
wasm_dir: PathBuf,
broadcast_sender: UnboundedSender<Vec<u8>>,
eth_oracle: Option<EthereumOracleChannels>,
db_cache: &crate::rocksdb::Cache,
db_cache: &rocksdb::Cache,
vp_wasm_compilation_cache: u64,
tx_wasm_compilation_cache: u64,
) -> (Self, AbciService, broadcast::Sender<()>) {
Expand Down
20 changes: 10 additions & 10 deletions crates/apps/src/lib/node/ledger/storage/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ use namada::types::time::DateTimeUtc;
use namada::types::token::ConversionState;
use namada::types::{ethereum_events, ethereum_structs};
use rayon::prelude::*;

use crate::config::utils::num_of_threads;
use crate::rocksdb::{
use rocksdb::{
BlockBasedOptions, ColumnFamily, ColumnFamilyDescriptor, DBCompactionStyle,
DBCompressionType, Direction, FlushOptions, IteratorMode, Options,
ReadOptions, WriteBatch,
};

use crate::config::utils::num_of_threads;

// TODO the DB schema will probably need some kind of versioning

/// Env. var to set a number of Rayon global worker threads
Expand All @@ -93,7 +93,7 @@ const NEW_DIFF_PREFIX: &str = "new";

/// RocksDB handle
#[derive(Debug)]
pub struct RocksDB(crate::rocksdb::DB);
pub struct RocksDB(rocksdb::DB);

/// DB Handle for batch writes.
#[derive(Default)]
Expand All @@ -102,7 +102,7 @@ pub struct RocksDBWriteBatch(WriteBatch);
/// Open RocksDB for the DB
pub fn open(
path: impl AsRef<Path>,
cache: Option<&crate::rocksdb::Cache>,
cache: Option<&rocksdb::Cache>,
) -> Result<RocksDB> {
let logical_cores = num_cpus::get();
let compaction_threads = num_of_threads(
Expand Down Expand Up @@ -190,7 +190,7 @@ pub fn open(
replay_protection_cf_opts,
));

crate::rocksdb::DB::open_cf_descriptors(&db_opts, path, cfs)
rocksdb::DB::open_cf_descriptors(&db_opts, path, cfs)
.map(RocksDB)
.map_err(|e| Error::DBError(e.into_string()))
}
Expand Down Expand Up @@ -636,7 +636,7 @@ impl RocksDB {
}

impl DB for RocksDB {
type Cache = crate::rocksdb::Cache;
type Cache = rocksdb::Cache;
type WriteBatch = RocksDBWriteBatch;

fn open(
Expand Down Expand Up @@ -1680,7 +1680,7 @@ fn iter_prefix<'a>(

#[derive(Debug)]
pub struct PersistentPrefixIterator<'a>(
PrefixIterator<crate::rocksdb::DBIterator<'a>>,
PrefixIterator<rocksdb::DBIterator<'a>>,
);

impl<'a> Iterator for PersistentPrefixIterator<'a> {
Expand Down Expand Up @@ -1755,7 +1755,7 @@ fn unknown_key_error(key: &str) -> Result<()> {

/// Try to increase NOFILE limit and set the `max_open_files` limit to it in
/// RocksDB options.
fn set_max_open_files(cf_opts: &mut crate::rocksdb::Options) {
fn set_max_open_files(cf_opts: &mut rocksdb::Options) {
#[cfg(unix)]
imp::set_max_open_files(cf_opts);
// Nothing to do on non-unix
Expand All @@ -1771,7 +1771,7 @@ mod imp {

const DEFAULT_NOFILE_LIMIT: Rlim = Rlim::from_raw(16384);

pub fn set_max_open_files(cf_opts: &mut crate::rocksdb::Options) {
pub fn set_max_open_files(cf_opts: &mut rocksdb::Options) {
let max_open_files = match increase_nofile_limit() {
Ok(max_open_files) => Some(max_open_files),
Err(err) => {
Expand Down
4 changes: 4 additions & 0 deletions crates/core/src/types/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ impl Amount {

/// Checked addition. Returns `None` on overflow or if
/// the amount exceed [`uint::MAX_VALUE`]
#[must_use]
pub fn checked_add(&self, amount: Amount) -> Option<Self> {
self.raw.checked_add(amount.raw).and_then(|result| {
if result <= uint::MAX_VALUE {
Expand All @@ -165,6 +166,7 @@ impl Amount {

/// Checked addition. Returns `None` on overflow or if
/// the amount exceed [`uint::MAX_SIGNED_VALUE`]
#[must_use]
pub fn checked_signed_add(&self, amount: Amount) -> Option<Self> {
self.raw.checked_add(amount.raw).and_then(|result| {
if result <= uint::MAX_SIGNED_VALUE {
Expand All @@ -189,13 +191,15 @@ impl Amount {
}

/// Checked division. Returns `None` on underflow.
#[must_use]
pub fn checked_div(&self, amount: Amount) -> Option<Self> {
self.raw
.checked_div(amount.raw)
.map(|result| Self { raw: result })
}

/// Checked multiplication. Returns `None` on overflow.
#[must_use]
pub fn checked_mul(&self, amount: Amount) -> Option<Self> {
self.raw
.checked_mul(amount.raw)
Expand Down
4 changes: 2 additions & 2 deletions crates/sdk/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::collections::{btree_map, BTreeMap, BTreeSet, HashMap, HashSet};
use std::env;
use std::fmt::Debug;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::str::FromStr;

// use async_std::io::prelude::WriteExt;
Expand Down Expand Up @@ -2263,7 +2263,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
.map_err(|e| Error::Other(e.to_string()))?
// Two up from "tests" dir to the root dir
.parent()
.and_then(Path::parent)
.and_then(std::path::Path::parent)
.ok_or_else(|| {
Error::Other("Can not get root dir".to_string())
})?
Expand Down

0 comments on commit f4e042d

Please sign in to comment.