Skip to content

Commit 1a48dde

Browse files
committed
feat: establish trigger configuration
- Complete `KeyValueAddress` implementation - Compose: generate triggers with their configs - Bump Iroha (hyperledger-iroha/iroha#5497) It works! Triggers are running and successfully reading their configuration. Next steps: - Update the UI. Make it display all entities with all metadata. This must make the architecture more understandable visually. - Update the relay. Make it scan metadata, scan blocks, and submit block messages to the trigger. Signed-off-by: quacumque <[email protected]>
1 parent e700a88 commit 1a48dde

File tree

10 files changed

+446
-130
lines changed

10 files changed

+446
-130
lines changed

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"debug": "npm:debug@^4.4.1",
1717
"true-myth": "npm:true-myth@^9.0.1",
1818
"ts-pattern": "npm:ts-pattern@^5.8.0",
19-
"zod": "npm:zod@^4.0.15",
19+
"zod": "npm:zod@^4.1.11",
2020
}
2121
}

deno.lock

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

executor/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM hyperledger/iroha:experimental-xx-858df795cc8ea480a214ff73f3087a3bbf5f7d85
33
FROM rust:1.89-bullseye
44
WORKDIR /app
55

6-
ARG IROHA_REV=858df795cc8ea480a214ff73f3087a3bbf5f7d85
6+
ARG IROHA_REV=a84bc8893451cf08f346eb476097c13ca7bf65fb
77
RUN git init && \
88
git remote add origin https://github.com/hyperledger-iroha/iroha.git && \
99
git fetch origin $IROHA_REV && \

generator/mod.ts

Lines changed: 140 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@ import * as fs from "@std/fs";
66
import * as path from "@std/path";
77
import * as TOML from "@std/toml";
88
import * as YAML from "@std/yaml";
9-
import { JsonValue } from "npm:type-fest@^4.33.0";
109
import { z } from "zod";
11-
import { RelayConfigSchema, UiConfigSchema } from "../ui/shared.ts";
10+
import {
11+
CheckpointSchema,
12+
KeyValueEntitySchema,
13+
RelayConfigSchema,
14+
TriggerConfigSchema,
15+
UiConfigSchema,
16+
} from "../ui/shared.ts";
1217

1318
const dirname = import.meta.dirname;
1419
assert(dirname);
1520

1621
const CONFIG_DIR = path.relative(Deno.cwd(), path.resolve(dirname, "../config"));
1722

18-
const IROHA_IMAGE = `hyperledger/iroha:experimental-xx-858df795cc8ea480a214ff73f3087a3bbf5f7d85`;
19-
const CHAINS = ["aaa", "bbb", "ccc"].slice(0, 1);
23+
// const IROHA_IMAGE = `hyperledger/iroha:experimental-xx-858df795cc8ea480a214ff73f3087a3bbf5f7d85`;
24+
const IROHA_IMAGE = `hyperledger/iroha:local-uwp`;
25+
const CHAINS = ["aaa", "bbb", "ccc"];
2026
const PEERS_ON_CHAIN = 1;
2127
const ACCOUNTS_ON_CHAIN = 3;
2228
const ASSETS = [
@@ -32,6 +38,17 @@ const CONFIG_MOUNT = "/config";
3238
const EXECUTOR_BUILDER_SERVICE_NAME = "executor-builder";
3339
const TRIGGER_BUILDER_SERVICE_NAME = "trigger-builder";
3440
const TRIGGER_WASM_NAME = "hub_chain_trigger.wasm";
41+
const TRIGGER_PATH_IN_CONFIG = path.join("wasm", TRIGGER_WASM_NAME);
42+
43+
const METADATA_KEYS = {
44+
TRIGGER: {
45+
CONFIG: "config",
46+
CHECKPOINT: "checkpoint",
47+
},
48+
RELAY_ACCOUNT: {
49+
BLOCK_MESSAGE: "block_message",
50+
},
51+
};
3552

3653
const Hub = Symbol("hub-chain");
3754
type ChainId = typeof Hub | string;
@@ -126,6 +143,17 @@ function genesisFor(chain: ChainId) {
126143
let mintAssets: { id: iroha.AssetId; quantity: number | string }[];
127144
let transferPermissions: { account: iroha.AccountId; asset: iroha.AssetDefinitionId }[];
128145

146+
let wasmTriggers: {
147+
id: string;
148+
action: {
149+
executable: string;
150+
repeats: string;
151+
authority: string;
152+
filter: unknown;
153+
};
154+
}[];
155+
let setKeyValueInstructions: ({ key: string; value: unknown } & z.infer<typeof KeyValueEntitySchema>)[];
156+
129157
if (chain !== Hub) {
130158
const accounts = userAccounts.get(chain)!;
131159
const relay = relayAccounts.get(chain)!;
@@ -148,6 +176,54 @@ function genesisFor(chain: ChainId) {
148176
account: acc.id,
149177
}))
150178
);
179+
180+
const TRIGGER_ID = "hub_chain";
181+
182+
wasmTriggers = [
183+
{
184+
id: TRIGGER_ID,
185+
action: {
186+
executable: TRIGGER_PATH_IN_CONFIG,
187+
repeats: "Indefinitely",
188+
authority: admin.id.toString(),
189+
filter: { Time: { PreCommit: null } },
190+
},
191+
},
192+
];
193+
194+
const triggerConfig: z.infer<typeof TriggerConfigSchema> = {
195+
mode: { type: "Domestic", chain },
196+
checkpoint_addr: {
197+
entity: { type: "Trigger", id: TRIGGER_ID },
198+
key: METADATA_KEYS.TRIGGER.CHECKPOINT,
199+
},
200+
block_message_addr: {
201+
entity: { type: "Account", id: relay.id },
202+
key: METADATA_KEYS.RELAY_ACCOUNT.BLOCK_MESSAGE,
203+
},
204+
chains: Object.fromEntries(
205+
[...omnibusAccounts]
206+
.filter(([chainX]) => chainX !== chain)
207+
.map(([chain, acc]) => [chain, { omnibus_account: acc.id }]),
208+
),
209+
};
210+
211+
setKeyValueInstructions = [
212+
{
213+
type: "Trigger",
214+
id: TRIGGER_ID,
215+
key: METADATA_KEYS.TRIGGER.CONFIG,
216+
value: triggerConfig,
217+
},
218+
{
219+
type: "Trigger",
220+
id: TRIGGER_ID,
221+
key: METADATA_KEYS.TRIGGER.CHECKPOINT,
222+
value: CheckpointSchema.encode({
223+
validators: new Set(peerKeys.get(Hub)!.map(x => x.publicKey())),
224+
}),
225+
},
226+
];
151227
} else {
152228
const relays = CHAINS.map(x => relayAccounts.get(x)!);
153229

@@ -166,6 +242,54 @@ function genesisFor(chain: ChainId) {
166242
account: relay.id,
167243
}))
168244
);
245+
246+
const triggerId = (chain: string) => `hub_chain_for_${chain}`;
247+
248+
wasmTriggers = CHAINS.map(chain => ({
249+
id: triggerId(chain),
250+
action: {
251+
executable: TRIGGER_PATH_IN_CONFIG,
252+
repeats: "Indefinitely",
253+
authority: admin.id.toString(),
254+
filter: { Time: { PreCommit: null } },
255+
},
256+
}));
257+
258+
setKeyValueInstructions = CHAINS.flatMap((chain) => {
259+
const triggerConfig: z.infer<typeof TriggerConfigSchema> = {
260+
mode: { type: "Domestic", chain },
261+
checkpoint_addr: {
262+
entity: { type: "Trigger", id: triggerId(chain) },
263+
key: METADATA_KEYS.TRIGGER.CHECKPOINT,
264+
},
265+
block_message_addr: {
266+
entity: { type: "Account", id: relayAccounts.get(chain)!.id },
267+
key: METADATA_KEYS.RELAY_ACCOUNT.BLOCK_MESSAGE,
268+
},
269+
chains: Object.fromEntries(
270+
[...omnibusAccounts]
271+
.filter(([chainX]) => chainX !== chain)
272+
.map(([chain, acc]) => [chain, { omnibus_account: acc.id }]),
273+
),
274+
};
275+
276+
return [
277+
{
278+
type: "Trigger",
279+
id: triggerId(chain),
280+
key: METADATA_KEYS.TRIGGER.CONFIG,
281+
value: triggerConfig,
282+
},
283+
{
284+
type: "Trigger",
285+
id: triggerId(chain),
286+
key: METADATA_KEYS.TRIGGER.CHECKPOINT,
287+
value: CheckpointSchema.encode({
288+
validators: new Set(peerKeys.get(Hub)!.map(x => x.publicKey())),
289+
}),
290+
},
291+
];
292+
});
169293
}
170294

171295
const instructions = [
@@ -220,6 +344,16 @@ function genesisFor(chain: ChainId) {
220344
},
221345
},
222346
})),
347+
348+
...setKeyValueInstructions.map(x => ({
349+
SetKeyValue: {
350+
[x.type]: {
351+
object: x.id,
352+
key: x.key,
353+
value: x.value,
354+
},
355+
},
356+
})),
223357
];
224358

225359
const topology = peerKeys.get(chain)!.map(x => x.publicKey());
@@ -230,28 +364,14 @@ function genesisFor(chain: ChainId) {
230364
executor: "wasm/executor.wasm",
231365
instructions,
232366
wasm_dir: ".",
233-
wasm_triggers: [
234-
{
235-
id: "hub_chain",
236-
action: {
237-
executable: path.join("wasm", TRIGGER_WASM_NAME),
238-
repeats: "Indefinitely",
239-
authority: admin.id.toString(),
240-
filter: { Time: { PreCommit: null } },
241-
},
242-
},
243-
],
367+
wasm_triggers: wasmTriggers,
244368
topology,
245369
parameters: {
246370
sumeragi: {
247371
block_time_ms: 500,
248372
commit_time_ms: 1000,
249373
max_clock_drift_ms: 1000,
250374
},
251-
smart_contract: {
252-
fuel: 200_000_000,
253-
memory: 200_000_000,
254-
},
255375
},
256376
};
257377
}
@@ -312,7 +432,7 @@ function peerComposeService(chain: ChainId, i: number) {
312432
},
313433
healthcheck: {
314434
test: "test $(curl -s http://127.0.0.1:8080/status/blocks) -gt 0",
315-
interval: "1s",
435+
interval: "3s",
316436
timeout: "200ms",
317437
retries: "10",
318438
start_period: "2s",

0 commit comments

Comments
 (0)