diff --git a/chain/client/src/client.rs b/chain/client/src/client.rs
index 6f499506f1c..3fed029324f 100644
--- a/chain/client/src/client.rs
+++ b/chain/client/src/client.rs
@@ -311,6 +311,7 @@ impl Client {
config.header_sync_progress_timeout,
config.header_sync_stall_ban_timeout,
config.header_sync_expected_height_per_second,
+ config.expected_shutdown.clone(),
);
let block_sync = BlockSync::new(
clock.clone(),
diff --git a/chain/client/src/client_actor.rs b/chain/client/src/client_actor.rs
index 65e913c4eb5..aee0a0ee1ef 100644
--- a/chain/client/src/client_actor.rs
+++ b/chain/client/src/client_actor.rs
@@ -1442,7 +1442,8 @@ impl ClientActorInner {
};
let peer_id = peer_info.peer_info.id.clone();
- let highest_height = peer_info.highest_block_height;
+ let shutdown_height = self.client.config.expected_shutdown.get().unwrap_or(u64::MAX);
+ let highest_height = peer_info.highest_block_height.min(shutdown_height);
if is_syncing {
if highest_height <= head.height {
diff --git a/chain/client/src/sync/header.rs b/chain/client/src/sync/header.rs
index 37ef69d9f33..e82e3d5ef40 100644
--- a/chain/client/src/sync/header.rs
+++ b/chain/client/src/sync/header.rs
@@ -59,6 +59,11 @@ pub struct HeaderSync {
/// Expected increase of header head height per second during header sync
expected_height_per_second: u64,
+
+ /// Not for production use.
+ /// Expected height when node will be automatically shut down, so header
+ /// sync can be stopped.
+ shutdown_height: near_chain_configs::MutableConfigValue