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

Implement ordered maps for smart contracts #405

Merged
merged 38 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8f2016b
Add quick in-memory version of state-btree
limemloh Feb 15, 2024
3779ada
Move Btree nodes and values into the contract state
limemloh Feb 20, 2024
5e9d818
Btree: use keys instead of value ID
limemloh Feb 20, 2024
25d5673
BTree: add more docs and use maybeuninit for node keys
limemloh Feb 22, 2024
54c5714
Implement remove and fix a few insert bugs
limemloh Feb 27, 2024
39b0a7d
Reuse already loaded nodes when deleting, fixing some issues aswell
limemloh Feb 28, 2024
2ef3354
Reduce the number of state lookups when deleting
limemloh Feb 29, 2024
692a51d
Implement `iter` and `clear`
limemloh Mar 1, 2024
461c6f0
Improve documentation of statebtreemap
limemloh Mar 1, 2024
7b676dd
Document StateBTreeMap and StateBTreeSet + add few more methods
limemloh Mar 1, 2024
78352b0
Fix clippy feedback
limemloh Mar 4, 2024
c9ae82b
Update changelog
limemloh Mar 4, 2024
cb19bea
StateBTreeSet::remove now avoids searching ahead for replacement key
limemloh Mar 5, 2024
50dd73b
Address review comments
limemloh Mar 6, 2024
4427511
Address some more review comments
limemloh Mar 8, 2024
1365d24
Restructure StateBTreeSet/Map into a separate module
limemloh Mar 11, 2024
33e731b
Fix related to empty root after removal, dublicate keys after split
limemloh Mar 12, 2024
fa9c07f
Introduce unit-tests using quickcheck for the btree
limemloh Mar 12, 2024
e0cb873
Introduce concordium-std feature 'internal-wasm-test'
limemloh Mar 12, 2024
04460a7
Fix clippy and doc complaints
limemloh Mar 12, 2024
01783cf
Fix no_std issues in state_btree
limemloh Mar 12, 2024
b69be0c
Remove type parameter S from StateBTreeMap and StateBTreeSet
limemloh Mar 13, 2024
99b461b
Add quickcheck tests for iter, higher and lower
limemloh Mar 14, 2024
4a91934
Add unit tests for eq_or_lower and eq_or_higher
limemloh Mar 14, 2024
c73d37f
Add must_use and warning for insert on StateMap
limemloh Mar 14, 2024
fd57aee
Add quickcheck test for clearing btree, checking state
limemloh Mar 14, 2024
166687b
Update btree documentation related to benchmarks and update rust sdk
limemloh Mar 21, 2024
54cb24a
Merge remote-tracking branch 'origin/main' into state-btree-map
limemloh Mar 21, 2024
29de383
Add guide for choosing the right collection (#409)
limemloh Mar 22, 2024
b4f08f8
Update rust version and fix clippy
limemloh Mar 22, 2024
aeaae93
Fix warnings
limemloh Mar 22, 2024
c20981a
Address review comments
limemloh Mar 25, 2024
5e7fdce
Update rust-sdk
limemloh Mar 25, 2024
3a9b1c6
Update rust version in contract-testing CI
limemloh Mar 25, 2024
e3b3d6f
Address yet another round of comments
limemloh Mar 25, 2024
d59719a
Merge remote-tracking branch 'origin/main' into state-btree-map
limemloh Mar 26, 2024
1702ccf
Address review comments
limemloh Mar 27, 2024
66a283e
Address last round of comments
limemloh Mar 27, 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
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 <[email protected]>"]
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"]
limemloh marked this conversation as resolved.
Show resolved Hide resolved

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