Skip to content

Commit bb684d0

Browse files
authored
Remove unused Subscribe and Unsubscribe messages. (#3636)
## Motivation `SystemMessage::Subscribe` and `Unsubscribe` were only used for system channels, which are now gone. ## Proposal Remove them, and the `subscribers` collection in the system execution state view. ## Test Plan CI ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - System channels were removed in #3634. - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent fb51e45 commit bb684d0

File tree

13 files changed

+36
-220
lines changed

13 files changed

+36
-220
lines changed

linera-chain/src/chain.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -532,30 +532,27 @@ where
532532
}
533533
}
534534
}
535-
536-
if bundle.goes_to_inbox() {
537-
// Process the inbox bundle and update the inbox state.
538-
let mut inbox = self.inboxes.try_load_entry_mut(origin).await?;
539-
#[cfg(with_metrics)]
540-
NUM_INBOXES
541-
.with_label_values(&[])
542-
.observe(self.inboxes.count().await? as f64);
543-
let entry = BundleInInbox::new(origin.clone(), &bundle);
544-
let skippable = bundle.is_skippable();
545-
let newly_added = inbox
546-
.add_bundle(bundle)
547-
.await
548-
.map_err(|error| match error {
549-
InboxError::ViewError(error) => ChainError::ViewError(error),
550-
error => ChainError::InternalError(format!(
551-
"while processing messages in certified block: {error}"
552-
)),
553-
})?;
554-
if newly_added && !skippable {
555-
let seen = local_time;
556-
self.unskippable_bundles
557-
.push_back(TimestampedBundleInInbox { entry, seen });
558-
}
535+
// Process the inbox bundle and update the inbox state.
536+
let mut inbox = self.inboxes.try_load_entry_mut(origin).await?;
537+
#[cfg(with_metrics)]
538+
NUM_INBOXES
539+
.with_label_values(&[])
540+
.observe(self.inboxes.count().await? as f64);
541+
let entry = BundleInInbox::new(origin.clone(), &bundle);
542+
let skippable = bundle.is_skippable();
543+
let newly_added = inbox
544+
.add_bundle(bundle)
545+
.await
546+
.map_err(|error| match error {
547+
InboxError::ViewError(error) => ChainError::ViewError(error),
548+
error => ChainError::InternalError(format!(
549+
"while processing messages in certified block: {error}"
550+
)),
551+
})?;
552+
if newly_added && !skippable {
553+
let seen = local_time;
554+
self.unskippable_bundles
555+
.push_back(TimestampedBundleInInbox { entry, seen });
559556
}
560557

561558
// Remember the certificate for future validator/client synchronizations.

linera-chain/src/data_types.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,6 @@ impl MessageBundle {
558558
pub fn is_protected(&self) -> bool {
559559
self.messages.iter().any(PostedMessage::is_protected)
560560
}
561-
562-
/// Returns whether this bundle must be added to the inbox.
563-
///
564-
/// If this is `false`, it gets handled immediately and should never be received in a block.
565-
pub fn goes_to_inbox(&self) -> bool {
566-
self.messages
567-
.iter()
568-
.any(|posted_message| posted_message.message.goes_to_inbox())
569-
}
570561
}
571562

572563
impl PostedMessage {

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -444,22 +444,10 @@ where
444444
let mut heights_by_recipient = BTreeMap::<_, BTreeMap<_, _>>::new();
445445
let mut targets = self.chain.outboxes.indices().await?;
446446
if let Some(tracked_chains) = self.tracked_chains.as_ref() {
447-
let publishers = self
448-
.chain
449-
.execution_state
450-
.system
451-
.subscriptions
452-
.indices()
453-
.await?
454-
.iter()
455-
.map(|subscription| subscription.chain_id)
456-
.collect::<HashSet<_>>();
457447
let tracked_chains = tracked_chains
458448
.read()
459449
.expect("Panics should not happen while holding a lock to `tracked_chains`");
460-
targets.retain(|target| {
461-
tracked_chains.contains(&target.recipient) || publishers.contains(&target.recipient)
462-
});
450+
targets.retain(|target| tracked_chains.contains(&target.recipient));
463451
}
464452
let outboxes = self.chain.outboxes.try_load_entries(&targets).await?;
465453
for (target, outbox) in targets.into_iter().zip(outboxes) {
@@ -544,20 +532,8 @@ where
544532
};
545533
let mut targets = self.chain.outboxes.indices().await?;
546534
{
547-
let publishers = self
548-
.chain
549-
.execution_state
550-
.system
551-
.subscriptions
552-
.indices()
553-
.await?
554-
.iter()
555-
.map(|subscription| subscription.chain_id)
556-
.collect::<HashSet<_>>();
557535
let tracked_chains = tracked_chains.read().unwrap();
558-
targets.retain(|target| {
559-
tracked_chains.contains(&target.recipient) || publishers.contains(&target.recipient)
560-
});
536+
targets.retain(|target| tracked_chains.contains(&target.recipient));
561537
}
562538
let outboxes = self.chain.outboxes.try_load_entries(&targets).await?;
563539
for outbox in outboxes {

linera-core/src/unit_tests/worker_tests.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,16 +2510,6 @@ where
25102510
*user_chain.execution_state.system.admin_id.get(),
25112511
Some(admin_id)
25122512
);
2513-
assert_eq!(
2514-
user_chain
2515-
.execution_state
2516-
.system
2517-
.subscriptions
2518-
.indices()
2519-
.await?
2520-
.len(),
2521-
0
2522-
);
25232513
user_chain.validate_incoming_bundles().await?;
25242514
matches!(
25252515
&user_chain
@@ -2629,16 +2619,6 @@ where
26292619
*user_chain.execution_state.system.admin_id.get(),
26302620
Some(admin_id)
26312621
);
2632-
assert_eq!(
2633-
user_chain
2634-
.execution_state
2635-
.system
2636-
.subscriptions
2637-
.indices()
2638-
.await?
2639-
.len(),
2640-
0
2641-
);
26422622
assert_eq!(user_chain.execution_state.system.committees.get().len(), 2);
26432623
user_chain.validate_incoming_bundles().await?;
26442624
Ok(())

linera-execution/src/execution_state_actor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ where
311311
if !app_permissions.can_close_chain(&application_id) {
312312
callback.respond(Err(ExecutionError::UnauthorizedApplication(application_id)));
313313
} else {
314-
let chain_id = self.context().extra().chain_id();
315-
self.system.close_chain(chain_id).await?;
314+
self.system.close_chain().await?;
316315
callback.respond(Ok(()));
317316
}
318317
}

linera-execution/src/graphql.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use linera_views::{context::Context, map_view::MapView};
1515
use crate::{
1616
committee::{Committee, Epoch, ValidatorState},
1717
system::{Recipient, UserData},
18-
ChannelSubscription, ExecutionStateView, SystemExecutionStateView,
18+
ExecutionStateView, SystemExecutionStateView,
1919
};
2020

2121
doc_scalar!(
@@ -73,11 +73,6 @@ impl<C: Send + Sync + Context> SystemExecutionStateView<C> {
7373
self.admin_id.get()
7474
}
7575

76-
#[graphql(derived(name = "subscription"))]
77-
async fn _subscriptions(&self) -> Result<Vec<ChannelSubscription>, async_graphql::Error> {
78-
Ok(self.subscriptions.indices().await?)
79-
}
80-
8176
#[graphql(derived(name = "committees"))]
8277
async fn _committees(&self) -> &BTreeMap<Epoch, Committee> {
8378
self.committees.get()

linera-execution/src/lib.rs

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -976,17 +976,6 @@ impl OutgoingMessage {
976976
}
977977
}
978978

979-
/// The identifier of a channel, relative to a particular application.
980-
#[derive(
981-
Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash, Serialize, Deserialize, SimpleObject,
982-
)]
983-
pub struct ChannelSubscription {
984-
/// The chain ID broadcasting on this channel.
985-
pub chain_id: ChainId,
986-
/// The name of the channel.
987-
pub name: ChannelName,
988-
}
989-
990979
impl OperationContext {
991980
/// Returns an account for the refund.
992981
/// Returns `None` if there is no authenticated signer of the [`OperationContext`].
@@ -1223,32 +1212,6 @@ impl Message {
12231212
}
12241213
}
12251214

1226-
/// Returns whether this message must be added to the inbox.
1227-
pub fn goes_to_inbox(&self) -> bool {
1228-
!matches!(
1229-
self,
1230-
Message::System(SystemMessage::Subscribe { .. } | SystemMessage::Unsubscribe { .. })
1231-
)
1232-
}
1233-
1234-
pub fn matches_subscribe(&self) -> Option<(&ChainId, &ChannelSubscription)> {
1235-
match self {
1236-
Message::System(SystemMessage::Subscribe { id, subscription }) => {
1237-
Some((id, subscription))
1238-
}
1239-
_ => None,
1240-
}
1241-
}
1242-
1243-
pub fn matches_unsubscribe(&self) -> Option<(&ChainId, &ChannelSubscription)> {
1244-
match self {
1245-
Message::System(SystemMessage::Unsubscribe { id, subscription }) => {
1246-
Some((id, subscription))
1247-
}
1248-
_ => None,
1249-
}
1250-
}
1251-
12521215
pub fn matches_open_chain(&self) -> Option<&OpenChainConfig> {
12531216
match self {
12541217
Message::System(SystemMessage::OpenChain(config)) => Some(config),

linera-execution/src/system.rs

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ use {linera_base::prometheus_util::register_int_counter_vec, prometheus::IntCoun
4141
use crate::test_utils::SystemExecutionState;
4242
use crate::{
4343
committee::{Committee, Epoch},
44-
ApplicationDescription, ApplicationId, ChannelSubscription, ExecutionError,
45-
ExecutionRuntimeContext, MessageContext, MessageKind, OperationContext, OutgoingMessage,
46-
QueryContext, QueryOutcome, ResourceController, TransactionTracker,
44+
ApplicationDescription, ApplicationId, ExecutionError, ExecutionRuntimeContext, MessageContext,
45+
MessageKind, OperationContext, OutgoingMessage, QueryContext, QueryOutcome, ResourceController,
46+
TransactionTracker,
4747
};
4848

4949
/// The relative index of the `OpenChain` message created by the `OpenChain` operation.
@@ -72,8 +72,6 @@ pub struct SystemExecutionStateView<C> {
7272
pub epoch: HashedRegisterView<C, Option<Epoch>>,
7373
/// The admin of the chain.
7474
pub admin_id: HashedRegisterView<C, Option<ChainId>>,
75-
/// Track the channels that we have subscribed to.
76-
pub subscriptions: HashedSetView<C, ChannelSubscription>,
7775
/// The committees that we trust, indexed by epoch number.
7876
// Not using a `MapView` because the set active of committees is supposed to be
7977
// small. Plus, currently, we would create the `BTreeMap` anyway in various places
@@ -211,16 +209,6 @@ pub enum SystemMessage {
211209
},
212210
/// Creates (or activates) a new chain.
213211
OpenChain(OpenChainConfig),
214-
/// Subscribes to a channel.
215-
Subscribe {
216-
id: ChainId,
217-
subscription: ChannelSubscription,
218-
},
219-
/// Unsubscribes from a channel.
220-
Unsubscribe {
221-
id: ChainId,
222-
subscription: ChannelSubscription,
223-
},
224212
/// Notifies that a new application was created.
225213
ApplicationCreated,
226214
}
@@ -353,10 +341,7 @@ where
353341
ChangeApplicationPermissions(application_permissions) => {
354342
self.application_permissions.set(application_permissions);
355343
}
356-
CloseChain => {
357-
let messages = self.close_chain(context.chain_id).await?;
358-
txn_tracker.add_outgoing_messages(messages)?;
359-
}
344+
CloseChain => self.close_chain().await?,
360345
Transfer {
361346
owner,
362347
amount,
@@ -682,7 +667,7 @@ where
682667
}
683668
}
684669
// These messages are executed immediately when cross-chain requests are received.
685-
Subscribe { .. } | Unsubscribe { .. } | OpenChain(_) => {}
670+
OpenChain(_) => {}
686671
// This message is only a placeholder: Its ID is part of the application ID.
687672
ApplicationCreated => {}
688673
}
@@ -762,27 +747,9 @@ where
762747
Ok(OutgoingMessage::new(child_id, message).with_kind(MessageKind::Protected))
763748
}
764749

765-
pub async fn close_chain(
766-
&mut self,
767-
id: ChainId,
768-
) -> Result<Vec<OutgoingMessage>, ExecutionError> {
769-
let mut messages = Vec::new();
770-
// Unsubscribe from all channels.
771-
self.subscriptions
772-
.for_each_index(|subscription| {
773-
messages.push(
774-
OutgoingMessage::new(
775-
subscription.chain_id,
776-
SystemMessage::Unsubscribe { id, subscription },
777-
)
778-
.with_kind(MessageKind::Protected),
779-
);
780-
Ok(())
781-
})
782-
.await?;
783-
self.subscriptions.clear();
750+
pub async fn close_chain(&mut self) -> Result<(), ExecutionError> {
784751
self.closed.set(true);
785-
Ok(messages)
752+
Ok(())
786753
}
787754

788755
pub async fn create_application(

linera-execution/src/test_utils/system_execution_state.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ use super::{MockApplication, RegisterMockApplication};
2424
use crate::{
2525
committee::{Committee, Epoch},
2626
execution::UserAction,
27-
ApplicationDescription, ChannelSubscription, ExecutionError, ExecutionRuntimeConfig,
28-
ExecutionRuntimeContext, ExecutionStateView, OperationContext, ResourceControlPolicy,
29-
ResourceController, ResourceTracker, TestExecutionRuntimeContext, UserContractCode,
27+
ApplicationDescription, ExecutionError, ExecutionRuntimeConfig, ExecutionRuntimeContext,
28+
ExecutionStateView, OperationContext, ResourceControlPolicy, ResourceController,
29+
ResourceTracker, TestExecutionRuntimeContext, UserContractCode,
3030
};
3131

3232
/// A system execution state, not represented as a view but as a simple struct.
@@ -35,7 +35,6 @@ pub struct SystemExecutionState {
3535
pub description: Option<ChainDescription>,
3636
pub epoch: Option<Epoch>,
3737
pub admin_id: Option<ChainId>,
38-
pub subscriptions: BTreeSet<ChannelSubscription>,
3938
pub committees: BTreeMap<Epoch, Committee>,
4039
pub ownership: ChainOwnership,
4140
pub balance: Amount,
@@ -88,7 +87,6 @@ impl SystemExecutionState {
8887
description,
8988
epoch,
9089
admin_id,
91-
subscriptions,
9290
committees,
9391
ownership,
9492
balance,
@@ -120,12 +118,6 @@ impl SystemExecutionState {
120118
view.system.description.set(description);
121119
view.system.epoch.set(epoch);
122120
view.system.admin_id.set(admin_id);
123-
for subscription in subscriptions {
124-
view.system
125-
.subscriptions
126-
.insert(&subscription)
127-
.expect("serialization of subscription should not fail");
128-
}
129121
view.system.committees.set(committees);
130122
view.system.ownership.set(ownership);
131123
view.system.balance.set(balance);

linera-rpc/tests/snapshots/format__format.yaml.snap

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,6 @@ ChannelFullName:
381381
TYPENAME: ChannelName
382382
ChannelName:
383383
NEWTYPESTRUCT: BYTES
384-
ChannelSubscription:
385-
STRUCT:
386-
- chain_id:
387-
TYPENAME: ChainId
388-
- name:
389-
TYPENAME: ChannelName
390384
Committee:
391385
STRUCT:
392386
- validators:
@@ -1085,20 +1079,6 @@ SystemMessage:
10851079
NEWTYPE:
10861080
TYPENAME: OpenChainConfig
10871081
3:
1088-
Subscribe:
1089-
STRUCT:
1090-
- id:
1091-
TYPENAME: ChainId
1092-
- subscription:
1093-
TYPENAME: ChannelSubscription
1094-
4:
1095-
Unsubscribe:
1096-
STRUCT:
1097-
- id:
1098-
TYPENAME: ChainId
1099-
- subscription:
1100-
TYPENAME: ChannelSubscription
1101-
5:
11021082
ApplicationCreated: UNIT
11031083
SystemOperation:
11041084
ENUM:

0 commit comments

Comments
 (0)