Skip to content

Commit 4d4ee15

Browse files
committed
feat: bump iroha; build executor; use kagami wasm
Signed-off-by: quacumque <quacumque@fastmail.jp>
1 parent 1f15052 commit 4d4ee15

File tree

8 files changed

+78
-62
lines changed

8 files changed

+78
-62
lines changed

executor/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM hyperledger/iroha:experimental-xx-858df795cc8ea480a214ff73f3087a3bbf5f7d85 AS iroha
2+
3+
FROM rust:1.89-bullseye
4+
WORKDIR /app
5+
6+
ARG IROHA_REV=858df795cc8ea480a214ff73f3087a3bbf5f7d85
7+
RUN git init && \
8+
git remote add origin https://github.com/hyperledger-iroha/iroha.git && \
9+
git fetch origin $IROHA_REV && \
10+
git reset --hard FETCH_HEAD
11+
12+
COPY --from=iroha /usr/local/bin/kagami /usr/local/bin/
13+
# TODO: add rust-src component to Iroha's rust-toolchain.toml
14+
RUN mkdir -p outputs && \
15+
rustup component add rust-src && \
16+
kagami wasm build wasm/libs/default_executor --out-file outputs/executor.wasm

generator/executor.wasm

-3.36 MB
Binary file not shown.

generator/mod.ts

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ const dirname = import.meta.dirname;
1414
assert(dirname);
1515

1616
const CONFIG_DIR = path.relative(Deno.cwd(), path.resolve(dirname, "../config"));
17-
const EXECUTOR = path.resolve(dirname, "executor.wasm");
1817

19-
const IROHA_IMAGE = `hyperledger/iroha:experimental-xx-8c67c3eb749af3b9c468d5b601d6fd40e1d8a453`;
18+
const IROHA_IMAGE = `hyperledger/iroha:experimental-xx-858df795cc8ea480a214ff73f3087a3bbf5f7d85`;
2019
const CHAINS = ["aaa", "bbb", "ccc"].slice(0, 1);
2120
const PEERS_ON_CHAIN = 1;
2221
const ACCOUNTS_ON_CHAIN = 3;
@@ -30,8 +29,9 @@ const ASSETS = [
3029

3130
const CONFIG_MOUNT = "/config";
3231

32+
const EXECUTOR_BUILDER_SERVICE_NAME = "executor-builder";
3333
const TRIGGER_BUILDER_SERVICE_NAME = "trigger-builder";
34-
const TRIGGER_WASM_NAME = "hub_chain_trigger.opt.wasm";
34+
const TRIGGER_WASM_NAME = "hub_chain_trigger.wasm";
3535

3636
const Hub = Symbol("hub-chain");
3737
type ChainId = typeof Hub | string;
@@ -76,10 +76,6 @@ const relayAccounts = new Map(CHAINS.map((chain) => {
7676
}];
7777
}));
7878

79-
const genesisKeys = new Map<ChainId, iroha.KeyPair>(
80-
([...CHAINS, Hub] as const).map((chain) => [chain, iroha.KeyPair.random()]),
81-
);
82-
8379
const peerKeys = new Map<ChainId, iroha.KeyPair[]>(
8480
([...CHAINS, Hub] as const).map(
8581
chain => [chain, Array.from({ length: PEERS_ON_CHAIN }, () => iroha.KeyPair.random())],
@@ -225,8 +221,9 @@ function genesisFor(chain: ChainId) {
225221
const topology = peerKeys.get(chain)!.map(x => x.publicKey());
226222

227223
return {
224+
creation_time: new Date().toISOString(),
228225
chain: chainToStr(chain),
229-
executor: "executor.wasm",
226+
executor: "wasm/executor.wasm",
230227
instructions,
231228
wasm_dir: ".",
232229
wasm_triggers: [
@@ -247,6 +244,10 @@ function genesisFor(chain: ChainId) {
247244
commit_time_ms: 1000,
248245
max_clock_drift_ms: 1000,
249246
},
247+
smart_contract: {
248+
fuel: 200_000_000,
249+
memory: 200_000_000,
250+
},
250251
},
251252
};
252253
}
@@ -263,7 +264,6 @@ function chainPublicPort(chain: ChainId): number {
263264

264265
function peerComposeService(chain: ChainId, i: number) {
265266
const peerKey = peerKeys.get(chain)!.at(i)!;
266-
const genesisKey = genesisKeys.get(chain)!;
267267

268268
const id = peerServiceId(chain, i);
269269
const trustedPeers = JSON.stringify(
@@ -276,31 +276,15 @@ function peerComposeService(chain: ChainId, i: number) {
276276

277277
const environment = {
278278
CHAIN: chainToStr(chain),
279+
GENESIS: `${CONFIG_MOUNT}/chain-${chainToStr(chain)}-genesis.json`,
279280
PUBLIC_KEY: peerKey.publicKey().multihash(),
280281
PRIVATE_KEY: peerKey.privateKey().multihash(),
281-
GENESIS_PUBLIC_KEY: genesisKey.publicKey().multihash(),
282282
P2P_PUBLIC_ADDRESS: `${id}:1337`,
283283
TRUSTED_PEERS: trustedPeers,
284284
TERMINAL_COLORS: "true",
285285
};
286286

287-
const isGenesis = i === 0;
288-
if (isGenesis) {
289-
Object.assign(environment, {
290-
GENESIS: "/tmp/genesis.signed.scale",
291-
GENESIS_PRIVATE_KEY: genesisKey.privateKey().multihash(),
292-
});
293-
}
294-
295-
const command = isGenesis
296-
? `/bin/sh -c "
297-
kagami genesis sign ${CONFIG_MOUNT}/chain-${chainToStr(chain)}-genesis.json \\\n\
298-
--public-key $GENESIS_PUBLIC_KEY \\\n\
299-
--private-key $GENESIS_PRIVATE_KEY \\\n\
300-
--out-file /tmp/genesis.signed.scale \\\n\
301-
&& irohad --config ${CONFIG_MOUNT}/irohad.toml
302-
"`
303-
: `irohad --config ${CONFIG_MOUNT}/irohad.toml`;
287+
const command = `irohad --config ${CONFIG_MOUNT}/irohad.toml`;
304288

305289
const ports = i === 0 ? [`${chainPublicPort(chain)}:8080`] : [];
306290

@@ -318,6 +302,9 @@ function peerComposeService(chain: ChainId, i: number) {
318302
[TRIGGER_BUILDER_SERVICE_NAME]: {
319303
condition: "service_completed_successfully",
320304
},
305+
[EXECUTOR_BUILDER_SERVICE_NAME]: {
306+
condition: "service_completed_successfully",
307+
},
321308
},
322309
healthcheck: {
323310
test: "test $(curl -s http://127.0.0.1:8080/status/blocks) -gt 0",
@@ -419,13 +406,25 @@ function triggerBuilderService() {
419406
build: {
420407
context: "../trigger",
421408
},
422-
volumes: [`../config/wasm:/app/outputs`],
409+
volumes: [`../config/wasm:/usr/wasm`],
410+
command: `\
411+
sh -c "
412+
cp /app/outputs/* /usr/wasm/ &&
413+
echo 'Copied WASMs'
414+
"`,
423415
};
424416
}
425417

418+
function defaultExecutorBuilderService() {
419+
const cfg = triggerBuilderService();
420+
cfg.build.context = `../executor`;
421+
return cfg;
422+
}
423+
426424
const dockerCompose = {
427425
services: {
428426
[TRIGGER_BUILDER_SERVICE_NAME]: triggerBuilderService(),
427+
[EXECUTOR_BUILDER_SERVICE_NAME]: defaultExecutorBuilderService(),
429428
...peerServices(),
430429
...relayServices(),
431430
// ui: uiService(),
@@ -449,10 +448,6 @@ for (const chain of ALL_CHAINS) {
449448
}
450449
}
451450

452-
const executorDest = path.join(CONFIG_DIR, "executor.wasm");
453-
$.logStep("Writing", executorDest);
454-
await Deno.copyFile(EXECUTOR, executorDest);
455-
456451
await writeConfig("ui.json", JSON.stringify(uiConfig(), null, 2));
457452

458453
$.logStep("Completed!", `Now you can run "docker-compose -f ${path.join(CONFIG_DIR, "docker-compose.yml")} up"`);

trigger/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.dockerignore
2+
.gitignore
3+
Dockerfile
4+
/target

trigger/Cargo.lock

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

trigger/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ debug = []
99
crate-type = ['cdylib']
1010

1111
[dependencies]
12-
iroha_crypto = { git = "https://github.com/hyperledger-iroha/iroha.git", rev = "d77d19d2", default-features = false }
13-
iroha_trigger = { git = "https://github.com/hyperledger-iroha/iroha.git", rev = "d77d19d2" }
12+
iroha_crypto = { git = "https://github.com/hyperledger-iroha/iroha.git", rev = "858df795", default-features = false }
13+
iroha_trigger = { git = "https://github.com/hyperledger-iroha/iroha.git", rev = "858df795" }
1414

1515
anyhow = { version = "1.0", default-features = false }
1616
dlmalloc = { version = "0.2.6", features = ["global"] }

trigger/Dockerfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
FROM hyperledger/iroha:experimental-xx-858df795cc8ea480a214ff73f3087a3bbf5f7d85 AS iroha
2+
13
FROM rust:1.89-bullseye
24
WORKDIR /app
35

46
COPY rust-toolchain.toml .
57
RUN rustup install
68

7-
COPY Cargo.lock Cargo.toml .
8-
COPY .cargo .cargo
9-
COPY src src
10-
RUN cargo build --release
11-
12-
RUN mkdir -p outputs && cp target/wasm32-unknown-unknown/release/hub_chain_trigger.wasm ./outputs/
13-
14-
RUN apt-get update && apt-get install binaryen
15-
RUN cd outputs && wasm-opt hub_chain_trigger.wasm -o hub_chain_trigger.opt.wasm -Oz --vacuum
9+
COPY . .
10+
RUN --mount=type=cache,target=/root/.cargo/git/db \
11+
--mount=type=cache,target=/root/.cargo/registry/cache \
12+
--mount=type=cache,target=/root/.cargo/registry/index \
13+
cargo fetch
14+
COPY --from=iroha /usr/local/bin/kagami /usr/local/bin/
15+
RUN mkdir -p outputs && kagami wasm build . --out-file outputs/hub_chain_trigger.wasm

trigger/rust-toolchain.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[toolchain]
2-
channel = "1.89.0"
2+
channel = "nightly-2025-05-08"
33
targets = ["wasm32-unknown-unknown"]
4+
components = ["rust-src"]

0 commit comments

Comments
 (0)