Skip to content

Commit

Permalink
Merge pull request #405 from Concordium/state-btree-map
Browse files Browse the repository at this point in the history
Implement ordered maps for smart contracts
  • Loading branch information
abizjak authored Mar 27, 2024
2 parents d874117 + 66a283e commit 670ffab
Show file tree
Hide file tree
Showing 24 changed files with 2,904 additions and 536 deletions.
76 changes: 46 additions & 30 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:
RUST_FMT: nightly-2023-04-01
RUST_VERSION: "1.73"
RUST_VERSION_TESTING_LIBRARY: "1.73"
CARGO_CONCORDIUM_VERSION: "3.2.0"
CARGO_CONCORDIUM_VERSION: "3.3.0"

jobs:
rustfmt:
Expand Down Expand Up @@ -103,6 +103,33 @@ jobs:
run: |
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features --color=always
# Run unit-tests for concordium-std compiled to wasm using cargo concordium test.
std-internal-wasm-test:
name: concordium-std internal wasm tests
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: recursive

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_VERSION }}

- name: Install Wasm target
run: rustup target install wasm32-unknown-unknown

- name: Run internal wasm unit test
working-directory: concordium-std
run: |
curl -L https://github.com/Concordium/concordium-smart-contract-tools/releases/download/releases/cargo-concordium/${CARGO_CONCORDIUM_VERSION}/cargo-concordium-linux-amd64 -o /tmp/cargo-concordium
chmod +x /tmp/cargo-concordium
sudo mv /tmp/cargo-concordium /usr/bin/cargo-concordium
cargo concordium test --only-unit-tests -- --features internal-wasm-test
# All templates are generated with the `cargo-generate` command and it is checked that the 'cargo test' command
# can be executed without errors on the generated smart contracts.
cargo-generate-templates:
Expand Down Expand Up @@ -145,10 +172,9 @@ jobs:
# Run all tests, including doc tests.
- name: Run cargo test
run: |
CARGO_CCD=cargo-concordium_${{ env.CARGO_CONCORDIUM_VERSION }}
wget https://distribution.concordium.software/tools/linux/$CARGO_CCD
chmod +x $CARGO_CCD
sudo mv $CARGO_CCD /usr/bin/cargo-concordium
curl -L https://github.com/Concordium/concordium-smart-contract-tools/releases/download/releases/cargo-concordium/${CARGO_CONCORDIUM_VERSION}/cargo-concordium-linux-amd64 -o /tmp/cargo-concordium
chmod +x /tmp/cargo-concordium
sudo mv /tmp/cargo-concordium /usr/bin/cargo-concordium
mv $PROJECT_NAME ${{ runner.temp }}/
cd ${{ runner.temp }}/$PROJECT_NAME
cargo concordium test --out "./concordium-out/module.wasm.v1"
Expand Down Expand Up @@ -195,10 +221,9 @@ jobs:
# Run all tests, including doc tests.
- name: Run cargo test
run: |
CARGO_CCD=cargo-concordium_${{ env.CARGO_CONCORDIUM_VERSION }}
wget https://distribution.concordium.software/tools/linux/$CARGO_CCD
chmod +x $CARGO_CCD
sudo mv $CARGO_CCD /usr/bin/cargo-concordium
curl -L https://github.com/Concordium/concordium-smart-contract-tools/releases/download/releases/cargo-concordium/${CARGO_CONCORDIUM_VERSION}/cargo-concordium-linux-amd64 -o /tmp/cargo-concordium
chmod +x /tmp/cargo-concordium
sudo mv /tmp/cargo-concordium /usr/bin/cargo-concordium
mv $PROJECT_NAME ${{ runner.temp }}/
cd ${{ runner.temp }}/$PROJECT_NAME
cargo concordium test --out "./concordium-out/module.wasm.v1"
Expand Down Expand Up @@ -560,18 +585,9 @@ jobs:
args: --manifest-path ${{ matrix.lib-crates }} --target=${{ matrix.target }} --features=${{ matrix.features }} -- -D warnings

check-std-no-std:
name: Build on nightly,
name: Build no-std on nightly,
runs-on: ubuntu-latest
needs: rustfmt
strategy:
matrix:
target:
- wasm32-unknown-unknown

crates:
- concordium-std/Cargo.toml
- concordium-cis2/Cargo.toml

steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand All @@ -583,14 +599,16 @@ jobs:
with:
profile: minimal
toolchain: nightly
target: ${{ matrix.target }}
target: wasm32-unknown-unknown
override: true

- name: Run cargo check with no-std
uses: actions-rs/cargo@v1
with:
command: build
args: --manifest-path ${{ matrix.crates }} --target=${{ matrix.target }} --no-default-features
- name: Run no-std build concordium-std
working-directory: concordium-std
run: cargo build --target wasm32-unknown-unknown --no-default-features --features bump_alloc

- name: Run no-std build concordium-cis2
working-directory: concordium-cis2
run: cargo build --target wasm32-unknown-unknown --no-default-features --features concordium-std/bump_alloc

check-no-std-examples:
name: Build on nightly,
Expand Down Expand Up @@ -864,11 +882,9 @@ jobs:

- name: Download and install Cargo Concordium
run: |
CARGO_CCD=cargo-concordium_${{ env.CARGO_CONCORDIUM_VERSION }}
wget https://distribution.concordium.software/tools/linux/$CARGO_CCD
chmod +x $CARGO_CCD
sudo mv $CARGO_CCD /usr/bin/cargo-concordium
curl -L https://github.com/Concordium/concordium-smart-contract-tools/releases/download/releases/cargo-concordium/${CARGO_CONCORDIUM_VERSION}/cargo-concordium-linux-amd64 -o /tmp/cargo-concordium
chmod +x /tmp/cargo-concordium
sudo mv /tmp/cargo-concordium /usr/bin/cargo-concordium
# The 'smart-contract-upgrade' example has a v1 and v2 contract and the tests in v1 needs the wasm module from v2 for upgrading.
- name: Build contract-upgrade version 2 module if needed
if: ${{ matrix.crates == 'examples/smart-contract-upgrade/contract-version1' }}
Expand Down
1 change: 1 addition & 0 deletions concordium-std/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
via the `HasHost::contract_module_reference` and `HasHost::contract_name` functions.
These are only available from protocol version 7, and as such are guarded by the
`p7` feature flag.
- Add two ordered collections: `StateBTreeMap` and `StateBTreeSet`. These are based on [B-Tree](https://en.wikipedia.org/wiki/B-tree), but where each node is stored in the low-level smart contract key-value store. Use one of these when needing operations related to the ordering of the keys, such as `higher(k)` providing the smallest key in collection which is stricly greater than `k`.

## concordium-std 10.0.0 (2024-02-22)

Expand Down
8 changes: 6 additions & 2 deletions concordium-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "concordium-std"
version = "10.0.0"
authors = ["Concordium <developers@concordium.com>"]
edition = "2021"
rust-version = "1.66"
rust-version = "1.73"
license = "MPL-2.0"
description = "A standard library for writing smart contracts for the Concordium blockchain in Rust."
homepage = "https://github.com/Concordium/concordium-rust-smart-contracts/"
Expand All @@ -29,6 +29,9 @@ features = ["smart-contract"]
default = ["std"]
std = ["concordium-contracts-common/std"]
wasm-test = ["concordium-contracts-common/wasm-test"]
# Own internal wasm-tests leak out to the smart contracts using this library,
# so a separate feature 'internal-wasm-test' is introduced for these.
internal-wasm-test = ["wasm-test", "concordium-quickcheck"]
build-schema = ["concordium-contracts-common/build-schema"]
crypto-primitives = ["sha2", "sha3", "secp256k1", "ed25519-zebra"]
concordium-quickcheck = ["getrandom", "quickcheck", "concordium-contracts-common/concordium-quickcheck", "std"]
Expand All @@ -38,7 +41,8 @@ bump_alloc = []
p7 = []

[lib]
crate-type = ["rlib"]
# cdylib is needed below to compile into a wasm module with internal unit tests.
crate-type = ["cdylib", "rlib"]

[profile.release]
# Tell `rustc` to optimize for small code size.
Expand Down
Loading

0 comments on commit 670ffab

Please sign in to comment.