Skip to content

Commit

Permalink
Minor nit
Browse files Browse the repository at this point in the history
  • Loading branch information
howardwu committed Feb 12, 2022
1 parent dd1cfb6 commit d8dab0d
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/rpc/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ mod tests {
/// Initializes a new instance of the ledger state.
fn new_ledger_state<N: Network, S: Storage, P: AsRef<Path>>(path: Option<P>) -> LedgerState<N> {
match path {
Some(path) => LedgerState::<N>::open_writer_inner::<S, _>(path, 1).expect("Failed to initialize ledger"),
None => LedgerState::<N>::open_writer_inner::<S, _>(temp_dir(), 1).expect("Failed to initialize ledger"),
Some(path) => LedgerState::<N>::open_writer_with_increment::<S, _>(path, 1).expect("Failed to initialize ledger"),
None => LedgerState::<N>::open_writer_with_increment::<S, _>(temp_dir(), 1).expect("Failed to initialize ledger"),
}
}

Expand Down
2 changes: 1 addition & 1 deletion storage/benches/insertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn insertion(c: &mut Criterion) {

// Prepare a test ledger and an iterator of blocks to insert.
let temp_dir = tempfile::tempdir().expect("Failed to open temporary directory").into_path();
let ledger = LedgerState::open_writer_inner::<RocksDB, _>(temp_dir, 1).expect("Failed to initialize ledger");
let ledger = LedgerState::open_writer_with_increment::<RocksDB, _>(temp_dir, 1).expect("Failed to initialize ledger");
let mut block_iter = blocks.iter();

c.bench_function("add_block", |b| {
Expand Down
2 changes: 1 addition & 1 deletion storage/benches/lookups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const NUM_BLOCKS: usize = 1_000;
fn lookups(c: &mut Criterion) {
// Prepare the test ledger.
let temp_dir = tempfile::tempdir().expect("Failed to open temporary directory").into_path();
let ledger = LedgerState::open_writer_inner::<RocksDB, _>(temp_dir, 1).expect("Failed to initialize ledger");
let ledger = LedgerState::open_writer_with_increment::<RocksDB, _>(temp_dir, 1).expect("Failed to initialize ledger");

// Read the test blocks; note: they don't include the genesis block, as it's always available when creating a ledger.
// note: the `blocks_100` and `blocks_1000` files were generated on a testnet2 storage using `LedgerState::dump_blocks`.
Expand Down
4 changes: 2 additions & 2 deletions storage/benches/opening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn opening(c: &mut Criterion) {
// Prepare a test ledger and insert all the test blocks.
let temp_dir = tempfile::tempdir().expect("Failed to open temporary directory").into_path();
{
let ledger = LedgerState::open_writer_inner::<RocksDB, _>(&temp_dir, 1).expect("Failed to initialize ledger");
let ledger = LedgerState::open_writer_with_increment::<RocksDB, _>(&temp_dir, 1).expect("Failed to initialize ledger");
for block in &blocks {
ledger.add_next_block(block).expect("Failed to add a test block");
}
Expand All @@ -42,7 +42,7 @@ fn opening(c: &mut Criterion) {
c.bench_function("Ledger::open_writer", |b| {
b.iter(|| {
let _ledger: LedgerState<Testnet2> =
LedgerState::open_writer_inner::<RocksDB, _>(&temp_dir, NUM_BLOCKS as u32).expect("Failed to initialize ledger");
LedgerState::open_writer_with_increment::<RocksDB, _>(&temp_dir, NUM_BLOCKS as u32).expect("Failed to initialize ledger");
})
});
}
Expand Down
4 changes: 2 additions & 2 deletions storage/src/state/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ impl<N: Network> LedgerState<N> {
/// a read-only instance of `LedgerState` may only call immutable methods.
///
pub fn open_writer<S: Storage, P: AsRef<Path>>(path: P) -> Result<Self> {
Self::open_writer_inner::<S, P>(path, 2_000)
Self::open_writer_with_increment::<S, P>(path, 2_000)
}

/// This function is hidden, as it's intended to be used directly in tests only.
/// The `validation_increment` parameter determines the number of blocks to be
/// handled during the incremental validation process.
#[doc(hidden)]
pub fn open_writer_inner<S: Storage, P: AsRef<Path>>(path: P, validation_increment: u32) -> Result<Self> {
pub fn open_writer_with_increment<S: Storage, P: AsRef<Path>>(path: P, validation_increment: u32) -> Result<Self> {
// Open storage.
let context = N::NETWORK_ID;
let is_read_only = false;
Expand Down
2 changes: 1 addition & 1 deletion storage/src/state/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn temp_dir() -> std::path::PathBuf {

/// Initializes a new instance of the ledger.
fn create_new_ledger<N: Network, S: Storage>() -> LedgerState<N> {
LedgerState::open_writer_inner::<S, _>(temp_dir(), 1).expect("Failed to initialize ledger")
LedgerState::open_writer_with_increment::<S, _>(temp_dir(), 1).expect("Failed to initialize ledger")
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions storage/tests/ledger_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn test_ledger_validation() {
// Prepare a test ledger and an iterator of blocks to insert.
let temp_dir = tempfile::tempdir().expect("Failed to open temporary directory").into_path();
{
let ledger = LedgerState::open_writer_inner::<RocksDB, _>(&temp_dir, 1).expect("Failed to initialize ledger");
let ledger = LedgerState::open_writer_with_increment::<RocksDB, _>(&temp_dir, 1).expect("Failed to initialize ledger");
for block in &blocks {
ledger.add_next_block(block).expect("Failed to add a test block");
}
Expand All @@ -50,6 +50,6 @@ fn test_ledger_validation() {
let increment: u32 = rng.gen_range(1..=NUM_BLOCKS as u32);
println!("Validating with an increment = {}", increment);
let _ledger: LedgerState<Testnet2> =
LedgerState::open_writer_inner::<RocksDB, &Path>(&temp_dir, increment).expect("Failed to initialize ledger");
LedgerState::open_writer_with_increment::<RocksDB, &Path>(&temp_dir, increment).expect("Failed to initialize ledger");
}
}

0 comments on commit d8dab0d

Please sign in to comment.