Skip to content

Commit d9b31c6

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

File tree

8 files changed

+78
-61
lines changed

8 files changed

+78
-61
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 & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ assert(dirname);
1616
const CONFIG_DIR = path.relative(Deno.cwd(), path.resolve(dirname, "../config"));
1717
const EXECUTOR = path.resolve(dirname, "executor.wasm");
1818

19-
const IROHA_IMAGE = `hyperledger/iroha:experimental-xx-8c67c3eb749af3b9c468d5b601d6fd40e1d8a453`;
19+
const IROHA_IMAGE = `hyperledger/iroha:experimental-xx-858df795cc8ea480a214ff73f3087a3bbf5f7d85`;
2020
const CHAINS = ["aaa", "bbb", "ccc"].slice(0, 1);
2121
const PEERS_ON_CHAIN = 1;
2222
const ACCOUNTS_ON_CHAIN = 3;
@@ -30,8 +30,9 @@ const ASSETS = [
3030

3131
const CONFIG_MOUNT = "/config";
3232

33+
const EXECUTOR_BUILDER_SERVICE_NAME = "executor-builder";
3334
const TRIGGER_BUILDER_SERVICE_NAME = "trigger-builder";
34-
const TRIGGER_WASM_NAME = "hub_chain_trigger.opt.wasm";
35+
const TRIGGER_WASM_NAME = "hub_chain_trigger.wasm";
3536

3637
const Hub = Symbol("hub-chain");
3738
type ChainId = typeof Hub | string;
@@ -76,10 +77,6 @@ const relayAccounts = new Map(CHAINS.map((chain) => {
7677
}];
7778
}));
7879

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

227224
return {
225+
creation_time: new Date().toISOString(),
228226
chain: chainToStr(chain),
229-
executor: "executor.wasm",
227+
executor: "wasm/executor.wasm",
230228
instructions,
231229
wasm_dir: ".",
232230
wasm_triggers: [
@@ -247,6 +245,10 @@ function genesisFor(chain: ChainId) {
247245
commit_time_ms: 1000,
248246
max_clock_drift_ms: 1000,
249247
},
248+
smart_contract: {
249+
fuel: 200_000_000,
250+
memory: 200_000_000,
251+
},
250252
},
251253
};
252254
}
@@ -263,7 +265,6 @@ function chainPublicPort(chain: ChainId): number {
263265

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

268269
const id = peerServiceId(chain, i);
269270
const trustedPeers = JSON.stringify(
@@ -276,31 +277,15 @@ function peerComposeService(chain: ChainId, i: number) {
276277

277278
const environment = {
278279
CHAIN: chainToStr(chain),
280+
GENESIS: `${CONFIG_MOUNT}/chain-${chainToStr(chain)}-genesis.json`,
279281
PUBLIC_KEY: peerKey.publicKey().multihash(),
280282
PRIVATE_KEY: peerKey.privateKey().multihash(),
281-
GENESIS_PUBLIC_KEY: genesisKey.publicKey().multihash(),
282283
P2P_PUBLIC_ADDRESS: `${id}:1337`,
283284
TRUSTED_PEERS: trustedPeers,
284285
TERMINAL_COLORS: "true",
285286
};
286287

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`;
288+
const command = `irohad --config ${CONFIG_MOUNT}/irohad.toml`;
304289

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

@@ -318,6 +303,9 @@ function peerComposeService(chain: ChainId, i: number) {
318303
[TRIGGER_BUILDER_SERVICE_NAME]: {
319304
condition: "service_completed_successfully",
320305
},
306+
[EXECUTOR_BUILDER_SERVICE_NAME]: {
307+
condition: "service_completed_successfully",
308+
},
321309
},
322310
healthcheck: {
323311
test: "test $(curl -s http://127.0.0.1:8080/status/blocks) -gt 0",
@@ -419,13 +407,25 @@ function triggerBuilderService() {
419407
build: {
420408
context: "../trigger",
421409
},
422-
volumes: [`../config/wasm:/app/outputs`],
410+
volumes: [`../config/wasm:/usr/wasm`],
411+
command: `\
412+
sh -c "
413+
cp /app/outputs/* /usr/wasm/ &&
414+
echo 'Copied WASMs'
415+
"`,
423416
};
424417
}
425418

419+
function defaultExecutorBuilderService() {
420+
const cfg = triggerBuilderService();
421+
cfg.build.context = `../executor`;
422+
return cfg;
423+
}
424+
426425
const dockerCompose = {
427426
services: {
428427
[TRIGGER_BUILDER_SERVICE_NAME]: triggerBuilderService(),
428+
[EXECUTOR_BUILDER_SERVICE_NAME]: defaultExecutorBuilderService(),
429429
...peerServices(),
430430
...relayServices(),
431431
// ui: uiService(),
@@ -449,10 +449,6 @@ for (const chain of ALL_CHAINS) {
449449
}
450450
}
451451

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

458454
$.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)