Skip to content

Commit 4eb5cd3

Browse files
authored
Fix CI (#2420)
* Clean up code * Update changelog * Fix `account_id` host fn call * Update fixtures * Fix tests * Increase partition size * Fix tests * Fix features * Fix tests * Increase partition count * Restructure testing for dry-run errors * Update `Cargo.lock` * Fix tests, update architecture docs
1 parent 30d6a71 commit 4eb5cd3

File tree

36 files changed

+320
-287
lines changed

36 files changed

+320
-287
lines changed

.github/workflows/ci.yml

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,51 @@ jobs:
451451
# at the same time, hence we use this workaround.
452452
QUICKCHECK_TESTS: 0
453453
run: |
454-
cargo +nightly nextest run --all-features --no-fail-fast --workspace --locked
455-
cargo +nightly test --all-features --no-fail-fast --workspace --doc --locked
454+
cargo +nightly nextest run --all-features --no-fail-fast --workspace --locked --jobs 3
455+
456+
test-docs:
457+
runs-on: ubuntu-latest
458+
needs: [set-image, check]
459+
defaults:
460+
run:
461+
shell: bash
462+
container:
463+
image: ${{ needs.set-image.outputs.IMAGE }}
464+
strategy:
465+
fail-fast: false
466+
matrix:
467+
workspace: [ink, linting]
468+
steps:
469+
- name: Checkout
470+
uses: actions/checkout@v4
471+
with:
472+
fetch-depth: 1
473+
474+
- name: Cache
475+
uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
476+
with:
477+
cache-directories: |
478+
${{ env.CARGO_TARGET_DIR }}
479+
480+
- name: Rust Info
481+
uses: ./.github/rust-info
482+
483+
- name: Test
484+
if: ${{ matrix.workspace == 'ink' }}
485+
env:
486+
# Setting incremental = 0 to reduce compilation artifact size.
487+
# The CI otherwise fails with "no disk space"
488+
# todo Remove again at one point. This is a speed trade-off.
489+
CARGO_INCREMENTAL: 0
490+
# Fix for linking of `linkme` for `cargo test`: https://github.com/dtolnay/linkme/issues/49
491+
RUSTFLAGS: -Clink-dead-code -Clink-arg=-z -Clink-arg=nostart-stop-gc
492+
# Since we run the tests with `--all-features` this implies the feature
493+
# `ink-fuzz-tests` as well -- i.e. the fuzz tests are run.
494+
# There's no way to disable a single feature while enabling all features
495+
# at the same time, hence we use this workaround.
496+
QUICKCHECK_TESTS: 0
497+
run: |
498+
cargo +nightly test --all-features --no-fail-fast --workspace --doc --locked
456499
457500
test-linting:
458501
runs-on: ubuntu-latest
@@ -602,7 +645,7 @@ jobs:
602645
strategy:
603646
fail-fast: false
604647
matrix:
605-
partition: [1, 2, 3, 4, 5, 6]
648+
partition: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
606649
steps:
607650
- name: Checkout
608651
uses: actions/checkout@v4
@@ -620,9 +663,9 @@ jobs:
620663
# Fix for linking of `linkme` for `cargo test`: https://github.com/dtolnay/linkme/issues/49
621664
RUSTFLAGS: -Clink-arg=-z -Clink-arg=nostart-stop-gc -Clink-dead-code
622665
with:
623-
# run all tests with --all-features, which will run the e2e-tests feature if present
666+
# Run all tests with --all-features, which will run the `e2e-tests` feature if present.
624667
args:
625-
/bin/bash -c "scripts/for_all_contracts_exec.sh --path integration-tests --ignore internal/static-buffer --ignore internal/mapping --partition ${{ matrix.partition }}/6 -- \
668+
/bin/bash -c "scripts/for_all_contracts_exec.sh --path integration-tests --ignore internal/static-buffer --ignore internal/mapping --partition ${{ matrix.partition }}/16 -- \
626669
cargo +nightly test --all-features --all --manifest-path {}"
627670

628671
examples-test-mapping:

.github/workflows/issue-notifier.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ jobs:
1717
- awesome-ink
1818
- cargo-contract
1919
- contracts-ui
20+
- docker-images
2021
- ink
2122
- ink-docs
2223
- ink-examples
23-
- ink-waterfall
2424
- ink-workshop
2525
- link
26-
- nft-marketplace-demo
27-
- pallet-contracts-xcm
28-
- smart-bench
2926
- squink-splash-advanced
3027
- squink-splash-beginner
3128
- substrate-contracts-node

.images/pallet-contracts.png

-314 KB
Binary file not shown.

ARCHITECTURE.md

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# ink!ternals
22

3-
todo: rework this doc
4-
53
This document describes the architecture of ink!. The information
64
here targets those who want to understand or modify the inner
75
workings of this project.
86

9-
In general we treat documentation as a first-class citizen.
7+
In general, we treat documentation as a first-class citizen.
108
All crates mentioned below should be documented really well.
119
You can find the crate documentation on docs.rs or for our
1210
`master` branch under GitHub pages. So for `ink` e.g.:
@@ -30,7 +28,7 @@ ink! is composed of a number of crates that are all found in the
3028
This includes getting and setting a smart contracts storage, as well
3129
as the mentioned environmental functions.
3230
* [`metadata`](https://github.com/use-ink/ink/tree/master/crates/metadata):
33-
Describes the contract in a platform agnostic way, i.e. its interface
31+
Describes the contract in a platform-agnostic way, i.e. its interface
3432
and the types, its storage layout, etc.
3533
* [`prelude`](https://github.com/use-ink/ink/tree/master/crates/prelude):
3634
Provides an interface to typical standard library types and
@@ -57,12 +55,19 @@ a `no_std` environment.
5755
Exceptions are `metadata` and `engine`, which cover use-cases that
5856
are only relevant off-chain.
5957

60-
ink! contracts are compiled for a WebAssembly (Wasm) target architecture,
61-
i.e. they are executed in a Wasm sandbox execution environment on the
62-
blockchain itself ‒ hence a `no_std` environment.
63-
More specifically they are executed by the [`pallet-revive`](https://github.com/paritytech/substrate/tree/master/frame/contracts),
64-
a module of the Substrate blockchain framework. This module takes ink!
65-
smart contracts and runs them in a sandbox environment.
58+
ink! contracts are compiled to RISC-V bytecode for
59+
[the PolkaVM interpreter](https://github.com/paritytech/polkavm).
60+
This is how ink! smart contracts are executed on a blockchain:
61+
they are uploaded to a blockchain that runs PolkaVM, PolkaVM then
62+
interprets them.
63+
As contracts are executed in a sandbox execution environment on the
64+
blockchain itself we compile them to a `no_std` environment.
65+
More specifically they are executed by the [`pallet-revive`](https://github.com/paritytech/substrate/tree/master/frame/revive),
66+
a module of the Polkadot SDK blockchain framework. This module takes ink!
67+
smart contracts and runs them in a PolkaVM sandbox environment.
68+
It also provides an API to smart contracts for anything a smart contract
69+
needs: storing + retrieving data, calling other contracts, sending value,
70+
fetching the block number, ….
6671

6772
## Overview
6873

@@ -72,24 +77,49 @@ The above diagram shows the main components of the ink! language
7277
and how they interact. This pipeline is run once you execute
7378
`cargo build` on an ink! smart contract.
7479

75-
The central delegating crate for the ink! eDSL is `ink`.
80+
The central umbrella crate for the ink! eDSL is `ink`.
7681

7782
In the `crates/ink/` folder you'll find three separate
7883
crates on which `ink` relies heavily:
7984

8085
* `ink_macro`: The procedural macros, they take code annotated with e.g.
81-
`[ink::contract]` and forwards it to `ink_ir`.
82-
* `ink_ir`: Defines everything the procedural macro needs in order to
83-
parse, analyze and generate code for ink! smart contracts.
86+
`[ink::contract]` and forward it to `ink_ir`.
87+
* `ink_ir`: The ink! Intermediate Representation (IR). Defines everything
88+
the procedural macro needs in order to parse, analyze and generate code
89+
for ink! smart contracts.
8490
* `ink_codegen`: Generates Rust code from the ink! IR.
8591

92+
The `cargo-expand` tool can be used to display the Rust source code that
93+
`ink_codegen` generates for an ink! contract:
94+
95+
```ignore
96+
cd ink/integration-tests/public/flipper/
97+
cargo expand --no-default-features --target riscv64gc-unknown-none-elf
98+
```
99+
100+
Ideally we'd use the target JSON file from PolkaVM for the `--target`,
101+
but [`cargo-expand`](https://crates.io/crates/cargo-expand) doesn't
102+
support JSON files for this parameter at the time of writing.
103+
86104
## Building ink! contracts
87105

88106
While you can build an ink! smart contract with just `cargo build`, we
89107
recommend using our build tool [`cargo-contract`](https://github.com/use-ink/cargo-contract).
90-
It automatically compiles for the correct WebAssembly target
108+
It automatically compiles for the correct PolkaVM target
91109
architecture and uses an optimal set of compiler flags.
92110

111+
Ann approximation of the build command it will execute is:
112+
113+
```bash
114+
cd ink/integration-tests/public/flipper/
115+
cargo +nightly build
116+
--no-default-features
117+
--target ~/polkavm/crates/polkavm-linker/riscv64emac-unknown-none-polkavm.json
118+
-Zbuild-std="core,alloc"
119+
```
120+
121+
You can also `build` or `check` a contract with this command.
122+
93123
## Allocator
94124

95125
ink! smart contracts use a very simple bump allocator for dynamic
@@ -101,7 +131,9 @@ This was done with the intention of reducing its complexity, which
101131
would have resulted in higher costs for the user (due to increased
102132
gas costs) and a lower transaction throughput. Freeing memory is
103133
irrelevant for our use-case anyway, as the entire memory instance
104-
is set up fresh for each individual contract call anyway.
134+
is set up fresh for each individual contract call.
135+
136+
_todo reviewed until here, below not yet_
105137

106138
## Unstable Rust features in ink!
107139

@@ -135,7 +167,7 @@ This `pallet-revive` is the smart contracts module of
135167

136168
The relationship is as depicted in this diagram:
137169

138-
<img src="./.images/pallet-contracts.png" alt="pallet-revive Interaction" width="800" />
170+
<img src="./.images/pallet-revive.png" alt="pallet-revive Architecture" width="800" />
139171

140172
### Communication with the pallet
141173
ink! uses a static buffer for interacting with `pallet-revive`, i.e.

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
[Unreleased]
88

9-
- Implement contract invokation in off-chain environment engine - [#1957](https://github.com/paritytech/ink/pull/1988)
9+
### Contract delegate can no longer be done by code
1010

1111
## Changed
1212
- Restrict which `cfg` attributes can be used ‒ [#2313](https://github.com/use-ink/ink/pull/2313)
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Add feature flag to compile contracts for `pallet-revive`[#2318](https://github.com/use-ink/ink/pull/2318)
1717
- Support for `caller_is_root` - [#2332] (https://github.com/use-ink/ink/pull/2332)
1818
- Improve support for Solidity ABI calling conventions - [#2411](https://github.com/use-ink/ink/pull/2411)
19+
- Implement contract invocation in off-chain environment engine - [#1957](https://github.com/paritytech/ink/pull/1988)
1920

2021
## Fixed
2122
- [E2E] Have port parsing handle comma-separated list ‒ [#2336](https://github.com/use-ink/ink/pull/2336)
@@ -608,7 +609,7 @@ errors that may come from the smart contracting language itself.
608609

609610
For example, take the case where a contract message is called using an invalid selector.
610611
This is not something a smart contract author should need to define as failure case, nor
611-
is it something that the Contracts pallet needs to be aware of.
612+
is it something that `pallet-revive` needs to be aware of.
612613

613614
Previously, the contract execution would trap if an invalid selector was used, leaving
614615
callers with no way to handle the error gracefully. This can now be handled with the help

0 commit comments

Comments
 (0)