Skip to content

Commit 345743e

Browse files
committed
merge
2 parents 18d308e + 81403d4 commit 345743e

File tree

21 files changed

+271
-77
lines changed

21 files changed

+271
-77
lines changed

.github/workflows/build-test.yaml

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ on:
5353
env:
5454
dummy: 17 # change to force cache invalidation
5555
CARGO_TERM_COLOR: always # implicitly adds '--color=always' to all cargo commands
56+
RUST_VERSION: 1.86
57+
GHC_VERSION: 9.10.2
5658

5759
jobs:
5860

5961
fourmolu:
6062
runs-on: ubuntu-latest
61-
if: ${{ !github.event.pull_request.draft }}
6263
steps:
6364

6465
- name: Download fourmolu
@@ -93,25 +94,17 @@ jobs:
9394
9495
rustfmt:
9596
runs-on: ubuntu-latest
96-
if: ${{ !github.event.pull_request.draft }}
97-
98-
strategy:
99-
matrix:
100-
plan:
101-
- rust: "1.82"
102-
10397
steps:
10498
- name: Checkout
10599
uses: actions/checkout@v2
106100
with:
107-
# token: ${{ secrets.CONCORDIUM_CI }}
108101
submodules: recursive
109102

110103
- name: Install Rust
111104
uses: actions-rs/toolchain@v1
112105
with:
113106
profile: minimal
114-
toolchain: ${{ matrix.plan.rust }}
107+
toolchain: ${{ env.RUST_VERSION }}
115108
override: true
116109
components: rustfmt
117110

@@ -127,13 +120,6 @@ jobs:
127120
needs: [fourmolu, rustfmt]
128121
# Use fixed OS version because we install packages on the system.
129122
runs-on: ubuntu-22.04
130-
if: ${{ !github.event.pull_request.draft }}
131-
132-
strategy:
133-
matrix:
134-
plan:
135-
- rust: 1.82
136-
ghc: 9.10.2
137123

138124
steps:
139125
- name: Remove unnecessary files
@@ -164,7 +150,7 @@ jobs:
164150
uses: actions-rs/toolchain@v1
165151
with:
166152
profile: minimal
167-
toolchain: ${{ matrix.plan.rust }}
153+
toolchain: ${{ env.RUST_VERSION }}
168154
override: true
169155
components: clippy, llvm-tools
170156
target: x86_64-pc-windows-gnu
@@ -184,10 +170,10 @@ jobs:
184170
concordium-base/smart-contracts/lib
185171
concordium-node/target
186172
collector/target
187-
key: ${{ runner.os }}-${{ env.dummy }}-rust-deps-${{ matrix.plan.rust }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}-${{ hashFiles('concordium-base/rust-src/**/*.rs','concordium-base/smart-contracts/wasm-chain-integration/**/*.rs')}}
173+
key: ${{ runner.os }}-${{ env.dummy }}-rust-deps-${{ env.RUST_VERSION }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}-${{ hashFiles('concordium-base/rust-src/**/*.rs','concordium-base/smart-contracts/wasm-chain-integration/**/*.rs')}}
188174
restore-keys: |
189-
${{ runner.os }}-${{ env.dummy }}-rust-deps-${{ matrix.plan.rust }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
190-
${{ runner.os }}-${{ env.dummy }}-rust-deps-${{ matrix.plan.rust }}
175+
${{ runner.os }}-${{ env.dummy }}-rust-deps-${{ env.RUST_VERSION }}-${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}
176+
${{ runner.os }}-${{ env.dummy }}-rust-deps-${{ env.RUST_VERSION }}
191177
192178
# HASKELL #
193179

@@ -208,9 +194,9 @@ jobs:
208194
uses: actions/cache@v4
209195
with:
210196
path: ~/.stack
211-
key: ${{ runner.os }}-${{ env.dummy }}-stack-global-${{ matrix.plan.ghc }}-${{ hashFiles('**.yaml') }}
197+
key: ${{ runner.os }}-${{ env.dummy }}-stack-global-${{ env.GHC_VERSION }}-${{ hashFiles('**.yaml') }}
212198
restore-keys: |
213-
${{ runner.os }}-${{ env.dummy }}-stack-global-${{ matrix.plan.ghc }}
199+
${{ runner.os }}-${{ env.dummy }}-stack-global-${{ env.GHC_VERSION }}
214200
- name: Cache '.stack-work'
215201
uses: actions/cache@v4
216202
with:
@@ -220,11 +206,11 @@ jobs:
220206
concordium-consensus/.stack-work
221207
concordium-consensus/haskell-lmdb/.stack-work
222208
223-
key: ${{ runner.os }}-${{ env.dummy }}-stack-work-${{ matrix.plan.ghc }}-${{ hashFiles('**.yaml') }}-${{ steps.cache-keys.outputs.proto_hash }}-${{ steps.cache-keys.outputs.base_hash }}
209+
key: ${{ runner.os }}-${{ env.dummy }}-stack-work-${{ env.GHC_VERSION }}-${{ hashFiles('**.yaml') }}-${{ steps.cache-keys.outputs.proto_hash }}-${{ steps.cache-keys.outputs.base_hash }}
224210
restore-keys: |
225-
${{ runner.os }}-${{ env.dummy }}-stack-work-${{ matrix.plan.ghc }}-${{ hashFiles('**.yaml') }}-${{ steps.cache-keys.outputs.proto_hash }}-
226-
${{ runner.os }}-${{ env.dummy }}-stack-work-${{ matrix.plan.ghc }}-${{ hashFiles('**.yaml') }}-
227-
${{ runner.os }}-${{ env.dummy }}-stack-work-${{ matrix.plan.ghc }}
211+
${{ runner.os }}-${{ env.dummy }}-stack-work-${{ env.GHC_VERSION }}-${{ hashFiles('**.yaml') }}-${{ steps.cache-keys.outputs.proto_hash }}-
212+
${{ runner.os }}-${{ env.dummy }}-stack-work-${{ env.GHC_VERSION }}-${{ hashFiles('**.yaml') }}-
213+
${{ runner.os }}-${{ env.dummy }}-stack-work-${{ env.GHC_VERSION }}
228214
229215
# Compile Haskell sources. This must be done before running checks or tests on the Rust sources.
230216
- name: Build consensus and run tests

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ on:
2222
env:
2323
UBUNTU_VERSION: '22.04'
2424
STATIC_LIBRARIES_IMAGE_TAG: 'rust-1.82_ghc-9.10.2'
25-
RUST_VERSION: '1.82'
25+
RUST_VERSION: '1.86'
2626
STACK_VERSION: '3.7.1'
2727
FLATBUFFERS_VERSION: '23.5.26'
2828
GHC_VERSION: '9.10.2'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ genesis_data
4949
/concordium-consensus/a.out
5050
/concordium-consensus/HSdll.dll
5151
/concordium-consensus/HSdll.dll.a
52+
/concordium-consensus/lib
5253
concordium-node/deps/static-libs
5354
.dir-locals.el
5455
hie.yaml

collector/src/bin/collector.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ use tonic::transport::{channel::Channel, ClientTlsConfig};
1111
#[macro_use]
1212
extern crate log;
1313

14-
#[allow(clippy::large_enum_variant, clippy::enum_variant_names)]
14+
#[allow(
15+
clippy::large_enum_variant,
16+
clippy::enum_variant_names,
17+
clippy::doc_overindented_list_items
18+
)]
1519
mod grpc {
1620
mod plt {
1721
tonic::include_proto!("concordium.v2.plt");
@@ -208,7 +212,7 @@ async fn main() {
208212
}
209213

210214
#[allow(clippy::cognitive_complexity)]
211-
async fn collect_data<'a>(
215+
async fn collect_data(
212216
node_name: NodeName,
213217
grpc_host: String,
214218
conf: &ConfigCli,

concordium-consensus/Setup.hs

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,74 @@ import Distribution.Simple.LocalBuildInfo
44
import Distribution.Simple.Setup
55
import Distribution.Simple.Utils
66
import Distribution.System
7+
import Distribution.Verbosity
78

89
import System.Directory
910
import System.Environment
1011

1112
import Data.Maybe
1213

13-
smartContractRoot = "../concordium-base/smart-contracts"
14+
-- | Notify and execute a command, if fails exit with the same exit code.
15+
runCmd :: Verbosity -> String -> IO ()
16+
runCmd verbosity cmd = do
17+
notice verbosity $ "Running '" ++ cmd ++ "'"
18+
let command : args = words cmd
19+
rawSystemExit verbosity command $ args
1420

15-
makeRust :: Args -> ConfigFlags -> IO HookedBuildInfo
16-
makeRust args flags = do
21+
-- | Path to Concordium Smart Contract Engine rust crate relative to this file.
22+
smartContractEngineCrateRelative = "../concordium-base/smart-contracts/wasm-chain-integration"
23+
24+
-- | Path to plt-scheduler rust crate relative to this file.
25+
pltSchedulerCrateRelative = "../plt-scheduler"
26+
27+
preConfHook :: Args -> ConfigFlags -> IO HookedBuildInfo
28+
preConfHook args flags = do
1729
let verbosity = fromFlag $ configVerbosity flags
18-
rawSystemExit verbosity "mkdir" ["-p", smartContractRoot ++ "/lib"]
1930

20-
-- This way of determining the platform is not ideal.
21-
notice verbosity "Calling 'cargo build'"
22-
rawSystemExit
23-
verbosity
24-
"cargo"
25-
["build", "--release", "--manifest-path", smartContractRoot ++ "/wasm-chain-integration/Cargo.toml", "--features=enable-ffi"]
31+
-- Convert relative paths into absolute paths.
32+
libraryDestination <- canonicalizePath "./lib"
33+
-- Ensure destination directory exists.
34+
runCmd verbosity $ "mkdir -p " ++ libraryDestination
35+
36+
-- Build and copy/symlink Concordium Smart contract Engine library.
37+
smartContractEngineCrate <- canonicalizePath smartContractEngineCrateRelative
38+
runCmd verbosity $ "cargo build --release --locked --features=enable-ffi --manifest-path=" ++ smartContractEngineCrate ++ "/Cargo.toml"
39+
case buildOS of
40+
Windows -> do
41+
runCmd verbosity $ "cp -u " ++ smartContractEngineCrate ++ "/target/release/concordium_smart_contract_engine.dll " ++ libraryDestination
42+
OSX -> do
43+
runCmd verbosity $ "ln -s -f " ++ smartContractEngineCrate ++ "/target/release/libconcordium_smart_contract_engine.a " ++ libraryDestination
44+
runCmd verbosity $ "ln -s -f " ++ smartContractEngineCrate ++ "/target/release/libconcordium_smart_contract_engine.dylib " ++ libraryDestination
45+
_ -> do
46+
runCmd verbosity $ "ln -s -f " ++ smartContractEngineCrate ++ "/target/release/libconcordium_smart_contract_engine.a " ++ libraryDestination
47+
runCmd verbosity $ "ln -s -f " ++ smartContractEngineCrate ++ "/target/release/libconcordium_smart_contract_engine.so " ++ libraryDestination
48+
49+
-- Build and copy/symlink PLT scheduler project
50+
pltSchedulerCrate <- canonicalizePath pltSchedulerCrateRelative
51+
runCmd verbosity $ "cargo build --release --locked --features ffi --manifest-path=" ++ pltSchedulerCrate ++ "/Cargo.toml"
2652
case buildOS of
2753
Windows -> do
28-
notice verbosity "Copying concordium_smart_contract_engine library"
29-
rawSystemExit verbosity "cp" ["-u", smartContractRoot ++ "/wasm-chain-integration/target/release/concordium_smart_contract_engine.dll", smartContractRoot ++ "/lib/"]
30-
-- We remove the static library if it exists. Previously, it would have been copied
31-
-- over, but now we want to just link with the dynamic library, so we ensure it is
32-
-- removed.
33-
rawSystemExit verbosity "rm" ["-f", smartContractRoot ++ "/lib/libconcordium_smart_contract_engine.a"]
54+
runCmd verbosity $ "cp -u " ++ pltSchedulerCrate ++ "/target/release/plt_scheduler.dll " ++ libraryDestination
55+
OSX -> do
56+
runCmd verbosity $ "ln -s -f " ++ pltSchedulerCrate ++ "/target/release/libplt_scheduler.a " ++ libraryDestination
57+
runCmd verbosity $ "ln -s -f " ++ pltSchedulerCrate ++ "/target/release/libplt_scheduler.dylib " ++ libraryDestination
3458
_ -> do
35-
rawSystemExit verbosity "ln" ["-s", "-f", "../wasm-chain-integration/target/release/libconcordium_smart_contract_engine.a", smartContractRoot ++ "/lib/"]
36-
case buildOS of
37-
OSX ->
38-
rawSystemExit verbosity "ln" ["-s", "-f", "../wasm-chain-integration/target/release/libconcordium_smart_contract_engine.dylib", smartContractRoot ++ "/lib/libconcordium_smart_contract_engine.dylib"]
39-
_ ->
40-
rawSystemExit verbosity "ln" ["-s", "-f", "../wasm-chain-integration/target/release/libconcordium_smart_contract_engine.so", smartContractRoot ++ "/lib/libconcordium_smart_contract_engine.so"]
59+
runCmd verbosity $ "ln -s -f " ++ pltSchedulerCrate ++ "/target/release/libplt_scheduler.a " ++ libraryDestination
60+
runCmd verbosity $ "ln -s -f " ++ pltSchedulerCrate ++ "/target/release/libplt_scheduler.so " ++ libraryDestination
4161
return emptyHookedBuildInfo
4262

4363
-- | On Windows, copy the DLL files to the binary install directory. This is to ensure that they
4464
-- are accessible when running the binaries, tests and benchmarks.
45-
copyDlls :: Args -> CopyFlags -> PackageDescription -> LocalBuildInfo -> IO ()
46-
copyDlls _ flags pkgDescr lbi = case buildOS of
65+
postCopyHook :: Args -> CopyFlags -> PackageDescription -> LocalBuildInfo -> IO ()
66+
postCopyHook _ flags pkgDescr lbi = case buildOS of
4767
Windows -> do
4868
let installDirs = absoluteComponentInstallDirs pkgDescr lbi (localUnitId lbi) copydest
49-
let copyLib lib = do
50-
rawSystemExit verbosity "cp" ["-u", smartContractRoot ++ "/lib/" ++ lib ++ ".dll", bindir installDirs]
51-
notice verbosity $ "Copy " ++ lib ++ " to " ++ bindir installDirs
52-
copyLib "concordium_smart_contract_engine"
69+
-- Copy DLL for Concordium Smart Contract Engine
70+
smartContractEngineCrate <- canonicalizePath smartContractEngineCrateRelative
71+
runCmd verbosity $ "cp -u " ++ smartContractEngineCrate ++ "/target/release/concordium_smart_contract_engine.dll " ++ bindir installDirs
72+
-- Copy DLL for PLT scheduler
73+
pltSchedulerCrate <- canonicalizePath pltSchedulerCrateRelative
74+
runCmd verbosity $ "cp -u " ++ pltSchedulerCrate ++ "/target/release/plt_scheduler.dll " ++ bindir installDirs
5375
_ -> return ()
5476
where
5577
distPref = fromFlag (copyDistPref flags)
@@ -59,6 +81,6 @@ copyDlls _ flags pkgDescr lbi = case buildOS of
5981
main =
6082
defaultMainWithHooks $
6183
simpleUserHooks
62-
{ preConf = makeRust,
63-
postCopy = copyDlls
84+
{ preConf = preConfHook,
85+
postCopy = postCopyHook
6486
}

concordium-consensus/package.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ library:
8888
- -O2
8989
- -fno-ignore-asserts
9090

91-
extra-libraries: concordium_smart_contract_engine
91+
extra-libraries:
92+
- concordium_smart_contract_engine
93+
- plt_scheduler
9294

9395
when:
9496
- condition: "!(os(windows)) && !(flag(dynamic))"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
3+
-- |
4+
-- Bindings into the @plt-scheduler@ Rust library exposing safe wrappers.
5+
--
6+
-- Each foreign imported function must match the signature of functions found in @plt-scheduler/src/ffi.rs@.
7+
module Concordium.PLTScheduler (
8+
executeTransaction,
9+
) where
10+
11+
import qualified Data.ByteString as BS
12+
import qualified Data.ByteString.Unsafe as BS
13+
import qualified Data.Word as Word
14+
import qualified Foreign as FFI
15+
import qualified Foreign.C.Types as FFI
16+
17+
-- | Execute a transaction payload modifying the `block_state` accordingly.
18+
-- The caller must ensure to rollback state changes in case of the transaction being rejected.
19+
--
20+
-- See @execute_transaction@ in @plt-scheduler@ rust crate for details.
21+
executeTransaction ::
22+
-- | Transaction payload byte string.
23+
BS.ByteString ->
24+
-- | The events produced or the reject reason.
25+
IO (Either () ())
26+
executeTransaction transactionPayload = do
27+
statusCode <- BS.unsafeUseAsCStringLen transactionPayload $ \(transactionPayloadPtr, transactionPayloadLen) -> do
28+
ffiExecuteTransaction (FFI.castPtr transactionPayloadPtr) (fromIntegral transactionPayloadLen)
29+
case statusCode of
30+
0 -> return $ Right ()
31+
1 -> return $ Left ()
32+
_ -> error "Unexpected status code from calling 'ffiExecuteTransaction'"
33+
34+
foreign import ccall "ffi_execute_transaction"
35+
ffiExecuteTransaction ::
36+
-- | Pointer to transaction payload bytes.
37+
FFI.Ptr Word.Word8 ->
38+
-- | Byte length of transaction payload.
39+
FFI.CSize ->
40+
-- | Status code
41+
IO Word.Word8

concordium-consensus/stack.static.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extra-deps:
99

1010
extra-lib-dirs:
1111
- ../concordium-base/lib
12-
- ../concordium-base/smart-contracts/lib
12+
- ./lib
1313

1414
ghc-options:
1515
# `simpl-tick-factor` parameter here is necessary due to a bug in the ghc: https://gitlab.haskell.org/ghc/ghc/-/issues/14637#note_413425

concordium-consensus/stack.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ extra-deps:
4444
- ../concordium-base
4545

4646
extra-lib-dirs:
47-
- ../concordium-base/lib
48-
- ../concordium-base/smart-contracts/lib
47+
- ../concordium-base/lib
48+
- ./lib
4949

5050
# Override default flag values for local packages and extra-deps
5151
# flags: {}

concordium-node/src/bin/bootstrap_checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn main() -> anyhow::Result<()> {
3737
let regenesis_arc: Arc<Regenesis> = Arc::new(Regenesis::from_blocks(regenesis_blocks));
3838

3939
ensure!(
40-
regenesis_arc.blocks.read().unwrap().len() > 0,
40+
!regenesis_arc.blocks.read().unwrap().is_empty(),
4141
"Bootstrapper can't run without specifying genesis hashes."
4242
);
4343

0 commit comments

Comments
 (0)