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

Publish template as a substate #1207

Open
sdbondi opened this issue Nov 29, 2024 · 1 comment
Open

Publish template as a substate #1207

sdbondi opened this issue Nov 29, 2024 · 1 comment
Assignees
Milestone

Comments

@sdbondi
Copy link
Member

sdbondi commented Nov 29, 2024

Problem

Validators need permanent(*) access to WASM templates. Currently, for simplicity, we use an URL that must be available for each validator. There is and can never be a guarantee that the URL will serve the template for as long as it is needed.

Proposal 1

A template author publishes the template directly to L2 by issuing a PublishTemplate instruction in a transaction.

The template engine will validate the WASM binary and create a substate template_xx where xx is H(template_author || content_sha)

template_author is a public key of the author (i.e. the transaction signer).

For now: Validators retrieve (if necessary) and cache the templates lazily/as needed. A new consensus message protocol should be implemented to allow the fetching of templates as a request/response.

Related: #1101

@sdbondi sdbondi converted this from a draft issue Nov 29, 2024
@sdbondi sdbondi added this to the v0.8.0 milestone Nov 29, 2024
@ksrichard ksrichard self-assigned this Nov 29, 2024
@ksrichard ksrichard moved this from Selected for development to In Progress in Tari Digital Assets Network (DAN) backlog Nov 29, 2024
sdbondi pushed a commit that referenced this issue Dec 6, 2024
Description
---
As part of #1207 , this
PR contains the basic instruction and skeleton for instruction
processing. There is a validation implemented for the new
PublishTemplate instruction (where also we validate size of wasm
binary).

Please note that in this PR there is no new substates or anything
generated yet.

Motivation and Context
---
#1207

How Has This Been Tested?
---
Send a new transaction to VN:

```rust
    let AccountGetResponse { account, public_key, } = client
        .accounts_get(ComponentAddressOrName::Name("acc"))
        .await?;
    let account_component_address = account.address
        .as_component_address()
        .expect("Failed to get component address");

    // publish wasm template
    let wasm_binary = fs::read("./templates/counter/target/wasm32-unknown-unknown/release/counter.wasm")?;
    let tx = Transaction::builder()
        .fee_transaction_pay_from_component(account_component_address, Amount(1000))
        .publish_template(wasm_binary)
        .build_unsigned_transaction();
    let transaction_submit_req = TransactionSubmitRequest {
        transaction: tx,
        signing_key_index: Some(account.key_index),
        detect_inputs: true,
        detect_inputs_use_unversioned: true,
        proof_ids: vec![],
        autofill_inputs: vec![],
    };
    let resp = client.submit_transaction(transaction_submit_req).await?;
    println!("Submit RESP: {resp:?}");
    let wait_req = TransactionWaitResultRequest {
        transaction_id: resp.transaction_id,
        timeout_secs: Some(120),
    };
    let wait_resp = client.wait_transaction_result(wait_req).await?;
    println!("TX RESP: {wait_resp:?}");
```

Check printed out result and transaction result on UIs.

Examples:

- Invalid wasm template binary

![image](https://github.com/user-attachments/assets/de090251-5dae-4b21-a72b-f3c4f4939db6)

- Size exceeding wasm template (manually set a lower limit to check
error)

![image](https://github.com/user-attachments/assets/49b588c2-5008-4d70-b831-ab2f0400f647)

- Success

![image](https://github.com/user-attachments/assets/ca86cd58-0ae9-4719-a3c8-132ca7fe8a51)


What process can a PR reviewer use to test or verify this change?
---


Breaking Changes
---

- [x] None
- [ ] Requires data directory to be deleted
- [ ] Other - Please specify
@sdbondi
Copy link
Member Author

sdbondi commented Dec 11, 2024

Ref #1214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants