Skip to content

Commit

Permalink
Remove vendored temppath (Sovereign-Labs#385)
Browse files Browse the repository at this point in the history
* Remove `temp` and `temporary` features from sov-db packages
  • Loading branch information
citizen-stig authored Jun 5, 2023
1 parent e7c2d02 commit e5d403a
Show file tree
Hide file tree
Showing 45 changed files with 162 additions and 233 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ derive_more = "0.99.11"
clap = { version = "4.2.7", features = ["derive"] }
toml = "0.7.3"
jsonrpsee = "0.16.2"
tempfile = "3.5"
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ fix: ## cargo fmt and fix

lint: ## cargo check and clippy
cargo check
cargo check --all-targets --all-features
cargo clippy --all

check-features: ## Checks that project compiles with all combinations of features
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-nft-module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ sov-modules-macros = { path = "../../module-system/sov-modules-macros" }
sov-state = { path = "../../module-system/sov-state", default-features = false }

[dev-dependencies]
sov-state = { path = "../../module-system/sov-state", features = ["temp"] }
sov-rollup-interface = { path = "../../rollup-interface" }
tempfile = { workspace = true }


[features]
Expand Down
10 changes: 7 additions & 3 deletions examples/demo-nft-module/tests/nft_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ fn genesis_and_mint() {
admin,
owners: vec![(0, owner1.clone())],
};
let mut working_set = WorkingSet::new(ProverStorage::temporary());

let tmpdir = tempfile::tempdir().unwrap();
let mut working_set = WorkingSet::new(ProverStorage::with_path(tmpdir.path()).unwrap());
let nft = NonFungibleToken::new();

// Genesis
Expand Down Expand Up @@ -70,7 +72,8 @@ fn transfer() {
admin: admin.clone(),
owners: vec![(0, admin.clone()), (1, owner1.clone()), (2, owner2.clone())],
};
let mut working_set = WorkingSet::new(ProverStorage::temporary());
let tmpdir = tempfile::tempdir().unwrap();
let mut working_set = WorkingSet::new(ProverStorage::with_path(tmpdir.path()).unwrap());
let nft = NonFungibleToken::new();
nft.genesis(&config, &mut working_set).unwrap();

Expand Down Expand Up @@ -128,7 +131,8 @@ fn burn() {
owners: vec![(0, owner1)],
};

let mut working_set = WorkingSet::new(ProverStorage::temporary());
let tmpdir = tempfile::tempdir().unwrap();
let mut working_set = WorkingSet::new(ProverStorage::with_path(tmpdir.path()).unwrap());
let nft = NonFungibleToken::new();
nft.genesis(&config, &mut working_set).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion examples/demo-prover/methods/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ downloader = "0.2"
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = "1.0"
sha2 = "0.10.6"
tempfile = "3.3"
tempfile = "3.5"
zip = "0.6"

[profile.dev]
Expand Down
2 changes: 1 addition & 1 deletion examples/demo-rollup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ const-rollup-config = { path = "../const-rollup-config" }


[dev-dependencies]
tempfile = "3.5.0"
tempfile = { workspace = true }
5 changes: 2 additions & 3 deletions examples/demo-stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ sov-state = { path = "../../module-system/sov-state", default-features = false }
sov-modules-api = { path = "../../module-system/sov-modules-api", default-features = false }
sov-modules-macros = { path = "../../module-system/sov-modules-macros" }
# Only enable the db on "native" feature
sov-schema-db = { path = "../../full-node/db/sov-schema-db", features = ["temppath"], optional = true }
sov-schema-db = { path = "../../full-node/db/sov-schema-db", optional = true }
sov-db = { path = "../../full-node/db/sov-db", optional = true }

[dev-dependencies]
sov-rollup-interface = { path = "../../rollup-interface", features = ["mocks"] }
tempfile = "3.5.0"
tempfile = { workspace = true }

[features]
default = ["native"]
native = [
"sov-state/temp",
"dep:sov-db",
"dep:sov-schema-db",
"sov-bank/native",
Expand Down
10 changes: 5 additions & 5 deletions examples/demo-stf/src/sov-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ mod test {

#[test]
fn test_sov_cli() {
let mut test_demo = TestDemo::new();
// Tempdir is created here, so it will be deleted only after test is finished.
let tempdir = tempfile::tempdir().unwrap();
let mut test_demo = TestDemo::with_path(tempdir.path().to_path_buf());
let test_data = read_test_data();

execute_txs(&mut test_demo.demo, test_demo.config, test_data.data);
Expand All @@ -266,13 +268,12 @@ mod test {

// Test helpers
struct TestDemo {
config: demo_stf::runtime::GenesisConfig<C>,
config: GenesisConfig<C>,
demo: DemoApp<C, MockZkvm>,
}

impl TestDemo {
fn new() -> Self {
let path = sov_schema_db::temppath::TempPath::new();
fn with_path(path: PathBuf) -> Self {
let value_setter_admin_private_key = DefaultPrivateKey::generate();
let election_admin_private_key = DefaultPrivateKey::generate();

Expand All @@ -282,7 +283,6 @@ mod test {
&election_admin_private_key,
);

let path = path.as_ref().to_path_buf();
let runner_config = Config {
storage: sov_state::config::Config { path },
};
Expand Down
12 changes: 8 additions & 4 deletions examples/demo-stf/src/tests/stf_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub mod test {

#[test]
fn test_demo_values_in_db() {
let path = sov_schema_db::temppath::TempPath::new();
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path();
let value_setter_admin_private_key = DefaultPrivateKey::generate();
let election_admin_private_key = DefaultPrivateKey::generate();

Expand Down Expand Up @@ -73,7 +74,8 @@ pub mod test {

#[test]
fn test_demo_values_in_cache() {
let path = sov_schema_db::temppath::TempPath::new();
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path();
let mut demo = create_new_demo(&path);

let value_setter_admin_private_key = DefaultPrivateKey::generate();
Expand Down Expand Up @@ -125,7 +127,8 @@ pub mod test {

#[test]
fn test_demo_values_not_in_db() {
let path = sov_schema_db::temppath::TempPath::new();
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path();

let value_setter_admin_private_key = DefaultPrivateKey::generate();
let election_admin_private_key = DefaultPrivateKey::generate();
Expand Down Expand Up @@ -176,7 +179,8 @@ pub mod test {

#[test]
fn test_sequencer_insufficient_funds() {
let path = sov_schema_db::temppath::TempPath::new();
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path();

let value_setter_admin_private_key = DefaultPrivateKey::generate();
let election_admin_private_key = DefaultPrivateKey::generate();
Expand Down
9 changes: 6 additions & 3 deletions examples/demo-stf/src/tests/tx_revert_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const SEQUENCER_BALANCE: u64 = LOCKED_AMOUNT + SEQUENCER_BALANCE_DELTA;

#[test]
fn test_tx_revert() {
let path = sov_schema_db::temppath::TempPath::new();
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path();
let value_setter_admin_private_key = DefaultPrivateKey::generate();
let election_admin_private_key = DefaultPrivateKey::generate();

Expand Down Expand Up @@ -87,7 +88,8 @@ fn test_tx_revert() {

#[test]
fn test_tx_bad_sig() {
let path = sov_schema_db::temppath::TempPath::new();
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path();
let value_setter_admin_private_key = DefaultPrivateKey::generate();
let election_admin_private_key = DefaultPrivateKey::generate();

Expand Down Expand Up @@ -145,7 +147,8 @@ fn test_tx_bad_sig() {

#[test]
fn test_tx_bad_serialization() {
let path = sov_schema_db::temppath::TempPath::new();
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path();

let value_setter_admin_private_key = DefaultPrivateKey::generate();
let election_admin_private_key = DefaultPrivateKey::generate();
Expand Down
8 changes: 3 additions & 5 deletions full-node/db/sov-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
rust-version = { workspace = true }
version = { workspace = true }
version = { workspace = true }
readme = "README.md"
resolver = "2"

Expand All @@ -19,19 +19,17 @@ jmt = { workspace = true }
sov-schema-db = { path = "../sov-schema-db", version = "0.1" }
sov-rollup-interface = { path = "../../../rollup-interface", version = "0.1" }


# External
anyhow = { workspace = true }
byteorder = { workspace = true }
borsh = { workspace = true }
serde = { workspace = true, features = ["derive"] }
rocksdb = { workspace = true }

bincode = "1.3.3"


[dev-dependencies]
sov-schema-db = { path = "../sov-schema-db", version = "0.1", features = ["temppath"] }
tempfile = { workspace = true }

[features]
default = []
temp = ["sov-schema-db/temppath"]
7 changes: 0 additions & 7 deletions full-node/db/sov-db/src/ledger_db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@ impl LedgerDB {
})
}

/// A rocksdb instance which stores its data in a tempdir
#[cfg(any(test, feature = "temp"))]
pub fn temporary() -> Self {
let path = sov_schema_db::temppath::TempPath::new();
Self::with_path(path).unwrap()
}

pub fn get_next_items_numbers(&self) -> ItemNumbers {
self.next_item_numbers.lock().unwrap().clone()
}
Expand Down
10 changes: 2 additions & 8 deletions full-node/db/sov-db/src/state_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ impl StateDB {
})
}

/// A rocksdb instance which stores its data in a tempdir
#[cfg(any(test, feature = "temp"))]
pub fn temporary() -> Self {
let path = sov_schema_db::temppath::TempPath::new();
Self::with_path(path).unwrap()
}

pub fn put_preimage(&self, key_hash: KeyHash, key: &Vec<u8>) -> Result<(), anyhow::Error> {
self.db.put::<KeyHashToKey>(&key_hash.0, key)
}
Expand Down Expand Up @@ -169,7 +162,8 @@ mod state_db_tests {

#[test]
fn test_simple() {
let db = StateDB::temporary();
let tmpdir = tempfile::tempdir().unwrap();
let db = StateDB::with_path(tmpdir.path()).unwrap();
let key_hash = KeyHash([1u8; 32]);
let key = vec![2u8; 100];
let value = [8u8; 150];
Expand Down
12 changes: 1 addition & 11 deletions full-node/db/sov-schema-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ prometheus = { workspace = true }
rocksdb = { workspace = true }
tracing = { workspace = true }

# Temppath external dependencies
byteorder = { workspace = true, optional = true }
rand = { workspace = true, optional = true }
hex = { workspace = true, optional = true }

[dev-dependencies]
byteorder = { workspace = true }
rand = { workspace = true }
hex = { workspace = true }

[features]
default = []
temppath = ["dep:byteorder", "dep:rand", "dep:hex"]
tempfile = { workspace = true }
29 changes: 16 additions & 13 deletions full-node/db/sov-schema-db/src/db_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use sov_rollup_interface::{
db::{errors::CodecError, ColumnFamilyName, KeyDecoder, KeyEncoder, Result, ValueCodec},
define_schema,
};
use std::path::Path;

use crate::{temppath::TempPath, Schema, SchemaBatch, DB};
use crate::{Schema, SchemaBatch, DB};
use tempfile::TempDir;

// Creating two schemas that share exactly the same structure but are stored in different column
// families. Also note that the key and value are of the same type `TestField`. By implementing
Expand Down Expand Up @@ -87,14 +89,14 @@ fn get_column_families() -> Vec<ColumnFamilyName> {
]
}

fn open_db(dir: &TempPath) -> DB {
fn open_db(dir: impl AsRef<Path>) -> DB {
let mut db_opts = rocksdb::Options::default();
db_opts.create_if_missing(true);
db_opts.create_missing_column_families(true);
DB::open(dir.path(), "test", get_column_families(), &db_opts).expect("Failed to open DB.")
DB::open(dir, "test", get_column_families(), &db_opts).expect("Failed to open DB.")
}

fn open_db_read_only(dir: &TempPath) -> DB {
fn open_db_read_only(dir: &TempDir) -> DB {
DB::open_cf_readonly(
&rocksdb::Options::default(),
dir.path(),
Expand All @@ -104,7 +106,7 @@ fn open_db_read_only(dir: &TempPath) -> DB {
.expect("Failed to open DB.")
}

fn open_db_as_secondary(dir: &TempPath, dir_sec: &TempPath) -> DB {
fn open_db_as_secondary(dir: &TempDir, dir_sec: &TempDir) -> DB {
DB::open_cf_as_secondary(
&rocksdb::Options::default(),
&dir.path(),
Expand All @@ -116,13 +118,13 @@ fn open_db_as_secondary(dir: &TempPath, dir_sec: &TempPath) -> DB {
}

struct TestDB {
_tmpdir: TempPath,
_tmpdir: TempDir,
db: DB,
}

impl TestDB {
fn new() -> Self {
let tmpdir = TempPath::new();
let tmpdir = tempfile::tempdir().unwrap();
let db = open_db(&tmpdir);

TestDB {
Expand Down Expand Up @@ -279,7 +281,7 @@ fn test_two_schema_batches() {

#[test]
fn test_reopen() {
let tmpdir = TempPath::new();
let tmpdir = tempfile::tempdir().unwrap();
{
let db = open_db(&tmpdir);
db.put::<TestSchema1>(&TestField(0), &TestField(0)).unwrap();
Expand All @@ -299,7 +301,7 @@ fn test_reopen() {

#[test]
fn test_open_read_only() {
let tmpdir = TempPath::new();
let tmpdir = tempfile::tempdir().unwrap();
{
let db = open_db(&tmpdir);
db.put::<TestSchema1>(&TestField(0), &TestField(0)).unwrap();
Expand All @@ -316,8 +318,8 @@ fn test_open_read_only() {

#[test]
fn test_open_as_secondary() {
let tmpdir = TempPath::new();
let tmpdir_sec = TempPath::new();
let tmpdir = tempfile::tempdir().unwrap();
let tmpdir_sec = tempfile::tempdir().unwrap();

let db = open_db(&tmpdir);
db.put::<TestSchema1>(&TestField(0), &TestField(0)).unwrap();
Expand Down Expand Up @@ -366,8 +368,9 @@ fn test_report_size() {

#[test]
fn test_checkpoint() {
let tmpdir = TempPath::new();
let checkpoint = TempPath::new();
let tmpdir = tempfile::tempdir().unwrap();
let checkpoint_parent = tempfile::tempdir().unwrap();
let checkpoint = checkpoint_parent.path().join("checkpoint");
{
let db = open_db(&tmpdir);
db.put::<TestSchema1>(&TestField(0), &TestField(0)).unwrap();
Expand Down
Loading

0 comments on commit e5d403a

Please sign in to comment.