Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ add maintenance mode to node #389

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions client/blockchain-service/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ where
///
/// Only required if the node is running as a provider.
pub(crate) capacity_manager: Option<CapacityRequestQueue>,
/// Whether the node is running in maintenance mode.
pub(crate) maintenance_mode: bool,
}

/// Event loop for the BlockchainService actor.
Expand Down Expand Up @@ -216,6 +218,12 @@ where
message: Self::Message,
) -> impl std::future::Future<Output = ()> + Send {
async {
// If the node is running in maintenance mode, we don't process any messages.
if self.maintenance_mode {
info!(target: LOG_TARGET, "🔒 Maintenance mode is enabled. Skipping message processing.");
return;
}

match message {
BlockchainServiceCommand::SendExtrinsic {
call,
Expand Down Expand Up @@ -1115,6 +1123,7 @@ where
rocksdb_root_path: impl Into<PathBuf>,
notify_period: Option<u32>,
capacity_request_queue: Option<CapacityRequestQueue>,
maintenance_mode: bool,
) -> Self {
Self {
event_bus_provider: BlockchainServiceEventBusProvider::new(),
Expand All @@ -1130,6 +1139,7 @@ where
persistent_state: BlockchainServiceStateStore::new(rocksdb_root_path.into()),
notify_period,
capacity_manager: capacity_request_queue,
maintenance_mode,
}
}

Expand Down Expand Up @@ -1285,6 +1295,12 @@ where
) where
Block: cumulus_primitives_core::BlockT<Hash = H256>,
{
// If the node is running in maintenance mode, we don't process block imports.
if self.maintenance_mode {
info!(target: LOG_TARGET, "🔒 Maintenance mode is enabled. Skipping processing ofblock import #{}: {}", block_number, block_hash);
return;
}

trace!(target: LOG_TARGET, "📠 Processing block import #{}: {}", block_number, block_hash);

// Provider-specific code to run on every block import.
Expand Down Expand Up @@ -1377,6 +1393,12 @@ where
let block_hash: H256 = notification.hash;
let block_number: BlockNumber = (*notification.header.number()).saturated_into();

// If the node is running in maintenance mode, we don't process finality notifications.
if self.maintenance_mode {
info!(target: LOG_TARGET, "🔒 Maintenance mode is enabled. Skipping finality notification #{}: {}", block_number, block_hash);
return;
}

info!(target: LOG_TARGET, "📨 Finality notification #{}: {}", block_number, block_hash);

// Get events from storage.
Expand Down
2 changes: 2 additions & 0 deletions client/blockchain-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub async fn spawn_blockchain_service<FSH>(
rocksdb_root_path: impl Into<PathBuf>,
notify_period: Option<u32>,
capacity_config: Option<CapacityConfig>,
maintenance_mode: bool,
) -> ActorHandle<BlockchainService<FSH>>
where
FSH: shc_forest_manager::traits::ForestStorageHandler + Clone + Send + Sync + 'static,
Expand All @@ -46,6 +47,7 @@ where
rocksdb_root_path,
notify_period,
capacity_config.map(CapacityRequestQueue::new),
maintenance_mode,
);

task_spawner.spawn_actor(blockchain_service)
Expand Down
7 changes: 7 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ pub struct ProviderConfigurations {
#[arg(long)]
pub provider: bool,

/// Run the node in maintenance mode.
/// In this mode, the node will not import blocks or participate in consensus,
/// but will allow specific RPC calls for file and storage management.
#[arg(long, default_value = "false")]
pub maintenance_mode: bool,

/// Type of StorageHub provider.
#[clap(
long,
Expand Down Expand Up @@ -173,6 +179,7 @@ impl ProviderConfigurations {
jump_capacity: self.jump_capacity,
extrinsic_retry_timeout: self.extrinsic_retry_timeout,
msp_charging_period: self.msp_charging_period,
maintenance_mode: self.maintenance_mode,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub struct ProviderOptions {
pub extrinsic_retry_timeout: u64,
/// MSP charging fees frequency.
pub msp_charging_period: Option<u32>,
/// Whether the node is running in maintenance mode.
pub maintenance_mode: bool,
}

fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
Expand Down
Loading
Loading