Skip to content

Commit

Permalink
refactor!: remove max prefix from blocks_in_memory (#5145)
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
  • Loading branch information
mversic authored Oct 14, 2024
1 parent 82b723d commit a5ea8e5
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion crates/iroha_config/src/parameters/actual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub struct Queue {
pub struct Kura {
pub init_mode: InitMode,
pub store_dir: WithOrigin<PathBuf>,
pub max_blocks_in_memory: NonZeroUsize,
pub blocks_in_memory: NonZeroUsize,
pub debug_output_new_blocks: bool,
}

Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_config/src/parameters/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod kura {
use nonzero_ext::nonzero;

pub const STORE_DIR: &str = "./storage";
pub const MAX_BLOCKS_IN_MEMORY: NonZeroUsize = nonzero!(128_usize);
pub const BLOCKS_IN_MEMORY: NonZeroUsize = nonzero!(128_usize);
}

pub mod network {
Expand Down
10 changes: 5 additions & 5 deletions crates/iroha_config/src/parameters/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ pub struct Kura {
)]
pub store_dir: WithOrigin<PathBuf>,
#[config(
env = "KURA_MAX_BLOCKS_IN_MEMORY",
default = "defaults::kura::MAX_BLOCKS_IN_MEMORY"
env = "KURA_BLOCKS_IN_MEMORY",
default = "defaults::kura::BLOCKS_IN_MEMORY"
)]
pub max_blocks_in_memory: NonZeroUsize,
pub blocks_in_memory: NonZeroUsize,
#[config(nested)]
pub debug: KuraDebug,
}
Expand All @@ -195,7 +195,7 @@ impl Kura {
let Self {
init_mode,
store_dir,
max_blocks_in_memory,
blocks_in_memory,
debug:
KuraDebug {
output_new_blocks: debug_output_new_blocks,
Expand All @@ -205,7 +205,7 @@ impl Kura {
actual::Kura {
init_mode,
store_dir,
max_blocks_in_memory,
blocks_in_memory,
debug_output_new_blocks,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_config/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn minimal_config_snapshot() {
id: ParameterId(kura.store_dir),
},
},
max_blocks_in_memory: 128,
blocks_in_memory: 128,
debug_output_new_blocks: false,
},
sumeragi: Sumeragi {
Expand Down
2 changes: 1 addition & 1 deletion crates/iroha_config/tests/fixtures/full.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GENESIS=./genesis.signed.scale
API_ADDRESS=127.0.0.1:8080
KURA_INIT_MODE=strict
KURA_STORE_DIR=/store/path/from/env
KURA_MAX_BLOCKS_IN_MEMORY=128
KURA_BLOCKS_IN_MEMORY=128
KURA_DEBUG_OUTPUT_NEW_BLOCKS=false
LOG_LEVEL=DEBUG
LOG_FORMAT=pretty
Expand Down
1 change: 1 addition & 0 deletions crates/iroha_config/tests/fixtures/full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ query_store_capacity_per_user = 128
[kura]
init_mode = "strict"
store_dir = "./storage"
blocks_in_memory = 128

[kura.debug]
output_new_blocks = true
Expand Down
4 changes: 2 additions & 2 deletions crates/iroha_core/benches/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use byte_unit::{Byte, UnitType};
use criterion::{criterion_group, criterion_main, Criterion};
use iroha_config::{
base::WithOrigin,
parameters::{actual::Kura as Config, defaults::kura::MAX_BLOCKS_IN_MEMORY},
parameters::{actual::Kura as Config, defaults::kura::BLOCKS_IN_MEMORY},
};
use iroha_core::{
block::*,
Expand All @@ -25,7 +25,7 @@ async fn measure_block_size_for_n_executors(n_executors: u32) {
let cfg = Config {
init_mode: iroha_config::kura::InitMode::Strict,
debug_output_new_blocks: false,
max_blocks_in_memory: MAX_BLOCKS_IN_MEMORY,
blocks_in_memory: BLOCKS_IN_MEMORY,
store_dir: WithOrigin::inline(dir.path().to_path_buf()),
};
let chain_id = ChainId::from("00000000-0000-0000-0000-000000000000");
Expand Down
26 changes: 13 additions & 13 deletions crates/iroha_core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::{

use iroha_config::{
kura::InitMode,
parameters::{actual::Kura as Config, defaults::kura::MAX_BLOCKS_IN_MEMORY},
parameters::{actual::Kura as Config, defaults::kura::BLOCKS_IN_MEMORY},
};
use iroha_crypto::{Hash, HashOf};
use iroha_data_model::block::{BlockHeader, SignedBlock};
Expand Down Expand Up @@ -42,7 +42,7 @@ pub struct Kura {
block_plain_text_path: Option<PathBuf>,
/// At most N last blocks will be stored in memory.
/// Older blocks will be dropped from memory and loaded from the disk if they are needed.
max_blocks_in_memory: NonZeroUsize,
blocks_in_memory: NonZeroUsize,
/// Amount of blocks loaded during initialization
init_block_count: usize,
}
Expand Down Expand Up @@ -74,7 +74,7 @@ impl Kura {
block_store: Mutex::new(block_store),
block_data: Mutex::new(block_data),
block_plain_text_path,
max_blocks_in_memory: config.max_blocks_in_memory,
blocks_in_memory: config.blocks_in_memory,
init_block_count: block_count,
});

Expand All @@ -88,7 +88,7 @@ impl Kura {
block_store: Mutex::new(BlockStore::new(PathBuf::new())),
block_data: Mutex::new(Vec::new()),
block_plain_text_path: None,
max_blocks_in_memory: MAX_BLOCKS_IN_MEMORY,
blocks_in_memory: BLOCKS_IN_MEMORY,
init_block_count: 0,
})
}
Expand Down Expand Up @@ -242,7 +242,7 @@ impl Kura {
Self::drop_old_block(
&mut block_data,
written_block_count,
kura.max_blocks_in_memory.get(),
kura.blocks_in_memory.get(),
);
written_block_count += 1;
}
Expand Down Expand Up @@ -332,7 +332,7 @@ impl Kura {

let block_arc = Arc::new(block);
// Only last N blocks should be kept in memory
if block_index + self.max_blocks_in_memory.get() >= data_array_guard.len() {
if block_index + self.blocks_in_memory.get() >= data_array_guard.len() {
data_array_guard[block_index].1 = Some(Arc::clone(&block_arc));
}
Some(block_arc)
Expand All @@ -357,12 +357,12 @@ impl Kura {
fn drop_old_block(
block_data: &mut BlockData,
written_block_count: usize,
max_blocks_in_memory: usize,
blocks_in_memory: usize,
) {
// Keep last N blocks and genesis block.
// (genesis block is used in metrics to get genesis timestamp)
if written_block_count > max_blocks_in_memory {
block_data[written_block_count - max_blocks_in_memory].1 = None;
if written_block_count > blocks_in_memory {
block_data[written_block_count - blocks_in_memory].1 = None;
}
}
}
Expand Down Expand Up @@ -810,7 +810,7 @@ impl<T> AddErrContextExt<T> for Result<T, std::io::Error> {
mod tests {
use std::{str::FromStr, thread, time::Duration};

use iroha_config::parameters::defaults::kura::MAX_BLOCKS_IN_MEMORY;
use iroha_config::parameters::defaults::kura::BLOCKS_IN_MEMORY;
use iroha_crypto::KeyPair;
use iroha_data_model::{
account::Account,
Expand Down Expand Up @@ -1009,7 +1009,7 @@ mod tests {
store_dir: iroha_config::base::WithOrigin::inline(
temp_dir.path().to_str().unwrap().into(),
),
max_blocks_in_memory: MAX_BLOCKS_IN_MEMORY,
blocks_in_memory: BLOCKS_IN_MEMORY,
debug_output_new_blocks: false,
})
.unwrap();
Expand Down Expand Up @@ -1039,7 +1039,7 @@ mod tests {
store_dir: iroha_config::base::WithOrigin::inline(
temp_dir.path().to_str().unwrap().into(),
),
max_blocks_in_memory: MAX_BLOCKS_IN_MEMORY,
blocks_in_memory: BLOCKS_IN_MEMORY,
debug_output_new_blocks: false,
})
.unwrap();
Expand Down Expand Up @@ -1091,7 +1091,7 @@ mod tests {
store_dir: iroha_config::base::WithOrigin::inline(
temp_dir.path().to_str().unwrap().into(),
),
max_blocks_in_memory: MAX_BLOCKS_IN_MEMORY,
blocks_in_memory: BLOCKS_IN_MEMORY,
debug_output_new_blocks: false,
})
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions docs/source/references/peer.template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
[kura]
# init_mode = "strict"
# store_dir = "./storage"
# blocks_in_memory = 128

## Add more of this section for each trusted peer
# [[sumeragi.trusted_peers]]
Expand Down

0 comments on commit a5ea8e5

Please sign in to comment.