Skip to content

Commit

Permalink
sqlite enforced -- fix test compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
Protryon committed Aug 26, 2021
1 parent 04be8dd commit 770c8b6
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 37 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ optional = true
[features]
default = [ ]
prometheus = [ "snarkos-network/prometheus" ]
sqlite = [ "snarkos-storage/sqlite_storage" ]
compile_capnp_schema = [ "capnpc" ]
noconfig = [ ]

Expand Down
5 changes: 0 additions & 5 deletions snarkos/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ pub struct Storage {
pub trim: bool,
/// If `true`, scans superfluous blocks for valid forks at boot time. Can take a while.
pub scan_for_forks: bool,
/// If `true`, uses sqlite instead of rocksdb for backend storage. Requires `sqlite` feature.
pub use_sqlite: bool,
/// If `Some`, will reset canon to at most this block height.
pub max_head: Option<u32>,
}
Expand Down Expand Up @@ -159,7 +157,6 @@ impl Default for Config {
trim: false,
validate: false,
scan_for_forks: false,
use_sqlite: false,
max_head: None,
},
}
Expand Down Expand Up @@ -235,7 +232,6 @@ impl Config {
"no-jsonrpc" => self.no_jsonrpc(arguments.is_present(option)),
"trim-storage" => self.trim_storage(arguments.is_present(option)),
"validate-storage" => self.validate_storage(arguments.is_present(option)),
"sqlite" => self.storage.use_sqlite = arguments.is_present(option),
// Options
"connect" => self.connect(arguments.value_of(option)),
"export-canon-blocks" => self.export_canon_blocks(clap::value_t!(arguments.value_of(*option), u32).ok()),
Expand Down Expand Up @@ -471,7 +467,6 @@ impl CLI for ConfigCli {
"import-canon-blocks",
"is-bootnode",
"is-miner",
"sqlite",
"is-crawler",
"ip",
"port",
Expand Down
32 changes: 13 additions & 19 deletions snarkos/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ use snarkos::{
use snarkos_consensus::{Consensus, ConsensusParameters, DeserializedLedger, DynLedger, MemoryPool, MerkleLedger};
use snarkos_network::{config::Config as NodeConfig, MinerInstance, Node, Sync};
use snarkos_rpc::start_rpc_server;
#[cfg(feature = "sqlite")]
use snarkos_storage::SqliteStorage;
use snarkos_storage::{
export_canon_blocks,
key_value::KeyValueStore,
AsyncStorage,
RocksDb,
SerialBlock,
SqliteStorage,
Storage,
VMBlock,
Validator,
Expand Down Expand Up @@ -120,25 +119,19 @@ async fn start_server(config: Config) -> anyhow::Result<()> {
)?;

info!("Loading storage at '{}'...", path.to_str().unwrap_or_default());
let storage = if config.storage.use_sqlite {
#[cfg(feature = "sqlite")]
{
let mut sqlite_path = path.clone();
sqlite_path.push("sqlite.db");

if config.storage.validate {
error!("validator not implemented for sqlite");
return Ok(());
}
let storage = {
let mut sqlite_path = path.clone();
sqlite_path.push("sqlite.db");

Arc::new(AsyncStorage::new(SqliteStorage::new(&sqlite_path)?))
}
#[cfg(not(feature = "sqlite"))]
{
error!("cannot use sqlite storage without `sqlite` compilation feature");
if config.storage.validate {
error!("validator not implemented for sqlite");
return Ok(());
}
} else {

Arc::new(AsyncStorage::new(SqliteStorage::new(&sqlite_path)?))
};

/*
let storage = RocksDb::open(&path)?;
// For extra safety, validate storage too if a trim is requested.
Expand All @@ -157,7 +150,8 @@ async fn start_server(config: Config) -> anyhow::Result<()> {
};
Arc::new(AsyncStorage::new(KeyValueStore::new(storage)))
};
*/

if let Some(max_head) = config.storage.max_head {
let canon_next = storage.get_block_hash(max_head + 1).await?;
Expand Down
2 changes: 1 addition & 1 deletion storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ license = "GPL-3.0"
edition = "2018"

[features]
default = [ "rocksdb_storage" ]
default = [ "rocksdb_storage", "sqlite_storage" ]
rocksdb_storage = [ "rocksdb" ]
sqlite_storage = [ "rusqlite" ]
mem_storage = [ ]
Expand Down
2 changes: 0 additions & 2 deletions storage/src/storage/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ pub struct ForkPath {
pub base_index: u32,
/// Set of digests from `base_index`'s corresponding block to the target block
pub path: Vec<Digest>,
// / Tree of all descendent blocks to the target block
// pub tail: DigestTree,
}

pub enum ForkDescription {
Expand Down
3 changes: 2 additions & 1 deletion storage/src/storage/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ pub trait SyncStorage {
return Ok(ForkDescription::TooLong);
}
let longest_path = self.longest_child_path(hash)?;
debug!("longest child path terminating in {:?}", longest_path.last());
// let descendents = self.get_block_digest_tree(hash)?;
debug!("longest child path terminating in {:?}", longest_path.len());
side_chain_path.extend(longest_path);
return Ok(ForkDescription::Path(ForkPath {
base_index: block_num as u32,
Expand Down
11 changes: 7 additions & 4 deletions testing/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod topology;
use crate::sync::FIXTURE;

use snarkos_network::{errors::*, *};
use snarkos_storage::{key_value::KeyValueStore, MemDb};
use snarkos_storage::{AsyncStorage, SqliteStorage};

use std::{net::SocketAddr, sync::Arc, time::Duration};
use tokio::{
Expand Down Expand Up @@ -183,9 +183,12 @@ pub async fn test_node(setup: TestSetup) -> Node {
let is_miner = setup.consensus_setup.as_ref().map(|c| c.is_miner) == Some(true);
let config = test_config(setup.clone());
let node = match setup.consensus_setup {
None => Node::new(config, Arc::new(KeyValueStore::new(MemDb::new())))
.await
.unwrap(),
None => Node::new(
config,
Arc::new(AsyncStorage::new(SqliteStorage::new_ephemeral().unwrap())),
)
.await
.unwrap(),
Some(consensus_setup) => {
let consensus = test_consensus(consensus_setup).await;
let mut node = Node::new(config, consensus.consensus.storage.clone()).await.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions testing/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod validator;

// pub use snarkos_storage::validator::FixMode;
use snarkos_consensus::{DynLedger, MerkleLedger};
use snarkos_storage::{key_value::KeyValueStore, DynStorage, MemDb};
use snarkos_storage::{AsyncStorage, DynStorage, SqliteStorage};
use snarkvm_algorithms::{MerkleParameters, CRH};
use snarkvm_dpc::testnet1::{instantiated::Components, Testnet1Components};

Expand All @@ -46,6 +46,6 @@ pub fn initialize_test_blockchain() -> (DynStorage, DynLedger) {
let ledger = DynLedger(Box::new(
MerkleLedger::new(ledger_parameters, &[], &[], &[], &[]).unwrap(),
));
let store = Arc::new(KeyValueStore::new(MemDb::new()));
let store = Arc::new(AsyncStorage::new(SqliteStorage::new_ephemeral().unwrap()));
(store, ledger)
}
4 changes: 2 additions & 2 deletions testing/src/sync/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
sync::genesis,
};
use snarkos_consensus::{DynLedger, MerkleLedger};
use snarkos_storage::{key_value::KeyValueStore, DynStorage, MemDb};
use snarkos_storage::{AsyncStorage, DynStorage, SqliteStorage};
use snarkvm_algorithms::{MerkleParameters, CRH};
use snarkvm_dpc::{
testnet1::{instantiated::*, NoopProgram, Testnet1Components},
Expand Down Expand Up @@ -49,7 +49,7 @@ pub struct Fixture {

impl Fixture {
pub fn storage(&self) -> DynStorage {
Arc::new(KeyValueStore::new(MemDb::new()))
Arc::new(AsyncStorage::new(SqliteStorage::new_ephemeral().unwrap()))
}

pub fn ledger(&self) -> DynLedger {
Expand Down

0 comments on commit 770c8b6

Please sign in to comment.