@@ -77,6 +77,38 @@ pub const DEFAULT_RPC_WS_PORT: u16 = 8546;
7777/// Default metrics port (Prometheus standard)
7878pub const DEFAULT_METRICS_PORT : u16 = 9100 ;
7979
80+ /// Default snap sync enabled setting
81+ pub const DEFAULT_SNAP_SYNC_ENABLED : bool = true ;
82+
83+ /// Default minimum peers required to start sync
84+ pub const DEFAULT_MIN_SYNC_PEERS : usize = 3 ;
85+
86+ /// Default sync request timeout in seconds
87+ pub const DEFAULT_SYNC_TIMEOUT_SECS : u64 = 30 ;
88+
89+ /// Default block gap threshold to trigger snap sync (vs block-by-block)
90+ pub const DEFAULT_SNAP_SYNC_THRESHOLD : u64 = 1024 ;
91+
92+ /// Serde default function for snap_sync_enabled
93+ fn default_snap_sync_enabled ( ) -> bool {
94+ DEFAULT_SNAP_SYNC_ENABLED
95+ }
96+
97+ /// Serde default function for min_sync_peers
98+ fn default_min_sync_peers ( ) -> usize {
99+ DEFAULT_MIN_SYNC_PEERS
100+ }
101+
102+ /// Serde default function for sync_timeout
103+ fn default_sync_timeout ( ) -> u64 {
104+ DEFAULT_SYNC_TIMEOUT_SECS
105+ }
106+
107+ /// Serde default function for snap_sync_threshold
108+ fn default_snap_sync_threshold ( ) -> u64 {
109+ DEFAULT_SNAP_SYNC_THRESHOLD
110+ }
111+
80112/// Serde default function for rpc_http_port
81113fn default_rpc_http_port ( ) -> u16 {
82114 DEFAULT_RPC_HTTP_PORT
@@ -109,6 +141,52 @@ pub struct PeerConfig {
109141 pub worker_addrs : Vec < SocketAddr > ,
110142}
111143
144+ /// Sync configuration for state synchronization
145+ ///
146+ /// Controls how the node performs snap sync when joining the network
147+ /// or recovering from being behind.
148+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
149+ pub struct SyncConfig {
150+ /// Enable snap sync for fast bootstrap.
151+ ///
152+ /// When enabled, nodes that are significantly behind will use snap sync
153+ /// to download state directly rather than replaying all blocks.
154+ #[ serde( default = "default_snap_sync_enabled" ) ]
155+ pub snap_sync_enabled : bool ,
156+
157+ /// Minimum peers required to start sync.
158+ ///
159+ /// The node will wait until it has at least this many peers with
160+ /// consistent state before beginning snap sync.
161+ #[ serde( default = "default_min_sync_peers" ) ]
162+ pub min_sync_peers : usize ,
163+
164+ /// Sync request timeout in seconds.
165+ ///
166+ /// Maximum time to wait for a response to a sync request before
167+ /// retrying with a different peer.
168+ #[ serde( default = "default_sync_timeout" ) ]
169+ pub sync_timeout_secs : u64 ,
170+
171+ /// Block gap threshold to trigger snap sync (vs block-by-block).
172+ ///
173+ /// If the node is behind by more than this many blocks, it will
174+ /// use snap sync. Otherwise, it will sync block-by-block.
175+ #[ serde( default = "default_snap_sync_threshold" ) ]
176+ pub snap_sync_threshold : u64 ,
177+ }
178+
179+ impl Default for SyncConfig {
180+ fn default ( ) -> Self {
181+ Self {
182+ snap_sync_enabled : DEFAULT_SNAP_SYNC_ENABLED ,
183+ min_sync_peers : DEFAULT_MIN_SYNC_PEERS ,
184+ sync_timeout_secs : DEFAULT_SYNC_TIMEOUT_SECS ,
185+ snap_sync_threshold : DEFAULT_SNAP_SYNC_THRESHOLD ,
186+ }
187+ }
188+ }
189+
112190/// Node configuration
113191///
114192/// Keys are loaded from the keyring backend specified by `keyring_backend`.
@@ -199,6 +277,13 @@ pub struct NodeConfig {
199277 /// Port for Prometheus metrics endpoint (default: 9100)
200278 #[ serde( default = "default_metrics_port" ) ]
201279 pub metrics_port : u16 ,
280+
281+ /// Sync configuration for state synchronization.
282+ ///
283+ /// Controls snap sync behavior for fast bootstrap when joining
284+ /// the network or recovering from being behind.
285+ #[ serde( default ) ]
286+ pub sync : SyncConfig ,
202287}
203288
204289/// Test configuration with keypairs for local testing
@@ -253,6 +338,7 @@ impl NodeConfig {
253338 rpc_http_port : DEFAULT_RPC_HTTP_PORT + ( index as u16 ) ,
254339 rpc_ws_port : DEFAULT_RPC_WS_PORT + ( index as u16 ) ,
255340 metrics_port : DEFAULT_METRICS_PORT + ( index as u16 ) ,
341+ sync : SyncConfig :: default ( ) ,
256342 } ;
257343
258344 LocalTestConfig {
0 commit comments