Skip to content

Commit ebc90d8

Browse files
authored
Create an option "linera service --pause" (#5927)
## Motivation Use `linera sync --next-height H` then query the state of the chain without adding any more blocks. ## Proposal Create an option `--pause` that skips the chain listener. ## Test Plan CI + tested manually ## Release Plan These changes should be backported to the latest `testnet` branch, then be released in a new SDK,
1 parent 94e03f2 commit ebc90d8

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

CLI.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,7 @@ Run a GraphQL service to explore and extend the chains of the wallet
781781
* `--query-cache-size <QUERY_CACHE_SIZE>` — Enable the application query response cache with the given per-chain capacity. Each entry stores a serialized GraphQL response keyed by (application_id, request_bytes). Incompatible with `--long-lived-services`
782782
* `--allow-subscription <ALLOWED_SUBSCRIPTIONS>` — Allow a named GraphQL subscription query. The operation name is extracted from the query string. Repeatable. Example: `--allow-subscription 'query CounterValue { getCounter { value } }'`
783783
* `--subscription-ttl-secs <SUBSCRIPTION_TTLS>` — Set a minimum TTL (in seconds) for a subscription query's cached result. When set, invalidations that arrive before the TTL expires are deferred until the remaining time elapses. Format: `Name=Secs`. Repeatable. Example: `--subscription-ttl-secs CounterValue=30`
784+
* `--pause` — Start in paused mode: do not synchronize chains from the network. The service will serve queries from local state only, without downloading new blocks or processing incoming messages
784785

785786

786787

linera-service/src/cli/command.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,12 @@ pub enum ClientCommand {
787787
/// Example: `--subscription-ttl-secs CounterValue=30`
788788
#[arg(long = "subscription-ttl-secs", value_parser = parse_subscription_ttl)]
789789
subscription_ttls: Vec<(String, u64)>,
790+
791+
/// Start in paused mode: do not synchronize chains from the network.
792+
/// The service will serve queries from local state only, without downloading
793+
/// new blocks or processing incoming messages.
794+
#[arg(long)]
795+
pause: bool,
790796
},
791797

792798
/// Query an application with a read-only GraphQL query.

linera-service/src/cli/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,7 @@ impl Runnable for Job {
12641264
query_cache_size,
12651265
allowed_subscriptions,
12661266
subscription_ttls,
1267+
pause,
12671268
} => {
12681269
let context = options
12691270
.create_client_context(storage, wallet, signer.into_value())
@@ -1362,6 +1363,7 @@ impl Runnable for Job {
13621363
query_subscriptions,
13631364
cancellation_token.clone(),
13641365
options.enable_memory_profiling(),
1366+
pause,
13651367
);
13661368
service.run(cancellation_token, command_receiver).await?;
13671369
}

linera-service/src/node_service.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,8 @@ where
12491249
query_subscriptions: Option<Arc<crate::query_subscription::QuerySubscriptionManager>>,
12501250
cancellation_token: CancellationToken,
12511251
enable_memory_profiling: bool,
1252+
/// If true, do not start the chain listener; serve queries from local state only.
1253+
pause: bool,
12521254
}
12531255

12541256
impl<C> Clone for NodeService<C>
@@ -1268,6 +1270,7 @@ where
12681270
query_subscriptions: self.query_subscriptions.clone(),
12691271
cancellation_token: self.cancellation_token.clone(),
12701272
enable_memory_profiling: self.enable_memory_profiling,
1273+
pause: self.pause,
12711274
}
12721275
}
12731276
}
@@ -1293,6 +1296,7 @@ where
12931296
query_subscriptions: Option<Arc<crate::query_subscription::QuerySubscriptionManager>>,
12941297
cancellation_token: CancellationToken,
12951298
enable_memory_profiling: bool,
1299+
pause: bool,
12961300
) -> Self {
12971301
let query_cache = query_cache_size.map(|size| Arc::new(QueryResponseCache::new(size)));
12981302
Self {
@@ -1307,6 +1311,7 @@ where
13071311
query_subscriptions,
13081312
cancellation_token,
13091313
enable_memory_profiling,
1314+
pause,
13101315
}
13111316
}
13121317

@@ -1408,28 +1413,33 @@ where
14081413
});
14091414
}
14101415

1411-
let storage = self.context.lock().await.storage().clone();
1412-
1413-
let chain_listener = ChainListener::new(
1414-
self.config,
1415-
self.context,
1416-
storage,
1417-
cancellation_token.clone(),
1418-
command_receiver,
1419-
true,
1420-
)
1421-
.run()
1422-
.await?;
1423-
let mut chain_listener = Box::pin(chain_listener).fuse();
14241416
let tcp_listener =
14251417
tokio::net::TcpListener::bind(SocketAddr::from(([0, 0, 0, 0], port))).await?;
14261418
let server = axum::serve(tcp_listener, app)
1427-
.with_graceful_shutdown(cancellation_token.cancelled_owned())
1419+
.with_graceful_shutdown(cancellation_token.clone().cancelled_owned())
14281420
.into_future();
1429-
futures::select! {
1430-
result = chain_listener => result?,
1431-
result = Box::pin(server).fuse() => result?,
1432-
};
1421+
1422+
if self.pause {
1423+
info!("Running in paused mode: chain synchronization is disabled");
1424+
server.await?;
1425+
} else {
1426+
let storage = self.context.lock().await.storage().clone();
1427+
let chain_listener = ChainListener::new(
1428+
self.config,
1429+
self.context,
1430+
storage,
1431+
cancellation_token.clone(),
1432+
command_receiver,
1433+
true,
1434+
)
1435+
.run()
1436+
.await?;
1437+
let mut chain_listener = Box::pin(chain_listener).fuse();
1438+
futures::select! {
1439+
result = chain_listener => result?,
1440+
result = Box::pin(server).fuse() => result?,
1441+
};
1442+
}
14331443

14341444
Ok(())
14351445
}

linera-service/src/schema_export.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ async fn main() -> std::io::Result<()> {
256256
None,
257257
tokio_util::sync::CancellationToken::new(),
258258
false, // memory profiling disabled for schema export
259+
false, // not paused
259260
);
260261
let schema = service.schema().sdl();
261262
print!("{}", schema);

0 commit comments

Comments
 (0)