Skip to content

Commit

Permalink
use SyncHandling variant instead of a flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Wójcik committed Nov 5, 2024
1 parent 245208d commit cac6aa9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
3 changes: 0 additions & 3 deletions node/src/reactor/main_reactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ pub(crate) struct MainReactor {

finality_signature_creation: bool,
prevent_validator_shutdown: bool,
catch_up_and_shutdown: bool,
}

impl reactor::Reactor for MainReactor {
Expand Down Expand Up @@ -1090,7 +1089,6 @@ impl reactor::Reactor for MainReactor {

let protocol_version = chainspec.protocol_config.version;
let prevent_validator_shutdown = config.value().node.prevent_validator_shutdown;
let catch_up_and_shutdown = config.value().node.catch_up_and_shutdown;

let trusted_hash = config.value().node.trusted_hash;
let (root_dir, config) = config.into_parts();
Expand Down Expand Up @@ -1278,7 +1276,6 @@ impl reactor::Reactor for MainReactor {
node_startup_instant,
finality_signature_creation: true,
prevent_validator_shutdown,
catch_up_and_shutdown,
};
info!("MainReactor: instantiated");

Expand Down
2 changes: 1 addition & 1 deletion node/src/reactor/main_reactor/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl MainReactor {
}
// shut down instead of switching to KeepUp if catch up and shutdown mode is
// enabled
if self.catch_up_and_shutdown {
if self.sync_handling.is_complete_block() {
info!("CatchUp: immediate shutdown after catching up");
self.state = ReactorState::ShutdownAfterCatchingUp;
(Duration::ZERO, Effects::new())
Expand Down
3 changes: 1 addition & 2 deletions node/src/reactor/main_reactor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,8 +1293,7 @@ async fn should_catch_up_and_shutdown() {
info!("joining node using block {trusted_height} {trusted_hash}");
let secret_key = SecretKey::random(&mut fixture.rng);
let (mut config, storage_dir) = fixture.create_node_config(&secret_key, Some(trusted_hash), 1);
config.node.sync_handling = SyncHandling::NoSync;
config.node.catch_up_and_shutdown = true;
config.node.sync_handling = SyncHandling::CompleteBlock;
let joiner_id = fixture
.add_node(Arc::new(secret_key), config, storage_dir)
.await;
Expand Down
12 changes: 8 additions & 4 deletions node/src/types/node_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ pub enum SyncHandling {
Ttl,
/// Don't attempt to sync historical blocks.
NoSync,
/// Don't attempt to sync historical blocks and shut down node instead of switching to KeepUp
/// after acquiring the first complete block
CompleteBlock,
}

impl SyncHandling {
Expand All @@ -37,6 +40,11 @@ impl SyncHandling {
pub fn is_no_sync(&self) -> bool {
matches!(self, SyncHandling::NoSync)
}

/// Don't Sync and shut down?
pub fn is_complete_block(&self) -> bool {
matches!(self, SyncHandling::CompleteBlock)
}
}

/// Node fast-sync configuration.
Expand Down Expand Up @@ -75,9 +83,6 @@ pub struct NodeConfig {

/// If true, prevents a node from shutting down if it is supposed to be a validator in the era.
pub prevent_validator_shutdown: bool,

/// Flag which forces node to shut down after initial sync is done
pub catch_up_and_shutdown: bool,
}

impl Default for NodeConfig {
Expand All @@ -92,7 +97,6 @@ impl Default for NodeConfig {
shutdown_for_upgrade_timeout: DEFAULT_SHUTDOWN_FOR_UPGRADE_TIMEOUT.parse().unwrap(),
upgrade_timeout: DEFAULT_UPGRADE_TIMEOUT.parse().unwrap(),
prevent_validator_shutdown: false,
catch_up_and_shutdown: false,
}
}
}

0 comments on commit cac6aa9

Please sign in to comment.