Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the need for request_application #3382

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
19 changes: 0 additions & 19 deletions CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ This document contains the help content for the `linera` command-line program.
* [`linera read-data-blob`↴](#linera-read-data-blob)
* [`linera create-application`↴](#linera-create-application)
* [`linera publish-and-create`↴](#linera-publish-and-create)
* [`linera request-application`↴](#linera-request-application)
* [`linera keygen`↴](#linera-keygen)
* [`linera assign`↴](#linera-assign)
* [`linera retry-pending-block`↴](#linera-retry-pending-block)
Expand Down Expand Up @@ -94,7 +93,6 @@ A Byzantine-fault tolerant sidechain with low-latency finality and high throughp
* `read-data-blob` — Verify that a data blob is readable
* `create-application` — Create an application
* `publish-and-create` — Create an application, and publish the required bytecode
* `request-application` — Request an application from another chain, so it can be used on this one
* `keygen` — Create an unassigned key pair
* `assign` — Link an owner with a key pair in the wallet to a chain that was created for that owner
* `retry-pending-block` — Retry a block we unsuccessfully tried to propose earlier
Expand Down Expand Up @@ -681,23 +679,6 @@ Create an application, and publish the required bytecode



## `linera request-application`

Request an application from another chain, so it can be used on this one

**Usage:** `linera request-application [OPTIONS] <APPLICATION_ID>`

###### **Arguments:**

* `<APPLICATION_ID>` — The ID of the application to request

###### **Options:**

* `--target-chain-id <TARGET_CHAIN_ID>` — The target chain on which the application is already registered. If not specified, the chain on which the application was created is used
* `--requester-chain-id <REQUESTER_CHAIN_ID>` — The owned chain on which the application is missing



## `linera keygen`

Create an unassigned key pair
Expand Down
8 changes: 2 additions & 6 deletions examples/crowd-funding/tests/campaign_lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ async fn collect_pledges() {
let mut pledges_and_transfers = Vec::new();

for (backer_chain, backer_account, _balance) in &backers {
backer_chain.register_application(campaign_id).await;

let pledge_certificate = backer_chain
.add_block(|block| {
block.with_operation(
Expand All @@ -78,7 +76,7 @@ async fn collect_pledges() {
})
.await;

assert_eq!(pledge_certificate.outgoing_message_count(), 3);
assert_eq!(pledge_certificate.outgoing_message_count(), 2);
pledges_and_transfers.push(pledge_certificate);
}

Expand Down Expand Up @@ -168,8 +166,6 @@ async fn cancel_successful_campaign() {
let mut pledges_and_transfers = Vec::new();

for (backer_chain, backer_account, _balance) in &backers {
backer_chain.register_application(campaign_id).await;

let pledge_certificate = backer_chain
.add_block(|block| {
block.with_operation(
Expand All @@ -182,7 +178,7 @@ async fn cancel_successful_campaign() {
})
.await;

assert_eq!(pledge_certificate.outgoing_message_count(), 3);
assert_eq!(pledge_certificate.outgoing_message_count(), 2);
pledges_and_transfers.push(pledge_certificate);
}

Expand Down
6 changes: 2 additions & 4 deletions examples/fungible/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ pub async fn create_with_accounts(
.await;

for (chain, account, initial_amount) in &accounts {
chain.register_application(application_id).await;

let claim_certificate = chain
.add_block(|block| {
block.with_operation(
Expand All @@ -96,15 +94,15 @@ pub async fn create_with_accounts(
})
.await;

assert_eq!(claim_certificate.outgoing_message_count(), 2);
assert_eq!(claim_certificate.outgoing_message_count(), 1);

let transfer_certificate = token_chain
.add_block(|block| {
block.with_messages_from(&claim_certificate);
})
.await;

assert_eq!(transfer_certificate.outgoing_message_count(), 2);
assert_eq!(transfer_certificate.outgoing_message_count(), 1);

chain
.add_block(|block| {
Expand Down
2 changes: 0 additions & 2 deletions examples/fungible/tests/cross_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ async fn test_bouncing_tokens() {
let receiver_chain = validator.new_chain().await;
let receiver_account = AccountOwner::from(receiver_chain.public_key());

receiver_chain.register_application(application_id).await;

let certificate = sender_chain
.add_block(|block| {
block.with_operation(
Expand Down
6 changes: 0 additions & 6 deletions examples/matching-engine/tests/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ async fn single_transaction() {
)
.await;

user_chain_a.register_application(token_id_b).await;
user_chain_b.register_application(token_id_a).await;

// Check the initial starting amounts for chain a and chain b
for (owner, amount) in [
(admin_account, None),
Expand Down Expand Up @@ -138,9 +135,6 @@ async fn single_transaction() {
vec![token_id_a.forget_abi(), token_id_b.forget_abi()],
)
.await;
// Doing the registrations
user_chain_a.register_application(matching_id).await;
user_chain_b.register_application(matching_id).await;

// Creating the bid orders
let mut bid_certificates = Vec::new();
Expand Down
55 changes: 42 additions & 13 deletions linera-base/src/data_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::{
doc_scalar, hex_debug, http,
identifiers::{
ApplicationId, BlobId, BlobType, BytecodeId, ChainId, Destination, EventId,
GenericApplicationId, MessageId, StreamId, UserApplicationId,
GenericApplicationId, StreamId, UserApplicationId,
},
limited_writer::{LimitedWriter, LimitedWriterError},
time::{Duration, SystemTime},
Expand Down Expand Up @@ -782,13 +782,17 @@ pub enum OracleResponse {

impl<'de> BcsHashable<'de> for OracleResponse {}

/// Description of the necessary information to run a user application.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Hash, Serialize)]
/// Description of the necessary information to run a user application used within blobs.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Hash, Serialize, WitType, WitStore)]
pub struct UserApplicationDescription {
/// The unique ID of the bytecode to use for the application.
pub bytecode_id: BytecodeId,
/// The unique ID of the application's creation.
pub creation: MessageId,
/// The chain ID that created the application.
pub creator_chain_id: ChainId,
/// Height of the block that created this application.
pub block_height: BlockHeight,
/// The index of the application among those created in the same block.
pub application_index: u32,
/// The parameters of the application.
#[serde(with = "serde_bytes")]
#[debug(with = "hex_debug")]
Expand All @@ -799,10 +803,19 @@ pub struct UserApplicationDescription {

impl From<&UserApplicationDescription> for UserApplicationId {
fn from(description: &UserApplicationDescription) -> Self {
UserApplicationId {
bytecode_id: description.bytecode_id,
creation: description.creation,
}
UserApplicationId::new(
CryptoHash::new(&BlobContent::new_application_description(description)),
description.bytecode_id,
)
}
}

impl BcsHashable<'_> for UserApplicationDescription {}

impl UserApplicationDescription {
/// Gets the serialized bytes for this `BlobUserApplicationDescription`.
pub fn to_bytes(&self) -> Vec<u8> {
bcs::to_bytes(self).expect("Serializing blob bytes should not fail!")
}
}

Expand Down Expand Up @@ -939,8 +952,7 @@ impl CompressedBytecode {
impl<'a> BcsHashable<'a> for BlobContent {}

/// A blob of binary data.
#[derive(Hash, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(with_testing, derive(Eq, PartialEq))]
#[derive(Hash, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct BlobContent {
/// The type of data represented by the bytes.
blob_type: BlobType,
Expand Down Expand Up @@ -978,6 +990,14 @@ impl BlobContent {
)
}

/// Creates a new application description [`BlobContent`] from a [`UserApplicationDescription`].
pub fn new_application_description(
application_description: &UserApplicationDescription,
) -> Self {
let bytes = application_description.to_bytes();
BlobContent::new(BlobType::ApplicationDescription, bytes)
}

/// Gets a reference to the blob's bytes.
pub fn bytes(&self) -> &[u8] {
&self.bytes
Expand All @@ -1001,8 +1021,7 @@ impl From<Blob> for BlobContent {
}

/// A blob of binary data, with its hash.
#[derive(Debug, Hash, Clone)]
#[cfg_attr(with_testing, derive(Eq, PartialEq))]
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
pub struct Blob {
/// ID of the blob.
hash: CryptoHash,
Expand Down Expand Up @@ -1043,6 +1062,16 @@ impl Blob {
Blob::new(BlobContent::new_service_bytecode(compressed_bytecode))
}

/// Creates a new application description [`BlobContent`] from the provided
/// description.
pub fn new_application_description(
application_description: &UserApplicationDescription,
) -> Self {
Blob::new(BlobContent::new_application_description(
application_description,
))
}

/// A content-addressed blob ID i.e. the hash of the `Blob`.
pub fn id(&self) -> BlobId {
BlobId {
Expand Down
Loading
Loading