-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3384968
commit ddd9645
Showing
3 changed files
with
304 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,302 @@ | ||
--- | ||
title: Holochain Upgrade 0.2 → 0.3 | ||
hide: | ||
- toc | ||
--- | ||
|
||
::: intro | ||
For existing hApps that have been written for Holochain version 0.2, these are steps to upgrade to Holochain version 0.3. | ||
::: | ||
|
||
### Steps to update from Holochain version 0.2 to 0.3 in Holonix | ||
|
||
!!! note | ||
The following steps only apply to Nix flakes that have been either generated by the Holochain scaffolding tool | ||
or follow the recommended format as described in [Dev Tools Setup](../install-advanced). | ||
!!! | ||
|
||
#### Update your `flake.nix` using a command | ||
|
||
In the root folder of the hApp to be upgraded execute the following command in a terminal: | ||
|
||
```shell | ||
nix run nixpkgs#gnused -- -i 's/dir=versions\/0_2/dir=versions\/0_3/g' flake.nix | ||
``` | ||
|
||
#### Update your `flake.nix` manually | ||
|
||
Alternatively open `flake.nix` in an editor. It should look like this: | ||
|
||
```nix | ||
{ | ||
description = "My hApp"; | ||
inputs = { | ||
nixpkgs.follows = "holonix/nixpkgs"; | ||
versions.url = "github:holochain/holochain?dir=versions/0_2"; | ||
holonix.url = "github:holochain/holochain"; | ||
holonix.inputs.versions.follows = "versions"; | ||
}; | ||
... | ||
} | ||
``` | ||
|
||
Change this line | ||
|
||
```nix | ||
versions.url = "github:holochain/holochain?dir=versions/0_2"; | ||
``` | ||
|
||
to | ||
|
||
```nix | ||
versions.url = "github:holochain/holochain?dir=versions/0_3"; | ||
``` | ||
|
||
#### Apply the update | ||
|
||
Updating the `flake.nix` won't make Nix use the new Holochain version when you next open a dev shell with `nix develop`. For the changes | ||
to take effect you need to run: | ||
|
||
```shell | ||
nix flake update | ||
``` | ||
|
||
!!! note | ||
This takes all updates from Holonix, possibly including an update to the Rust version that Holonix is currently using. | ||
You should run this command whenever you update your Cargo dependencies to the latest HDI/HDK versions. | ||
!!! | ||
|
||
#### Open a dev shell and check the update has worked | ||
|
||
Open a dev shell like you normally would | ||
|
||
```shell | ||
nix develop | ||
``` | ||
|
||
Then check that Holochain is on a 0.3.x version | ||
|
||
```shell | ||
holochain --version | ||
``` | ||
|
||
This should print something like `holochain 0.3.1`. It is fine for the last number to be higher. It's the minor version, the `3`, that tells you that you've successfully updated from Holochain version 0.2 to 0.3 in Holonix. | ||
|
||
### Update NPM dependencies | ||
|
||
!!! note | ||
The following steps only apply to projects that have been either generated by the Holochain scaffolding tool | ||
or have followed the same folder layout. Otherwise, you will need to adjust the commands. | ||
!!! | ||
|
||
#### Update the `@holochain/client` | ||
|
||
In your project's `ui/package.json` and `tests/package.json` you will find a dependency on `@holochain/client`. These should be using `0.16.x`, which is the version compatible with Holochain 0.2. To work with Holochain 0.3, you need to update to `0.17.x`. | ||
|
||
You can always check what versions of the Holochain client are available on the [NPM registry](https://www.npmjs.com/package/@holochain/client?activeTab=versions) and you can find out what versions are compatible with a Holochain version by checking the [project's documentation](https://github.com/holochain/holochain-client-js). | ||
|
||
To update the Holochain client for the UI, you can run | ||
|
||
``` | ||
npm install --workspace ui @holochain/client@^0.17.0 | ||
``` | ||
|
||
and for the tests you can run | ||
|
||
``` | ||
npm install --workspace tests @holochain/client@^0.17.0 | ||
``` | ||
|
||
!!!note | ||
This will not install version `0.17.0` if a newer version has been released. Check your `package-lock.json` to see exactly what version got installed. It will be `0.17.x` because the `^` constraint only permits patch upgrades, so you will get a version that's compatible with Holochain 0.3. | ||
!!! | ||
|
||
There have been a few changes to the client. First, the `AppAgentWebsocket` has been merged with the `AppWebsocket`, and | ||
its `connect` method has been simplified. You can now connect to a websocket by changing: | ||
```js | ||
const client = await AppAgentWebsocket.connect(new URL('https://UNUSED'), 'hello-world'); | ||
``` | ||
|
||
To this: | ||
|
||
```js | ||
const client = await AppWebsocket.connect(); | ||
``` | ||
|
||
Then anywhere that you used to need to pass the installed app id (e.g. `'hello-world'` above), you no longer need to. | ||
So for example, you would change | ||
|
||
```js | ||
await client.appInfo('hello-world'); | ||
``` | ||
|
||
To this: | ||
|
||
```js | ||
await client.appInfo(); | ||
``` | ||
|
||
This is because app client connections are now bound to the app that they are connected to. So there's no need to tell | ||
the conductor which app you want to operate on, it already knows. | ||
|
||
#### Update `@holochain/hc-spin` | ||
|
||
If you're using `hc-spin` then you will need to upgrade it to work with the new Holochain version. | ||
|
||
You can do this by running: | ||
```bash | ||
npm install --save-dev @holochain/hc-spin@">=0.300.0 <0.400.0" | ||
``` | ||
|
||
You can always check what versions of `@holochain/hc-spin` are available on the [NPM registry](https://www.npmjs.com/package/@holochain/hc-spin?activeTab=versions). | ||
|
||
#### Update `@holochain/tryorama` | ||
|
||
In your project's `tests/package.json` you will find a dependency on `@holochain/tryorama`. This should be using `0.15.x`, which is the version compatible with Holochain 0.2. To work with Holochain 0.3, you need to update to `0.16.x`. | ||
|
||
You can always check what versions of Tryorama are available on the [NPM registry](https://www.npmjs.com/package/@holochain/tryorama?activeTab=versions) and you can find out what versions are compatible with a Holochain version by checking the [project's documentation](https://github.com/holochain/tryorama?tab=readme-ov-file#compatibility). | ||
|
||
To update Tryorama, you can run | ||
|
||
``` | ||
npm install --workspace tests @holochain/tryorama@^0.16.0 | ||
``` | ||
|
||
!!!note | ||
This will not install version `0.16.0` if a newer version has been released. Check your `package-lock.json` to see exactly what version got installed. It will be `0.16.x` because the `^` constraint only permits patch upgrades, so you will get a version that's compatible with Holochain 0.3. | ||
!!! | ||
|
||
### Update Cargo dependencies | ||
|
||
This section is harder to write a general guide for because it's common for hApps to add dependencies on other Holochain crates. If you have added other dependencies than the `hdi` and `hdk` to your project then you will need to update those too but figuring out which versions you | ||
need is not described here. There is a hint at the end of the section. | ||
|
||
#### Update the HDK and the HDI | ||
|
||
Open your project's `Cargo.toml` in an editor and look for the `[workspace.dependencies]` section. Here you should find something like | ||
|
||
``` | ||
[workspace.dependencies] | ||
hdi = "=0.3.8" | ||
hdk = "=0.2.8" | ||
``` | ||
|
||
Change these to point at their latest versions. At the time of writing this would be | ||
|
||
``` | ||
[workspace.dependencies] | ||
hdi = "=0.4.1" | ||
hdk = "=0.3.1" | ||
``` | ||
|
||
Please check the latest version for these on their respective pages on the `crates.io` registry, [HDK](https://crates.io/crates/hdk/versions) and [HDI](https://crates.io/crates/hdi/versions). You need to use `0.3.x` for the hdk and `0.4.x` for the `HDI`, so you are looking for the latest patch version that is available for each. | ||
|
||
Once you've updated your `Cargo.toml` you need to update your `Cargo.lock` and check whether your project is building. To do this in one step | ||
you can run | ||
|
||
```shell | ||
cargo build | ||
``` | ||
|
||
#### Dealing with API changes in the HDK and HDI | ||
|
||
You are likely to run into API changes in the HDK and HDI at this point. You can check the [Holochain changelog](https://github.com/holochain/holochain/blob/develop-0.3/CHANGELOG.md) to see what has changed. In some cases there will be guidance for what you need to change. | ||
|
||
If you have trouble resolving the build issues or the changelog doesn't give you enough information about what has changed then please reach out on Discord or open a [Github issue](https://github.com/holochain/holochain/issues/new/choose). | ||
|
||
Below are some known changes that you might need to address. | ||
|
||
##### HDI: macro rename `hdk_entry_defs` -> `hdk_entry_types` | ||
|
||
This macro was renamed for consistency with other macros. The changelog entry for this change is [here](https://github.com/holochain/holochain/blob/develop-0.3/CHANGELOG.md#hdk_derive-030-beta-dev23). | ||
|
||
You're looking for code like: | ||
```rust | ||
#[derive(Serialize, Deserialize)] | ||
#[serde(tag = "type")] | ||
#[hdk_entry_defs] | ||
#[unit_enum(UnitEntryTypes)] | ||
pub enum EntryTypes { | ||
Hello(Hello), | ||
} | ||
``` | ||
|
||
Which should be updated to: | ||
```rust | ||
#[derive(Serialize, Deserialize)] | ||
#[serde(tag = "type")] | ||
#[hdk_entry_types] | ||
#[unit_enum(UnitEntryTypes)] | ||
pub enum EntryTypes { | ||
Hello(Hello), | ||
} | ||
``` | ||
|
||
##### HDK: `get_links` function signature change | ||
|
||
The `get_links` function signature has changed. The changelog entry for this change is [here](https://github.com/holochain/holochain/blob/develop-0.3/CHANGELOG.md#hdk-030-beta-dev10). | ||
|
||
You're looking for code like: | ||
```rust | ||
let links = get_links(path.path_entry_hash()?, LinkTypes::AllHellos, None)?; | ||
``` | ||
|
||
Which should be updated to: | ||
```rust | ||
let links = get_links(GetLinksInputBuilder::try_new(path.path_entry_hash()?, LinkTypes::AllHellos)?.build())?; | ||
``` | ||
|
||
##### HDK: `remote_signal` function renamed | ||
|
||
Most HDK functions follow the naming pattern `verb[_target]`. The `remote_signal` function was renamed to `send_remote_signal` to follow this pattern | ||
and make it clearer what the function does. The changelog entry for this change is [here](https://github.com/holochain/holochain/blob/develop-0.3/CHANGELOG.md#hdk-030-beta-dev23). | ||
|
||
##### HDK: `GetOptions` rework | ||
|
||
The `GetOptions` enum used to have `Content` and `Latest` variants. The meaning of these weren't clear and they were not | ||
consistently implemented. The `Content` variant was renamed to `Local` and using it will request that data lookups are | ||
done using local data only. The `Latest` variant was renamed to `Network` and allows Holochain to choose to go to the | ||
network to fetch data if required. The changelog entry for this change is [here](https://github.com/holochain/holochain/blob/develop-0.3/CHANGELOG.md#holochain_zome_types-030-beta-dev29). | ||
|
||
You're looking for code like: | ||
```rust | ||
get(r.action().entry_hash().unwrap().clone(), GetOptions::content())?; | ||
``` | ||
|
||
Which should be updated to: | ||
```rust | ||
get(r.action().entry_hash().unwrap().clone(), GetOptions::network())?; | ||
``` | ||
|
||
The `Local` variant is intended to support a local first app which is willing to operate with the currently available data. | ||
If you aren't sure which option to use then `Network` is recommended to use as the default. Then you can build in local first | ||
capabilities when you are ready. | ||
|
||
#### Updating other dependencies | ||
|
||
If you depend on other Holochain crates, then you will need to find compatible versions to update to. You can check available versions on `crates.io` by searching for them by name. You can also check the [Holochain changelog](https://github.com/holochain/holochain/blob/develop-0.3/CHANGELOG.md) to see what versions have been released together. Note that we don't release crates unless they have changes, so if you don't see the crate you're looking for in a release, then please check the previous releases for the last time we released it. If you get stuck or have build issues, then please reach out on Discord or open a [Github issue](https://github.com/holochain/holochain/issues/new/choose). | ||
|
||
#### General advice for upgrading | ||
|
||
It's likely that you will need to make more changes than have been mentioned above, but hopefully this guide has given you a head start! Here are some other things to look out for in this upgrade: | ||
- There have been significant changes to Holochain's data validation. You may see validation failures that you didn't see before upgrading. Our experience of helping people upgrade to dev versions of 0.3 is that these are often due to issues in your app's validation logic. | ||
Please check your validation logic and check whether there might be an issue there. If not, then please reach out on Discord or open a [Github issue](https://github.com/holochain/holochain/issues/new/choose) for help. | ||
- There have been changes to the data structures provided for app validation. This means that you will need to update your validation code to remove some fields that are no longer available. You should check the changelog [here](https://github.com/holochain/holochain/blob/develop-0.3/CHANGELOG.md#hdi-040-beta-dev36). | ||
If you need to retain the fields that have been removed for your validation logic, then your best option is probably to scaffold an app for 0.3 and take a look at the validation code that is generated. | ||
You can do this by running `nix run --override-input versions "github:holochain/holochain?dir=versions/0_3" github:holochain/holochain#hc-scaffold`. | ||
- There have been significant app interface changes for Holochain 0.3. There is a changelog entry [here](https://github.com/holochain/holochain/blob/develop-0.3/CHANGELOG.md#holochain-030-beta-dev47). Most problems will be taken care of by picking | ||
the right client versions and following any changes that are required to use the new client. However, if you are integrating with Holochain's app websocket directly or maintaining your own client then you should get in touch if you run into any difficulties upgrading. | ||
- Databases up to 0.3 have been unencrypted by default. From 0.3 onwards, databases are always encrypted by default. You can disable this by building Holochain with different options if you need to, or we can show you how to open the encrypted databases if you need. | ||
For now, we are assuming that people don't often need to do this so there is no guide. If this assumption turns out to be wrong, we can create a guide for this! | ||
- A change was made to help hApp developers spot mistakes in DNA manifests that might catch you out if you have extra fields or old fields in your DNA manifest. You can read about this change [here](https://github.com/holochain/holochain/blob/develop-0.3/CHANGELOG.md#holochain_types-030-beta-dev24). | ||
- Holochain 0.2 and 0.3 are not network compatible. That means that if you have users of you hApp still running Holochain 0.2, then even with the same DNA hash, they would not be able to connect to users running Holochain 0.3. | ||
The changes between 0.2 and 0.3 are not as significant as they were between 0.1 and 0.2, but they still prevent communication between the two versions. | ||
|
||
### Next steps | ||
|
||
You should check that your project builds, tests are passing and that anything else your CI will check is working. You should also check that your hApp is still working because static checks and tests might not catch changes that are required in your UI. | ||
|
||
For general project health, you should check if any other dependencies in your project need an update. Please refer to NPM and Cargo documentation for this. | ||
|
||
That should be everything, you can now develop against Holochain 0.3! Good luck, and if you need help then please do get in touch on Discord or open a [Github issue](https://github.com/holochain/holochain/issues/new/choose). |