Skip to content

Commit

Permalink
path override
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-aranha-cw committed Jun 7, 2024
1 parent bf4de85 commit 5351b5d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
7 changes: 6 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,11 @@ pub struct PermanentStorageConfig {
/// Permamenent storage timeout when opening a connection (in millis).
#[arg(long = "perm-storage-timeout", value_parser=parse_duration, env = "PERM_STORAGE_TIMEOUT")]
pub perm_storage_timeout: Duration,

#[cfg(feature = "rocks")]
/// RocksDB storage path prefix to execute multiple local Stratus instances.
#[arg(long = "rocks-path-prefix", env = "ROCKS_PATH_PREFIX", default_value = "")]
pub rocks_path_prefix: Option<String>,
}

#[derive(DebugAsJson, Clone, serde::Serialize)]
Expand All @@ -856,7 +861,7 @@ impl PermanentStorageConfig {
let perm: Arc<dyn PermanentStorage> = match self.perm_storage_kind {
PermanentStorageKind::InMemory => Arc::new(InMemoryPermanentStorage::default()),
#[cfg(feature = "rocks")]
PermanentStorageKind::Rocks => Arc::new(RocksPermanentStorage::new().await?),
PermanentStorageKind::Rocks => Arc::new(RocksPermanentStorage::new(self.rocks_path_prefix.clone()).await?),
PermanentStorageKind::Postgres { ref url } => {
let config = PostgresPermanentStorageConfig {
url: url.to_owned(),
Expand Down
2 changes: 1 addition & 1 deletion src/eth/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl Consensus {
socket.connect("8.8.8.8:80").ok().unwrap();
let my_ip = socket.local_addr().ok().map(|addr| addr.ip().to_string()).unwrap();

PeerAddress::new(format!("http://{}", my_ip), jsonrpc_port, grpc_port) //FIXME TODO pick ports from config
PeerAddress::new(format!("http://{}", my_ip), jsonrpc_port, grpc_port)
}

/// Initializes the heartbeat and election timers.
Expand Down
4 changes: 2 additions & 2 deletions src/eth/storage/rocks/rocks_permanent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ pub struct RocksPermanentStorage {
}

impl RocksPermanentStorage {
pub async fn new() -> anyhow::Result<Self> {
pub async fn new(rocks_path_prefix: Option<String>) -> anyhow::Result<Self> {
tracing::info!("creating rocksdb storage");

let state = RocksStorageState::new();
let state = RocksStorageState::new(rocks_path_prefix);
state.sync_data().await?;
let block_number = state.preload_block_number()?;
Ok(Self { state, block_number })
Expand Down
29 changes: 12 additions & 17 deletions src/eth/storage/rocks/rocks_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,28 @@ pub struct RocksStorageState {
pub backup_trigger: Arc<mpsc::Sender<()>>,
}

impl Default for RocksStorageState {
fn default() -> Self {
impl RocksStorageState {
pub fn new(rocks_path_prefix: Option<String>) -> Self {
let (tx, rx) = mpsc::channel::<()>(1);

//XXX TODO while repair/restore from backup, make sure to sync online and only when its in sync with other nodes, receive requests
let path_prefix = rocks_path_prefix.unwrap_or_else(|| "".to_string());

let state = Self {
accounts: RocksDb::new("./data/accounts.rocksdb", DbConfig::Default).unwrap(),
accounts_history: RocksDb::new("./data/accounts_history.rocksdb", DbConfig::FastWriteSST).unwrap(),
account_slots: RocksDb::new("./data/account_slots.rocksdb", DbConfig::Default).unwrap(),
account_slots_history: RocksDb::new("./data/account_slots_history.rocksdb", DbConfig::FastWriteSST).unwrap(),
transactions: RocksDb::new("./data/transactions.rocksdb", DbConfig::LargeSSTFiles).unwrap(),
blocks_by_number: RocksDb::new("./data/blocks_by_number.rocksdb", DbConfig::LargeSSTFiles).unwrap(),
blocks_by_hash: RocksDb::new("./data/blocks_by_hash.rocksdb", DbConfig::LargeSSTFiles).unwrap(), //XXX this is not needed we can afford to have blocks_by_hash pointing into blocks_by_number
logs: RocksDb::new("./data/logs.rocksdb", DbConfig::LargeSSTFiles).unwrap(),
accounts: RocksDb::new(&format!("{}./data/accounts.rocksdb", path_prefix), DbConfig::Default).unwrap(),
accounts_history: RocksDb::new(&format!("{}./data/accounts_history.rocksdb", path_prefix), DbConfig::FastWriteSST).unwrap(),
account_slots: RocksDb::new(&format!("{}./data/account_slots.rocksdb", path_prefix), DbConfig::Default).unwrap(),
account_slots_history: RocksDb::new(&format!("{}./data/account_slots_history.rocksdb", path_prefix), DbConfig::FastWriteSST).unwrap(),
transactions: RocksDb::new(&format!("{}./data/transactions.rocksdb", path_prefix), DbConfig::LargeSSTFiles).unwrap(),
blocks_by_number: RocksDb::new(&format!("{}./data/blocks_by_number.rocksdb", path_prefix), DbConfig::LargeSSTFiles).unwrap(),
blocks_by_hash: RocksDb::new(&format!("{}./data/blocks_by_hash.rocksdb", path_prefix), DbConfig::LargeSSTFiles).unwrap(),
logs: RocksDb::new(&format!("{}./data/logs.rocksdb", path_prefix), DbConfig::LargeSSTFiles).unwrap(),
backup_trigger: Arc::new(tx),
};

state.listen_for_backup_trigger(rx).unwrap();

state
}
}

impl RocksStorageState {
pub fn new() -> Self {
Self::default()
}

pub fn listen_for_backup_trigger(&self, mut rx: mpsc::Receiver<()>) -> anyhow::Result<()> {
tracing::info!("creating backup trigger listener");
Expand Down

0 comments on commit 5351b5d

Please sign in to comment.