Skip to content

Commit 7c814f8

Browse files
authored
Remove system channels. (#3634)
## Motivation As of #3432 we are not using system channels anymore. ## Proposal Remove the `SystemChannel` type and any system channel-specific logic, in particular the "off-chain subscription handling". ## Test Plan The `social` example tests make sure that _user_ pub-sub channels still work. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent a3fc962 commit 7c814f8

File tree

18 files changed

+52
-280
lines changed

18 files changed

+52
-280
lines changed

linera-base/src/identifiers.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -418,34 +418,24 @@ pub struct ChannelName(
418418
/// A channel name together with its application ID.
419419
pub struct ChannelFullName {
420420
/// The application owning the channel.
421-
pub application_id: GenericApplicationId,
421+
pub application_id: ApplicationId,
422422
/// The name of the channel.
423423
pub name: ChannelName,
424424
}
425425

426426
impl fmt::Display for ChannelFullName {
427427
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
428428
let name = hex::encode(&self.name);
429-
match self.application_id {
430-
GenericApplicationId::System => write!(f, "system channel {name}"),
431-
GenericApplicationId::User(app_id) => write!(f, "user channel {name} for app {app_id}"),
432-
}
429+
let app_id = self.application_id;
430+
write!(f, "user channel {name} for app {app_id}")
433431
}
434432
}
435433

436434
impl ChannelFullName {
437-
/// Creates a full system channel name.
438-
pub fn system(name: ChannelName) -> Self {
439-
Self {
440-
application_id: GenericApplicationId::System,
441-
name,
442-
}
443-
}
444-
445435
/// Creates a full user channel name.
446-
pub fn user(name: ChannelName, application_id: ApplicationId) -> Self {
436+
pub fn new(name: ChannelName, application_id: ApplicationId) -> Self {
447437
Self {
448-
application_id: application_id.into(),
438+
application_id,
449439
name,
450440
}
451441
}

linera-chain/src/chain.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use linera_base::{
1818
},
1919
ensure,
2020
identifiers::{
21-
AccountOwner, ApplicationId, BlobType, ChainId, ChannelFullName, Destination, MessageId,
21+
AccountOwner, ApplicationId, BlobType, ChainId, ChannelFullName, Destination,
22+
GenericApplicationId, MessageId,
2223
},
2324
ownership::ChainOwnership,
2425
};
@@ -509,7 +510,7 @@ where
509510
bundle: MessageBundle,
510511
local_time: Timestamp,
511512
add_to_received_log: bool,
512-
) -> Result<bool, ChainError> {
513+
) -> Result<(), ChainError> {
513514
assert!(!bundle.messages.is_empty());
514515
let chain_id = self.chain_id();
515516
tracing::trace!(
@@ -520,8 +521,6 @@ where
520521
chain_id: origin.sender,
521522
height: bundle.height,
522523
};
523-
let mut subscribe_names_and_ids = Vec::new();
524-
let mut unsubscribe_names_and_ids = Vec::new();
525524

526525
// Handle immediate messages.
527526
for posted_message in &bundle.messages {
@@ -531,17 +530,8 @@ where
531530
self.execute_init_message(message_id, config, bundle.timestamp, local_time)
532531
.await?;
533532
}
534-
} else if let Some((id, subscription)) = posted_message.message.matches_subscribe() {
535-
let name = ChannelFullName::system(subscription.name.clone());
536-
subscribe_names_and_ids.push((name, *id));
537-
}
538-
if let Some((id, subscription)) = posted_message.message.matches_unsubscribe() {
539-
let name = ChannelFullName::system(subscription.name.clone());
540-
unsubscribe_names_and_ids.push((name, *id));
541533
}
542534
}
543-
self.process_unsubscribes(unsubscribe_names_and_ids).await?;
544-
let new_outbox_entries = self.process_subscribes(subscribe_names_and_ids).await?;
545535

546536
if bundle.goes_to_inbox() {
547537
// Process the inbox bundle and update the inbox state.
@@ -572,7 +562,7 @@ where
572562
if add_to_received_log {
573563
self.received_log.push(chain_and_height);
574564
}
575-
Ok(new_outbox_entries)
565+
Ok(())
576566
}
577567

578568
/// Updates the `received_log` trackers.
@@ -1192,8 +1182,15 @@ where
11921182
message.grant == Amount::ZERO,
11931183
ChainError::GrantUseOnBroadcast
11941184
);
1185+
let GenericApplicationId::User(application_id) =
1186+
message.message.application_id()
1187+
else {
1188+
return Err(ChainError::InternalError(
1189+
"System messages cannot be sent to channels".to_string(),
1190+
));
1191+
};
11951192
channel_broadcasts.insert(ChannelFullName {
1196-
application_id: message.message.application_id(),
1193+
application_id,
11971194
name: name.clone(),
11981195
});
11991196
}

linera-chain/src/data_types.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use linera_base::{
2020
hashed::Hashed,
2121
hex_debug,
2222
identifiers::{
23-
Account, AccountOwner, BlobId, ChainId, ChannelFullName, Destination, MessageId,
23+
Account, AccountOwner, BlobId, ChainId, ChannelFullName, Destination, GenericApplicationId,
24+
MessageId,
2425
},
2526
};
2627
use linera_execution::{
@@ -330,7 +331,10 @@ impl OutgoingMessageExt for OutgoingMessage {
330331
application_id,
331332
name,
332333
}),
333-
) => *application_id == self.message.application_id() && name == dest_name,
334+
) => {
335+
GenericApplicationId::User(*application_id) == self.message.application_id()
336+
&& name == dest_name
337+
}
334338
}
335339
}
336340

linera-core/src/chain_worker/actor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ where
125125
origin: Origin,
126126
bundles: Vec<(Epoch, MessageBundle)>,
127127
#[debug(skip)]
128-
callback: oneshot::Sender<Result<Option<(BlockHeight, NetworkActions)>, WorkerError>>,
128+
callback: oneshot::Sender<Result<Option<BlockHeight>, WorkerError>>,
129129
},
130130

131131
/// Handle cross-chain request to confirm that the recipient was updated.

linera-core/src/chain_worker/state/attempted_changes.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ where
440440
&mut self,
441441
origin: Origin,
442442
bundles: Vec<(Epoch, MessageBundle)>,
443-
) -> Result<Option<(BlockHeight, NetworkActions)>, WorkerError> {
443+
) -> Result<Option<BlockHeight>, WorkerError> {
444444
// Only process certificates with relevant heights and epochs.
445445
let next_height_to_receive = self
446446
.state
@@ -467,19 +467,14 @@ where
467467
// Process the received messages in certificates.
468468
let local_time = self.state.storage.clock().current_time();
469469
let mut previous_height = None;
470-
let mut new_outbox_entries = false;
471470
for bundle in bundles {
472471
let add_to_received_log = previous_height != Some(bundle.height);
473472
previous_height = Some(bundle.height);
474473
// Update the staged chain state with the received block.
475-
if self
476-
.state
474+
self.state
477475
.chain
478476
.receive_message_bundle(&origin, bundle, local_time, add_to_received_log)
479-
.await?
480-
{
481-
new_outbox_entries = true;
482-
}
477+
.await?;
483478
}
484479
if !self.state.config.allow_inactive_chains && !self.state.chain.is_active() {
485480
// Refuse to create a chain state if the chain is still inactive by
@@ -491,15 +486,9 @@ where
491486
);
492487
return Ok(None);
493488
}
494-
let actions = if new_outbox_entries {
495-
self.state.create_network_actions().await?
496-
} else {
497-
// Don't create network actions, so that old entries don't cause retry loops.
498-
NetworkActions::default()
499-
};
500489
// Save the chain.
501490
self.save().await?;
502-
Ok(Some((last_updated_height, actions)))
491+
Ok(Some(last_updated_height))
503492
}
504493

505494
/// Handles the cross-chain request confirming that the recipient was updated.

linera-core/src/chain_worker/state/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ where
274274
&mut self,
275275
origin: Origin,
276276
bundles: Vec<(Epoch, MessageBundle)>,
277-
) -> Result<Option<(BlockHeight, NetworkActions)>, WorkerError> {
277+
) -> Result<Option<BlockHeight>, WorkerError> {
278278
ChainWorkerStateWithAttemptedChanges::new(self)
279279
.await
280280
.process_cross_chain_update(origin, bundles)

linera-core/src/chain_worker/state/temporary_changes.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ use std::collections::HashMap;
88
use linera_base::{
99
data_types::{ApplicationDescription, ArithmeticError, Blob, Timestamp},
1010
ensure,
11-
identifiers::{AccountOwner, ApplicationId, ChannelFullName, GenericApplicationId},
11+
identifiers::{AccountOwner, ApplicationId},
1212
};
1313
use linera_chain::{
1414
data_types::{
15-
BlockExecutionOutcome, BlockProposal, ExecutedBlock, IncomingBundle, Medium, MessageAction,
15+
BlockExecutionOutcome, BlockProposal, ExecutedBlock, IncomingBundle, MessageAction,
1616
ProposalContent, ProposedBlock,
1717
},
1818
manager,
1919
};
20-
use linera_execution::{ChannelSubscription, Query, QueryOutcome};
20+
use linera_execution::{Query, QueryOutcome};
2121
use linera_storage::{Clock as _, Storage};
2222
use linera_views::views::{View, ViewError};
2323
#[cfg(with_testing)]
@@ -305,21 +305,7 @@ where
305305
} else {
306306
MessageAction::Accept
307307
};
308-
let subscriptions = &chain.execution_state.system.subscriptions;
309308
for (origin, inbox) in pairs {
310-
if let Medium::Channel(ChannelFullName {
311-
application_id: GenericApplicationId::System,
312-
name,
313-
}) = &origin.medium
314-
{
315-
let subscription = ChannelSubscription {
316-
chain_id: origin.sender,
317-
name: name.clone(),
318-
};
319-
if !subscriptions.contains(&subscription).await? {
320-
continue; // We are not subscribed to this channel.
321-
}
322-
}
323309
for bundle in inbox.added_bundles.elements().await? {
324310
messages.push(IncomingBundle {
325311
origin: origin.clone(),

linera-core/src/worker.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ where
608608
origin: Origin,
609609
recipient: ChainId,
610610
bundles: Vec<(Epoch, MessageBundle)>,
611-
) -> Result<Option<(BlockHeight, NetworkActions)>, WorkerError> {
611+
) -> Result<Option<BlockHeight>, WorkerError> {
612612
self.query_chain_worker(recipient, move |callback| {
613613
ChainWorkerRequest::ProcessCrossChainUpdate {
614614
origin,
@@ -988,11 +988,10 @@ where
988988
let mut actions = NetworkActions::default();
989989
for (medium, bundles) in bundle_vecs {
990990
let origin = Origin { sender, medium };
991-
if let Some((height, new_actions)) = self
991+
if let Some(height) = self
992992
.process_cross_chain_update(origin.clone(), recipient, bundles)
993993
.await?
994994
{
995-
actions.extend(new_actions);
996995
height_by_origin.push((origin, height));
997996
}
998997
}

linera-execution/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use linera_base::{
5050
};
5151
use linera_views::{batch::Batch, views::ViewError};
5252
use serde::{Deserialize, Serialize};
53-
use system::{AdminOperation, OpenChainConfig, SystemChannel};
53+
use system::{AdminOperation, OpenChainConfig};
5454
use thiserror::Error;
5555

5656
#[cfg(with_revm)]
@@ -314,12 +314,6 @@ pub enum ExecutionError {
314314
InvalidCommitteeEpoch { expected: Epoch, provided: Epoch },
315315
#[error("Failed to remove committee")]
316316
InvalidCommitteeRemoval,
317-
#[error("Cannot subscribe to a channel ({1}) on the same chain ({0})")]
318-
SelfSubscription(ChainId, SystemChannel),
319-
#[error("Chain {0} tried to subscribe to channel {1} but it is already subscribed")]
320-
AlreadySubscribedToChannel(ChainId, SystemChannel),
321-
#[error("Invalid unsubscription request to channel {1} on chain {0}")]
322-
InvalidUnsubscription(ChainId, SystemChannel),
323317
#[error("Amount overflow")]
324318
AmountOverflow,
325319
#[error("Amount underflow")]

linera-execution/src/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ impl ContractRuntime for ContractSyncRuntimeHandle {
12001200
fn subscribe(&mut self, chain: ChainId, name: ChannelName) -> Result<(), ExecutionError> {
12011201
let mut this = self.inner();
12021202
let application_id = this.current_application().id;
1203-
let full_name = ChannelFullName::user(name, application_id);
1203+
let full_name = ChannelFullName::new(name, application_id);
12041204
this.transaction_tracker.subscribe(full_name, chain);
12051205

12061206
Ok(())
@@ -1209,7 +1209,7 @@ impl ContractRuntime for ContractSyncRuntimeHandle {
12091209
fn unsubscribe(&mut self, chain: ChainId, name: ChannelName) -> Result<(), ExecutionError> {
12101210
let mut this = self.inner();
12111211
let application_id = this.current_application().id;
1212-
let full_name = ChannelFullName::user(name, application_id);
1212+
let full_name = ChannelFullName::new(name, application_id);
12131213
this.transaction_tracker.unsubscribe(full_name, chain);
12141214

12151215
Ok(())

0 commit comments

Comments
 (0)