Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions examples/fungible/tests/cross_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use fungible::{
};
use linera_sdk::{
linera_base_types::{AccountOwner, Amount},
test::{Medium, MessageAction, TestValidator},
test::{MessageAction, TestValidator},
};

This comment was marked as spam.


/// Test transferring tokens across microchains.
Expand Down Expand Up @@ -118,11 +118,7 @@ async fn test_bouncing_tokens() {

receiver_chain
.add_block(move |block| {
block.with_messages_from_by_medium(
&certificate,
&Medium::Direct,
MessageAction::Reject,
);
block.with_messages_from_by_action(&certificate, MessageAction::Reject);
})
.await;

Expand Down
5 changes: 2 additions & 3 deletions linera-base/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ use crate::{
crypto::{BcsHashable, CryptoError, CryptoHash},
doc_scalar, hex_debug, http,
identifiers::{
ApplicationId, BlobId, BlobType, ChainId, Destination, EventId, GenericApplicationId,
ModuleId, StreamId,
ApplicationId, BlobId, BlobType, ChainId, EventId, GenericApplicationId, ModuleId, StreamId,
},
limited_writer::{LimitedWriter, LimitedWriterError},
time::{Duration, SystemTime},
Expand Down Expand Up @@ -307,7 +306,7 @@ pub struct Resources {
#[witty_specialize_with(Message = Vec<u8>)]
pub struct SendMessageRequest<Message> {
/// The destination of the message.
pub destination: Destination,
pub destination: ChainId,
/// Whether the message is authenticated.
pub authenticated: bool,
/// Whether the message is tracked.
Expand Down
125 changes: 0 additions & 125 deletions linera-base/src/identifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,54 +404,6 @@ pub struct ModuleId<Abi = (), Parameters = (), InstantiationArgument = ()> {
_phantom: PhantomData<(Abi, Parameters, InstantiationArgument)>,
}

/// The name of a subscription channel.
#[derive(
Clone,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
Serialize,
Deserialize,
WitLoad,
WitStore,
WitType,
)]
pub struct ChannelName(
#[serde(with = "serde_bytes")]
#[debug(with = "hex_debug")]
Vec<u8>,
);

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
/// A channel name together with its application ID.
pub struct ChannelFullName {
/// The application owning the channel.
pub application_id: ApplicationId,
/// The name of the channel.
pub name: ChannelName,
}

impl fmt::Display for ChannelFullName {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let name = hex::encode(&self.name);
let app_id = self.application_id;
write!(f, "user channel {name} for app {app_id}")
}
}

impl ChannelFullName {
/// Creates a full user channel name.
pub fn new(name: ChannelName, application_id: ApplicationId) -> Self {
Self {
application_id,
name,
}
}
}

/// The name of an event stream.
#[derive(
Clone,
Expand Down Expand Up @@ -538,74 +490,6 @@ pub struct EventId {
pub index: u32,
}

/// The destination of a message, relative to a particular application.
#[derive(
Clone,
Debug,
Eq,
Hash,
Ord,
PartialEq,
PartialOrd,
Serialize,
Deserialize,
WitLoad,
WitStore,
WitType,
)]
pub enum Destination {
/// Direct message to a chain.
Recipient(ChainId),
/// Broadcast to the current subscribers of our channel.
Subscribers(ChannelName),
}

impl Destination {
/// Whether the destination is a broadcast channel.
pub fn is_channel(&self) -> bool {
matches!(self, Destination::Subscribers(_))
}

/// Returns the recipient chain, or `None` if it is `Subscribers`.
pub fn recipient(&self) -> Option<ChainId> {
match self {
Destination::Recipient(chain_id) => Some(*chain_id),
Destination::Subscribers(_) => None,
}
}
}

impl From<ChainId> for Destination {
fn from(chain_id: ChainId) -> Self {
Destination::Recipient(chain_id)
}
}

impl From<ChannelName> for Destination {
fn from(channel_name: ChannelName) -> Self {
Destination::Subscribers(channel_name)
}
}

impl AsRef<[u8]> for ChannelName {
fn as_ref(&self) -> &[u8] {
&self.0
}
}

impl From<Vec<u8>> for ChannelName {
fn from(name: Vec<u8>) -> Self {
ChannelName(name)
}
}

impl ChannelName {
/// Turns the channel name into bytes.
pub fn into_bytes(self) -> Vec<u8> {
self.0
}
}

impl StreamName {
/// Turns the stream name into bytes.
pub fn into_bytes(self) -> Vec<u8> {
Expand Down Expand Up @@ -1112,13 +996,8 @@ doc_scalar!(
"The unique identifier (UID) of a chain. This is currently computed as the hash value of a \
ChainDescription."
);
doc_scalar!(ChannelName, "The name of a subscription channel");
doc_scalar!(StreamName, "The name of an event stream");
bcs_scalar!(MessageId, "The index of a message in a chain");
doc_scalar!(
Destination,
"The destination of a message, relative to a particular application."
);
doc_scalar!(
AccountOwner,
"A unique identifier for a user or an application."
Expand All @@ -1128,10 +1007,6 @@ doc_scalar!(
BlobId,
"A content-addressed blob ID i.e. the hash of the `BlobContent`"
);
doc_scalar!(
ChannelFullName,
"A channel name together with its application ID."
);

#[cfg(test)]
mod tests {
Expand Down
9 changes: 2 additions & 7 deletions linera-base/src/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use test_case::test_case;
use crate::{
crypto::{AccountPublicKey, CryptoHash},
data_types::{Amount, BlockHeight, Resources, SendMessageRequest, TimeDelta, Timestamp},
identifiers::{
Account, AccountOwner, ApplicationId, ChainId, ChannelName, Destination, MessageId,
ModuleId,
},
identifiers::{Account, AccountOwner, ApplicationId, ChainId, MessageId, ModuleId},
ownership::{ChainOwnership, TimeoutConfig},
vm::VmRuntime,
};
Expand All @@ -33,8 +30,6 @@ use crate::{
#[test_case(message_id_test_case(); "of_message_id")]
#[test_case(application_id_test_case(); "of_application_id")]
#[test_case(module_id_test_case(); "of_module_id")]
#[test_case(ChannelName::from(b"channel name".to_vec()); "of_channel_name")]
#[test_case(Destination::Recipient(ChainId::root(0)); "of_destination")]
#[test_case(timeout_config_test_case(); "of_timeout_config")]
#[test_case(chain_ownership_test_case(); "of_chain_ownership")]
fn test_wit_roundtrip<T>(input: T)
Expand Down Expand Up @@ -72,7 +67,7 @@ fn send_message_request_test_case() -> SendMessageRequest<Vec<u8>> {
SendMessageRequest {
authenticated: true,
is_tracked: false,
destination: Destination::Subscribers(b"channel".to_vec().into()),
destination: ChainId::root(0),
grant: Resources {
bytes_to_read: 200,
bytes_to_write: 0,
Expand Down
13 changes: 6 additions & 7 deletions linera-chain/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use thiserror::Error;

use crate::{
data_types::{
BlockExecutionOutcome, IncomingBundle, Medium, MessageAction, MessageBundle,
OperationResult, OutgoingMessageExt, PostedMessage, ProposedBlock,
BlockExecutionOutcome, IncomingBundle, MessageAction, MessageBundle, OperationResult,
OutgoingMessageExt, PostedMessage, ProposedBlock,
},
types::CertificateValue,
};
Expand Down Expand Up @@ -405,12 +405,11 @@ impl Block {
/// recipient. Messages originating from different transactions of the original block
/// are kept in separate bundles. If the medium is a channel, does not verify that the
/// recipient is actually subscribed to that channel.
pub fn message_bundles_for<'a>(
&'a self,
medium: &'a Medium,
pub fn message_bundles_for(
&self,
recipient: ChainId,
certificate_hash: CryptoHash,
) -> impl Iterator<Item = (Epoch, MessageBundle)> + 'a {
) -> impl Iterator<Item = (Epoch, MessageBundle)> + '_ {
let mut index = 0u32;
let block_height = self.header.height;
let block_timestamp = self.header.timestamp;
Expand All @@ -421,7 +420,7 @@ impl Block {
.filter_map(move |(transaction_index, txn_messages)| {
let messages = (index..)
.zip(txn_messages)
.filter(|(_, message)| message.has_destination(medium, recipient))
.filter(|(_, message)| message.destination == recipient)
.map(|(idx, message)| message.clone().into_posted(idx))
.collect::<Vec<_>>();
index += txn_messages.len() as u32;
Expand Down
18 changes: 8 additions & 10 deletions linera-chain/src/certificate/confirmed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize};
use super::{generic::GenericCertificate, Certificate};
use crate::{
block::{Block, ConfirmedBlock, ConversionError},
data_types::{Medium, MessageBundle},
data_types::MessageBundle,
};

impl GenericCertificate<ConfirmedBlock> {
Expand All @@ -26,18 +26,16 @@ impl GenericCertificate<ConfirmedBlock> {
self.block().message_by_id(message_id).is_some()
}

/// Returns the bundles of messages sent via the given medium to the specified
/// recipient. Messages originating from different transactions of the original block
/// are kept in separate bundles. If the medium is a channel, does not verify that the
/// recipient is actually subscribed to that channel.
pub fn message_bundles_for<'a>(
&'a self,
medium: &'a Medium,
/// Returns the bundles of messages sent to the specified recipient.
/// Messages originating from different transactions of the original block
/// are kept in separate bundles.
pub fn message_bundles_for(
&self,
recipient: ChainId,
) -> impl Iterator<Item = (Epoch, MessageBundle)> + 'a {
) -> impl Iterator<Item = (Epoch, MessageBundle)> + '_ {
let certificate_hash = self.hash();
self.block()
.message_bundles_for(medium, recipient, certificate_hash)
.message_bundles_for(recipient, certificate_hash)
}

#[cfg(with_testing)]
Expand Down
Loading
Loading