Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Updated the deployer example. #230

Merged
merged 4 commits into from
Dec 6, 2022

Conversation

dmkozh
Copy link
Contributor

@dmkozh dmkozh commented Dec 1, 2022

This is still incomplete:

  • The examples tag should be bumped
  • The CLI should be updated, so that there is some way to install the contract WASM

I'm sending this for a preliminary review as the updates above are trivial.

@stellar-jenkins
Copy link

@dmkozh dmkozh changed the base branch from main to dev December 2, 2022 18:12
This is still incomplete:

- The examples tag should be bumped
- The CLI should be updated, so that there is some way to install the contract WASM
@stellar-jenkins
Copy link

Copy link
Contributor

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few requests, most minor, the one at the end might be tricky.

Open the `deployer/deployer/src/src.rs` file to follow along.
Open the `deployer/deployer/src/lib.rs` file to follow along.

### Contract code installation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title needs capitalizing for consistency, and I suggest we shorten it, since it is easier to create a concept stories around single word names like "installation" and "deployment".

Suggested change
### Contract code installation
### Contract Installation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalized. I think we need to keep 'code' around though, as we are not installing the contract yet (IMO 'contract deploy' and 'contract install' aren't really distinguishable and both concern 'contracts', while the code is not a contract).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really "code" either, it's compiled into some form of code, but not "code" the way developers think of code normally. And it is a contract. It's literally the contract. Deployment creates a contract instance, one of the paragraphs in the doc use that language of "contract instance". So I think we already have dual usage of the term. But that's fine, lets keep code as that's what is in the env and XDR too I realize.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WASM is binary code and that's the way I think about that personally. But I'm fine with updating the terminology to make it less ambiguous. I agree that the code is a contract in some sense, but OTOH saying 'contract instance' every time we refer to the thing you can invoke (and the thing that you'd use 99% of the time) is kind of redundant. Maybe they can be used interchangeably, but then we need something to disambiguate WASM in docs like this one.

docs/examples/deployer.mdx Outdated Show resolved Hide resolved

Before deploying the new contract instances, the WASM code needs to be installed
on-chain. Then it can be reused to deploy an arbitrary number of contract
instances. The installation typically should happen outside of the deployer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
instances. The installation typically should happen outside of the deployer
instances. The installation should typically happen outside of the deployer

Comment on lines 93 to 94
[Below](#tests) is the example of installing the contract code in tests. For the actual
installation see the general deployment [tutorial](https://soroban.stellar.org/docs/tutorials/deploy-to-futurenet).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[Below](#tests) is the example of installing the contract code in tests. For the actual
installation see the general deployment [tutorial](https://soroban.stellar.org/docs/tutorials/deploy-to-futurenet).
See the [tests](#tests) for an example of installing the contract in tests. For the actual
installation see the deployment [tutorial](https://soroban.stellar.org/docs/tutorials/deploy-to-futurenet).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.


### Deployer

The `deployer` contract deploys other contracts. It accepts a salt that will be
used to derive a contract ID, and a WASM bytes to deploy. It also accepts an
initialization function and arguments to pass to that function.
used to derive a contract ID, and a hash-based identifier of the installed WASM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
used to derive a contract ID, and a hash-based identifier of the installed WASM
used to derive a contract ID, and a hash of the installed WASM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about removing this... Maybe we should really only hash the code (initially the install entries had more fields), but that would need to happen in the next release. Added an additional comment to make that clear.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the wasm hash only a hash of the code or something else? Because If it is of something else I think the SDK is misleading.

docs/examples/deployer.mdx Show resolved Hide resolved

```rust
env.register_contract(&deployer_id, Deployer);
```

...and created a client for it:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...and created a client for it:
Create a client that will be used to invoke the contract.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased.

Comment on lines 192 to 210
The deployer contract is registered with the environment.
Register the deployer contract with the environment:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep these as sentences with trailing . for consistency with the other other examples. I don't mind changing it, but if we're going to change it, can you go over every page in the doc and update them all? The docs try and be as consistent as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 275 to 277
TODO: the CLI currently doesn't support the install operation. Before running
the `invoke` below, the contract has to be installed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no plan to add an install command to the CLI in this iteration, so we need to remove this todo and come up with a way for them to "install" it.

```sh
soroban invoke \
--wasm target/wasm32-unknown-unknown/release/soroban_deployer_contract.wasm \
--id 0 \
--fn deploy \
--arg 0000000000000000000000000000000000000000000000000000000000000000 \
--arg $(xxd -p -c- target/wasm32-unknown-unknown/release/soroban_deployer_test_contract.wasm) \
--arg <installed WASM hash> \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to tell people how to get this hash. Can you add that?

Copy link
Contributor Author

@dmkozh dmkozh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the phrasing according to comments. I'll come back to the CLI-related part when we have some changes for CLI merged.

Open the `deployer/deployer/src/src.rs` file to follow along.
Open the `deployer/deployer/src/lib.rs` file to follow along.

### Contract code installation
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capitalized. I think we need to keep 'code' around though, as we are not installing the contract yet (IMO 'contract deploy' and 'contract install' aren't really distinguishable and both concern 'contracts', while the code is not a contract).

docs/examples/deployer.mdx Outdated Show resolved Hide resolved
Comment on lines 93 to 94
[Below](#tests) is the example of installing the contract code in tests. For the actual
installation see the general deployment [tutorial](https://soroban.stellar.org/docs/tutorials/deploy-to-futurenet).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.


### Deployer

The `deployer` contract deploys other contracts. It accepts a salt that will be
used to derive a contract ID, and a WASM bytes to deploy. It also accepts an
initialization function and arguments to pass to that function.
used to derive a contract ID, and a hash-based identifier of the installed WASM
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about removing this... Maybe we should really only hash the code (initially the install entries had more fields), but that would need to happen in the next release. Added an additional comment to make that clear.

used to derive a contract ID, and a WASM bytes to deploy. It also accepts an
initialization function and arguments to pass to that function.
used to derive a contract ID, and a hash-based identifier of the installed WASM
code to deploy. It also accepts an initialization function and arguments to pass
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased.

WASM bytes. The WASM bytes will be deployed and the contract ID for that new
contract is returned. The contract ID is deterministic and is derived from the
deploying contract and the salt.
WASM hash. The contract that with the code corresponding to the `wasm_hash` will
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased and added more context regarding properties/benefits of hash-based deployment.

let client = DeployerClient::new(&env, &deployer_id);
let client = DeployerClient::new(&env, &env.register_contract(None, Deployer));

// Install the WASM code to be deployed from the deployer contract.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines 192 to 210
The deployer contract is registered with the environment.
Register the deployer contract with the environment:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.


```rust
env.register_contract(&deployer_id, Deployer);
```

...and created a client for it:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased.

@stellar-jenkins
Copy link

This commit should be reverted if the respective CLI PR doesn't get into release.
@stellar-jenkins
Copy link

@stellar-jenkins
Copy link

@leighmcculloch leighmcculloch merged commit 702f395 into stellar-deprecated:dev Dec 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants