Skip to content

Commit

Permalink
Merge branch 'main' into code-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli authored Apr 2, 2024
2 parents 51ef87d + 1a9e385 commit 9164bb1
Show file tree
Hide file tree
Showing 157 changed files with 3,521 additions and 5,880 deletions.
97 changes: 97 additions & 0 deletions .github/workflows/try-runtime.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: try-runtime
on:
schedule:
- cron: '0 6 * * 0' # At 00:00 on Sunday
issue_comment:
types: [created]
pull_request:
types: [labeled]
paths:
- '**.rs'
- .github/workflows/try-runtime.yml
jobs:
try-runtime:
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
chain: [altair, centrifuge]
if: >
github.event_name == 'schedule' ||
contains(github.event.pull_request.labels.*.name, 'D8-migration') ||
(github.event_name == 'issue_comment' &&
contains(github.event.comment.body, '/try-runtime') &&
github.event.issue.pull_request != '')
runs-on: ubuntu-latest-4-cores
name: "${{ matrix.chain }}"
steps:
- name: Check out code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab #3.5.2

- name: Get PR author and commenter
id: get-users
if: github.event_name == 'issue_comment'
run: |
PR_AUTHOR=$(gh pr view ${{ github.event.issue.number }} --json author --jq .author.login)
COMMENT_AUTHOR="${{ github.event.comment.user.login }}"
echo "::set-output name=pr_author::$PR_AUTHOR"
echo "::set-output name=comment_author::$COMMENT_AUTHOR"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check if commenter is PR author and a repo contributor
if: >
steps.get-users.outputs.pr_author == steps.get-users.outputs.comment_author &&
github.event_name == 'issue_comment'
run: |
if [[ "${{ steps.get-users.outputs.pr_author }}" != "${{ steps.get-users.outputs.comment_author }}" ]]; then
echo "PR author is not the comment author."
exit 1
fi
CONTRIBUTOR_CHECK=$(gh api repos/${{ github.repository }}/contributors --jq '.[].login | select(. == "${{ steps.get-users.outputs.comment_author }}")')
if [[ -z "$CONTRIBUTOR_CHECK" ]]; then
echo "Commenter is not a contributor."
exit 1
fi
echo "Commenter is a contributor and PR author."
- name: Prep build on Ubuntu
uses: ./.github/actions/prep-ubuntu
with:
cache: enabled
GWIP: ${{ secrets.GWIP_SCCACHE }}
GSA: ${{ secrets.GSA_SCCACHE }}

# - name: Install try-runtime-cli
# run: cargo install --git https://github.com/paritytech/try-runtime-cli --tag v0.5.4 --locked
- name: cargo build
run: ./ci/run-check.sh -F try-runtime
env:
TARGET: cargo-build
RUSTC_WRAPPER: "sccache"

- name: Run try-runtime
run: ./ci/run-check.sh "${{ matrix.chain }}"
env:
TARGET: try-runtime

notify-slack:
needs: try-runtime
if: always() && needs.try-runtime.result == 'failure' && github.event_name == 'schedule'
runs-on: ubuntu-latest
steps:
- name: Notify Slack
uses: rtCamp/action-slack-notify@b24d75fe0e728a4bf9fc42ee217caa686d141ee8 #v2.2.1
env:
SLACK_CHANNEL: eng-protocol-general
SLACK_COLOR: '#FF0000'
SLACK_ICON: "https://github.githubassets.com/assets/GitHub-Mark-ea2971cee799.png"
SLACK_MESSAGE: |
Weekly try-runtime job failed on main branch. Please check:
<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|GHA Job URL>
SLACK_TITLE: 'Job Failure Notification'
SLACK_USERNAME: "Centrifuge GHA Bot"
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion ci/run-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,26 @@ case $TARGET in
docs-build)
RUSTDOCFLAGS="-D warnings" cargo doc --all --no-deps
;;


try-runtime)
if [ "$1" == "altair" ]; then
echo "Running try-runtime for altair"
RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace \
cargo run --release --features try-runtime try-runtime \
--runtime target/release/wbuild/altair-runtime/altair_runtime.wasm \
--chain altair on-runtime-upgrade live \
--uri wss://fullnode.altair.centrifuge.io:443
elif [ "$1" == "centrifuge" ]; then
echo "Running try-runtime for centrifuge"
RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace \
cargo run --release --features try-runtime try-runtime \
--runtime target/release/wbuild/centrifuge-runtime/centrifuge_runtime.wasm \
--chain centrifuge on-runtime-upgrade live --uri wss://fullnode.centrifuge.io:443
else
echo "Invalid argument. Please specify 'altair' or 'centrifuge'."
exit 1
fi
;;
subalfred)
# Find all child directories containing Cargo.toml files
# TODO: Filter by crates found in the workspace
Expand Down
70 changes: 21 additions & 49 deletions docs/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Initialize your Wasm Build environment:

Build Wasm and native code:

- Prerequisites : cmake, libclang-dev
- Prerequisites : `cmake`, `libclang-dev`

```bash
cargo build --release
Expand All @@ -28,7 +28,7 @@ and another one to verify how it works in a more real environment as a parachain
The following command will run the unit and integration tests:

```bash
cargo +nightly test --workspace --release --features runtime-benchmarks,try-runtime
cargo test --workspace --release --features runtime-benchmarks,try-runtime
```

### Environment tests
Expand Down Expand Up @@ -58,7 +58,7 @@ It runs a [collator](https://wiki.polkadot.network/docs/learn-collator) node:
*Note: the command above will show logs and block until the parachain is stopped.
If you had a previous state, you can reset the node using `purge` after the command.*

Similar to the relay chain, you can explore the parachain using the [polkadot.js (on localhost:11946)](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A11946#/explorer) client.
Similar to the relay chain, you can explore the parachain using the [polkadot.js (on localhost:11936)](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2Flocalhost%3A11936#/explorer) client.
You will see the block production frozen until you connect it to the relay chain.

By default, the initialized parachain will have the id `2000`.
Expand All @@ -84,33 +84,28 @@ You can play with it from the parachain client, make transfers, inspect events,
## Linting
### Source code
Lint the source code with `cargo +nightly fmt`. This excludes certain paths (defined in `rustfmt.toml`) that we want to stay as close as possible to `paritytech/substrate` to simplify upgrading to new releases.
Lint the source code with `cargo fmt --all`. This excludes certain paths (defined in `rustfmt.toml`) that we want to stay as close as possible to `paritytech/substrate` to simplify upgrading to new releases.
### Cargo.toml files
1. Install [taplo](https://github.com/tamasfe/taplo) with `cargo install taplo-cli`.
2. Lint the `Cargo.toml` files with `taplo fmt`.
## Verifying Runtime
1. Check out the commit at which the runtime was built.
2. Run `TARGET=build-runtime RUST_TOOLCHAIN=nightly ./ci/script.sh`
3. A similar output is generated
2. Build the WASM via `cargo build --release`
3. Ensure the output from [subwasm](https://github.com/chevdor/subwasm) matches the release one. Run `subwasm info ./target/release/wbuild/centrifuge-runtime/centrifuge_runtime.compact.compressed.wasm`, which creates an output like the following one:
```
✨ Your Substrate WASM Runtime is ready! ✨
Summary:
Generator : srtool v0.9.5
GIT commit : 27326e69481f08313d6048da1500befe209bdf71
GIT tag : v0.0.3
GIT branch : master
Time : 2020-03-20T11:00:24Z
Rustc : rustc 1.43.0-nightly (5e7af4669 2020-02-16)
Size : 928 KB (950464 bytes)
Content : 0x0061736d0100000001c2022f60037f7f...3436363920323032302d30322d313629
Package : centrifuge-runtime
Proposal : 0x5c3d2cd41d70c514566c9b512743ad229fa96518061fe21c8178ba43cfcf16dc
SHA256 : 3f0d2e98e2351144027826f26277bda90e5fabc13f0945fc8fec13d116602e2a
Wasm : ./target/srtool/release/wbuild/centrifuge-runtime/centrifuge_runtime.compact.wasm
🏋️ Runtime size: 1.819 MB (1,906,886 bytes)
🗜 Compressed: Yes, 78.50%
✨ Reserved meta: OK - [6D, 65, 74, 61]
🎁 Metadata version: V14
🔥 Core version: centrifuge-1025 (centrifuge-1.tx2.au1)
🗳️ system.setCode hash: 0x210cdf71ee5c5fbea3dc5090c596a992b148030474121b481a856433eb5720f3
🗳️ authorizeUpgrade hash: 0x319e30838e1acc9dd071261673060af687704430c45b14cdb5fc97ec561e2a12
🗳️ Blake2-256 hash: 0xb7f74401c52ee8634ad28fe91e8a6b1debb802d4d2058fdda184a6f2746477f6
📦 IPFS: https://www.ipfs.io/ipfs/QmS3GDmbGKvcmSd7ca1AN9B34BW3DuDEDQ1iSLXgkjktpG
```
4. `Proposal` hash should match the runtime upgrade proposal
4. The `Blake2-256` hash should match the hex of the `authorizeUpgrade` call.
See more [here](docs/runtime-upgrade.md).
## Generate new Spec and Parachain files
Expand Down Expand Up @@ -143,13 +138,13 @@ the collator node the parachain will be running on.
# Updating to a newer version of Polkadot
When a new version of Polkadot is released, companion releases happen for the other
parity projects such as Substrate and Cumulus, as well as for other third-party projects
such as the `orml` pallets, `xcm-simulator`, etc.
parity projects such as the Polkadot SDK, as well as for other third-party projects
such as the `ORML` pallets, `xcm-simulator`, etc.
Therefore, updating this repository to a new version of Polkadot means updating all of these dependencies
(internal and external to Centrifuge ) and have them all aligned on the same version of Polkadot.
_Note: When we say "new version of Polkadot", we implicitly mean "Polkadot, Substrate, Cumulus"._
_Note: When we say "new version of Polkadot", we implicitly mean "Polkadot SDK, Frontier, ORML"._
The high level flow to upgrade to a newer version of Polkadot is:
Expand All @@ -172,9 +167,7 @@ The high level flow to upgrade to a newer version of Polkadot is:
```shell
export POLKADOT_NEW_VERSION="<version>"; # for example, 0.9.32
diener update --polkadot --branch release-v$POLKADOT_NEW_VERSION;
diener update --substrate --branch polkadot-v$POLKADOT_NEW_VERSION;
diener update --cumulus --branch polkadot-v$POLKADOT_NEW_VERSION;
diener update --polkadot-sdk --branch release-v$POLKADOT_NEW_VERSION;
```
**Note**: This step only updates the versions of those dependencies across the repository. Any breaking changes introduced
Expand Down Expand Up @@ -216,26 +209,5 @@ by the new versions will have to be dealt with manually afterwards.
If you face compilation errors like "type X doesn't implement trait Y", and the compiler
doesn't suggest you import any particular trait, experience is that there are different versions
of Polkadot|Substrate|Cumulus being pulled; The `cargo patch` rules in `Cargo.toml` should be handling that so if this
still happens it's likely because some new crate of Polkadot|Substrate|Cumulus is being pulled directly or indirectly
still happens it's likely because some new crate of Polkadot SDK or Frontier is being pulled directly or indirectly
and we need to include that crate in the appropriate `cargo patch` rule.
Running `nix --extra-experimental-features "nix-command flakes" build` should fail if multiple versions of a crate is
being pulled and, therefore, not yet being handled by any `cargo patch` rules, making it very easy to spot the crate
causing the trouble.

## NIX

The CI runs a `nix-build` job that executes `nix build` on the entire repository. This job fails if the output
`cargoSha256` for the revision being built does not match the expected value defined in `flake.nix`.

Whenever a dependency is added, removed, or updated, said `cargoSha256` value defined in `flake.nix` needs to be updated.
To do that, you need:

1. [Install Nix](https://nixos.org/download.html)

2. On your feature branch, run:
```shell
nix --extra-experimental-features "nix-command flakes" build
```

3. Use the new `cargoSha256` output provided on step 2. and update it in `flake.nix`
4. Commit and push
21 changes: 0 additions & 21 deletions libs/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,27 +471,6 @@ pub trait TryConvert<A, B> {
fn try_convert(a: A) -> Result<B, Self::Error>;
}

/// Converts a balance value into an asset balance.
// TODO: Remove usage for the one from frame_support::traits::tokens once we are
// on the same Polkadot version
pub trait ConversionToAssetBalance<InBalance, AssetId, AssetBalance> {
fn to_asset_balance(
balance: InBalance,
asset_id: AssetId,
) -> Result<AssetBalance, DispatchError>;
}

/// Converts an asset balance value into balance.
// TODO: Remove usage for the one from frame_support::traits::tokens once we are
// on the same Polkadot version
pub trait ConversionFromAssetBalance<AssetBalance, AssetId, OutBalance> {
type Error;
fn from_asset_balance(
balance: AssetBalance,
asset_id: AssetId,
) -> Result<OutBalance, Self::Error>;
}

// TODO: Probably these should be in a future cfg-utils.
// Issue: https://github.com/centrifuge/centrifuge-chain/issues/1380

Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ is-it-maintained-open-issues = { repository = "centrifuge/centrifuge-chain" }

[package]
name = "centrifuge-chain"
version = "0.10.37"
version = "0.10.39"
description = "Centrifuge chain implementation in Rust."
build = "build.rs"
default-run = "centrifuge-chain"
Expand Down
Loading

0 comments on commit 9164bb1

Please sign in to comment.