Skip to content

Commit 4e89d71

Browse files
authored
A0-4260: Only support full sync mode (#1688)
# 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
1 parent e29cb1f commit 4e89d71

File tree

5 files changed

+67
-7
lines changed

5 files changed

+67
-7
lines changed

bin/node/src/config/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::Cli;
2+
3+
mod pruning;
4+
mod sync;
5+
6+
use pruning::PruningConfigValidator;
7+
use sync::SyncConfigValidator;
8+
9+
/// Validate and modify the configuration to make it conform to our assumptions.
10+
pub struct Validator {
11+
pruning: PruningConfigValidator,
12+
sync: SyncConfigValidator,
13+
}
14+
15+
impl Validator {
16+
/// Modifies the settings.
17+
pub fn process(cli: &mut Cli) -> Self {
18+
Validator {
19+
pruning: PruningConfigValidator::process(cli),
20+
sync: SyncConfigValidator::process(cli),
21+
}
22+
}
23+
24+
/// Warns the user about the modified settings.
25+
pub fn report(self) {
26+
let Validator { pruning, sync } = self;
27+
pruning.report();
28+
sync.report();
29+
}
30+
}

bin/node/src/pruning_config.rs renamed to bin/node/src/config/pruning.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ mod tests {
140140
use sc_service::{BlocksPruning, PruningMode};
141141

142142
use super::PruningParams;
143-
use crate::pruning_config::{DEFAULT_BLOCKS_PRUNING, DEFAULT_STATE_PRUNING};
143+
use crate::config::pruning::{DEFAULT_BLOCKS_PRUNING, DEFAULT_STATE_PRUNING};
144144

145145
#[test]
146146
fn pruning_sanity_check() {

bin/node/src/config/sync.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use log::warn;
2+
use sc_cli::arg_enums::SyncMode;
3+
4+
use crate::Cli;
5+
6+
/// Modifies the sync config to ensure only full sync is used.
7+
pub struct SyncConfigValidator {
8+
overwritten: Option<SyncMode>,
9+
}
10+
11+
impl SyncConfigValidator {
12+
/// Modifies the settings.
13+
pub fn process(cli: &mut Cli) -> Self {
14+
let overwritten = match cli.run.network_params.sync {
15+
SyncMode::Full => None,
16+
mode => Some(mode),
17+
};
18+
cli.run.network_params.sync = SyncMode::Full;
19+
SyncConfigValidator { overwritten }
20+
}
21+
22+
/// Warns the user if they attempted to use a sync setting other than full.
23+
pub fn report(self) {
24+
if let Some(mode) = self.overwritten {
25+
warn!(
26+
"Only full sync mode is supported, ignoring request for {:?} mode.",
27+
mode
28+
);
29+
}
30+
}
31+
}

bin/node/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ mod aleph_cli;
22
mod aleph_node_rpc;
33
mod chain_spec;
44
mod cli;
5+
mod config;
56
mod executor;
67
mod resources;
78
mod rpc;
89
mod service;
910

1011
pub use cli::{Cli, Subcommand};
12+
pub use config::Validator as ConfigValidator;
1113
#[cfg(any(
1214
feature = "runtime-benchmarks",
1315
feature = "local-debugging",

bin/node/src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
mod pruning_config;
2-
3-
use aleph_node::{new_authority, new_partial, Cli, Subcommand};
1+
use aleph_node::{new_authority, new_partial, Cli, ConfigValidator, Subcommand};
42
use log::info;
53
use primitives::HEAP_PAGES;
6-
use pruning_config::PruningConfigValidator;
74
use sc_cli::{clap::Parser, SubstrateCli};
85
use sc_network::config::Role;
96
use sc_service::{Configuration, PartialComponents};
@@ -15,7 +12,7 @@ fn enforce_heap_pages(config: &mut Configuration) {
1512
fn main() -> sc_cli::Result<()> {
1613
let mut cli = Cli::parse();
1714

18-
let pruning_config_validation_result = PruningConfigValidator::process(&mut cli);
15+
let config_validation_result = ConfigValidator::process(&mut cli);
1916

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

145-
pruning_config_validation_result.report();
142+
config_validation_result.report();
146143

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

0 commit comments

Comments
 (0)