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

Add 0.3 upgrade guide #454

Merged
merged 27 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ddd9645
Add 0.3 upgrade guide
ThetaSinner Jun 17, 2024
a8c39bb
Update src/pages/get-started/upgrade-holochain-0.3.md
ThetaSinner Jun 18, 2024
52c28a5
Update src/pages/get-started/upgrade-holochain-0.3.md
ThetaSinner Jun 18, 2024
f633ba0
Review changes
ThetaSinner Jun 18, 2024
a6b6483
Add main page tile
ThetaSinner Jun 18, 2024
ac01fb0
Fix links
ThetaSinner Jun 18, 2024
92059d4
Fix link for previous guide
ThetaSinner Jun 18, 2024
912ec27
Relative links not helpful
ThetaSinner Jun 18, 2024
d530809
apply formatting fixes to 0.2 upgrade guide
pdaoust Jun 18, 2024
4644065
Update src/pages/upgrade/upgrade-holochain-0.3.md
ThetaSinner Jun 19, 2024
6e0848f
Apply suggestions from code review
ThetaSinner Jun 19, 2024
20eff30
Apply suggestions from code review
ThetaSinner Jun 19, 2024
7a6520c
Add redirect
ThetaSinner Jun 19, 2024
e6ce4f9
Update src/pages/upgrade/upgrade-holochain-0.3.md
ThetaSinner Jun 19, 2024
adf8820
Update src/pages/upgrade/upgrade-holochain-0.3.md
ThetaSinner Jun 19, 2024
1484825
Update src/pages/upgrade/upgrade-holochain-0.3.md
ThetaSinner Jun 19, 2024
771f75c
Update src/pages/upgrade/upgrade-holochain-0.3.md
ThetaSinner Jun 19, 2024
c17b825
Update src/pages/upgrade/upgrade-holochain-0.3.md
ThetaSinner Jun 19, 2024
28dc3a9
Update src/pages/upgrade/upgrade-holochain-0.3.md
ThetaSinner Jun 19, 2024
922a963
Update src/pages/upgrade/upgrade-holochain-0.3.md
ThetaSinner Jun 19, 2024
689a921
Fix whitespace
ThetaSinner Jun 19, 2024
3ba29e5
Merge branch 'add-0.3-upgrade-guide' of github.com:holochain/docs-pag…
pdaoust Jun 21, 2024
b853d0d
markdown formatting fixes
pdaoust Jun 21, 2024
bdcfe7f
some work on information architecture / nav
pdaoust Jun 21, 2024
ee0c50d
fix over-eager header promoting regex friendly fire
pdaoust Jun 24, 2024
4805b9c
remove upgrade guide from home page
pdaoust Jun 24, 2024
23cdd31
Merge pull request #456 from holochain/add-0.3-upgrade-guide-paul-edits
pdaoust Jun 24, 2024
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
3 changes: 2 additions & 1 deletion src/pages/_data/navigation/mainNav.json5
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
{ title: "Dev Tools Setup Tips", url: "/get-started/install-advanced/" },
{ title: "Setup Without Nix", url: "/get-started/install-without-nix/" },
{ title: "Distribute your App", url: "/get-started/distribute-your-app/" },
{ title: "Holochain Upgrade 0.1 → 0.2", url: "/get-started/upgrade-holochain/" },
{ title: "Holochain Upgrade 0.1 → 0.2", url: "/get-started/upgrade-holochain-0.2/" },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it okay to rename these? It will break existing links but it'd be nice to have a pattern for these file names going forward. If we do want to maintain links then maybe we could always have the link with no version suffix go to the latest guide?

Copy link
Collaborator

@pdaoust pdaoust Jun 18, 2024

Choose a reason for hiding this comment

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

yup, totally a good idea. The only caveat is that we should always add a 301 redirect to /netlify.toml when we do this, for search results and bookmarks.

[edit] read your whole comment, and I like the idea of having a URL that just 302 redirects to the latest guide too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the 301. The 302 I changed my mind about, because we now have a top level page that lists all the version migration guides so there's an easy place to send people to look for the right guide

{ title: "Holochain Upgrade 0.2 → 0.3", url: "/get-started/upgrade-holochain-0.3/" },
{ title: "Setup For a Local Event", url: "/get-started/at-an-event/" },
]
},
Expand Down
302 changes: 302 additions & 0 deletions src/pages/get-started/upgrade-holochain-0.3.md
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.
Copy link
Contributor

Choose a reason for hiding this comment

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

What I do in cargo.tomls has no effect on the flake or its lock. This suggests to run nix flake update every time I update HDI/HDK. What's the reason for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They're not directly related but the Nix updates should be done at least as frequently. I'll reword this to make it clearer what I'm getting at

!!!

#### 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).
ThetaSinner marked this conversation as resolved.
Show resolved Hide resolved

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`
ThetaSinner marked this conversation as resolved.
Show resolved Hide resolved

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
ThetaSinner marked this conversation as resolved.
Show resolved Hide resolved
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).