Skip to content

Commit

Permalink
A0-4260: Only support full sync mode (#1688)
Browse files Browse the repository at this point in the history
# Description

We don't really support other sync modes than `Full` for our node
anyway, so this changes the config and warns the user on startup.

## Type of change

- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)

# Checklist:

- I have created new documentation
  • Loading branch information
timorleph authored Apr 22, 2024
1 parent e29cb1f commit 4e89d71
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 7 deletions.
30 changes: 30 additions & 0 deletions bin/node/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::Cli;

mod pruning;
mod sync;

use pruning::PruningConfigValidator;
use sync::SyncConfigValidator;

/// Validate and modify the configuration to make it conform to our assumptions.
pub struct Validator {
pruning: PruningConfigValidator,
sync: SyncConfigValidator,
}

impl Validator {
/// Modifies the settings.
pub fn process(cli: &mut Cli) -> Self {
Validator {
pruning: PruningConfigValidator::process(cli),
sync: SyncConfigValidator::process(cli),
}
}

/// Warns the user about the modified settings.
pub fn report(self) {
let Validator { pruning, sync } = self;
pruning.report();
sync.report();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mod tests {
use sc_service::{BlocksPruning, PruningMode};

use super::PruningParams;
use crate::pruning_config::{DEFAULT_BLOCKS_PRUNING, DEFAULT_STATE_PRUNING};
use crate::config::pruning::{DEFAULT_BLOCKS_PRUNING, DEFAULT_STATE_PRUNING};

#[test]
fn pruning_sanity_check() {
Expand Down
31 changes: 31 additions & 0 deletions bin/node/src/config/sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use log::warn;
use sc_cli::arg_enums::SyncMode;

use crate::Cli;

/// Modifies the sync config to ensure only full sync is used.
pub struct SyncConfigValidator {
overwritten: Option<SyncMode>,
}

impl SyncConfigValidator {
/// Modifies the settings.
pub fn process(cli: &mut Cli) -> Self {
let overwritten = match cli.run.network_params.sync {
SyncMode::Full => None,
mode => Some(mode),
};
cli.run.network_params.sync = SyncMode::Full;
SyncConfigValidator { overwritten }
}

/// Warns the user if they attempted to use a sync setting other than full.
pub fn report(self) {
if let Some(mode) = self.overwritten {
warn!(
"Only full sync mode is supported, ignoring request for {:?} mode.",
mode
);
}
}
}
2 changes: 2 additions & 0 deletions bin/node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ mod aleph_cli;
mod aleph_node_rpc;
mod chain_spec;
mod cli;
mod config;
mod executor;
mod resources;
mod rpc;
mod service;

pub use cli::{Cli, Subcommand};
pub use config::Validator as ConfigValidator;
#[cfg(any(
feature = "runtime-benchmarks",
feature = "local-debugging",
Expand Down
9 changes: 3 additions & 6 deletions bin/node/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
mod pruning_config;

use aleph_node::{new_authority, new_partial, Cli, Subcommand};
use aleph_node::{new_authority, new_partial, Cli, ConfigValidator, Subcommand};
use log::info;
use primitives::HEAP_PAGES;
use pruning_config::PruningConfigValidator;
use sc_cli::{clap::Parser, SubstrateCli};
use sc_network::config::Role;
use sc_service::{Configuration, PartialComponents};
Expand All @@ -15,7 +12,7 @@ fn enforce_heap_pages(config: &mut Configuration) {
fn main() -> sc_cli::Result<()> {
let mut cli = Cli::parse();

let pruning_config_validation_result = PruningConfigValidator::process(&mut cli);
let config_validation_result = ConfigValidator::process(&mut cli);

match &cli.subcommand {
Some(Subcommand::BootstrapChain(cmd)) => cmd.run(),
Expand Down Expand Up @@ -142,7 +139,7 @@ fn main() -> sc_cli::Result<()> {
None => {
let runner = cli.create_runner(&cli.run)?;

pruning_config_validation_result.report();
config_validation_result.report();

let mut aleph_cli_config = cli.aleph;
runner.run_node_until_exit(|mut config| async move {
Expand Down

0 comments on commit 4e89d71

Please sign in to comment.