Skip to content

Commit c157add

Browse files
committed
Merge branch 'develop' into feature/proven-settlemnet
# Conflicts: # packages/sequencer/src/protocol/production/BlockTaskFlowService.ts # packages/sequencer/src/protocol/production/tasks/StateTransitionTask.ts
2 parents 3ffc0c7 + d9cc60a commit c157add

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

packages/common/src/config/ModuleContainer.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,6 @@ export class ModuleContainer<
454454
);
455455
}
456456

457-
protected createSuperClassAliases(module: any) {}
458-
459457
/**
460458
* This is a placeholder for individual modules to override.
461459
* This method will be called whenever the underlying container fully

packages/common/src/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ export function requireTrue(
1919
}
2020
}
2121

22+
/**
23+
* Utility function to split an array of type T into a record <K, T[]> based on a
24+
* function T => K that determines the key of each record
25+
*/
2226
export function splitArray<T, K extends string | number>(
2327
arr: T[],
2428
split: (t: T) => K

packages/sequencer/src/protocol/production/BlockTaskFlowService.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Protocol,
1010
StateTransitionProof,
1111
} from "@proto-kit/protocol";
12-
import { log, MAX_FIELD, MOCK_PROOF } from "@proto-kit/common";
12+
import { log, MAX_FIELD } from "@proto-kit/common";
1313

1414
import { TaskQueue } from "../../worker/queue/TaskQueue";
1515
import { Flow, FlowCreator } from "../../worker/flow/Flow";
@@ -215,11 +215,7 @@ export class BlockTaskFlowService {
215215
this.flowCreator
216216
);
217217
blockMergingFlow.onCompletion(async (result) => {
218-
const printableProof =
219-
result.proof === MOCK_PROOF
220-
? result.proof
221-
: result.toJSON().proof.slice(100);
222-
log.debug(`Block generation finished, with proof ${printableProof}`); // TODO Remove result logging
218+
log.debug(`Block generation finished, with proof ${result.proof}`); // TODO Remove result logging
223219
flow.resolve(result);
224220
});
225221
blockMergingFlow.deferErrorsTo(flow);

packages/sequencer/src/sequencer/executor/Sequencer.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ export class Sequencer<Modules extends SequencerModulesRecord>
6666
* modules to start each
6767
*/
6868
public async start() {
69+
// The sequencer uses tsyringe to resolve modules (and their dependencies)
70+
// and then starts them. However, this can be problematic as although tsyringe may resolve
71+
// dependencies, it doesn't actually start them. For example, a database may be created,
72+
// but the connection strings, etc, won't be constructed until it's started, and this may
73+
// cause an error if a module that relies on it is started first. The way to fix this is
74+
// ensure that we start modules based on the order they were resolved.
75+
// We iterate through the methods three times:
76+
6977
this.useDependencyFactory(this.container.resolve(MethodIdFactory));
7078

7179
// Log startup info
@@ -75,15 +83,41 @@ export class Sequencer<Modules extends SequencerModulesRecord>
7583
log.info("Starting sequencer...");
7684
log.info("Modules:", moduleClassNames);
7785

86+
// Iteration #1: We invoke the afterResolution feature for the container
87+
// to ensure every time a module is resolved it gets recorded.
88+
const orderedModules: Extract<keyof Modules, string>[] = [];
89+
// eslint-disable-next-line guard-for-in
90+
for (const moduleName in this.definition.modules) {
91+
this.container.afterResolution(
92+
moduleName,
93+
() => {
94+
orderedModules.push(moduleName);
95+
},
96+
{
97+
frequency: "Once",
98+
}
99+
);
100+
}
101+
// Iteration #2: We resolve each module and thus populate
102+
// the orderedModules list to understand the sequencing.
78103
// eslint-disable-next-line guard-for-in
79104
for (const moduleName in this.definition.modules) {
80105
const sequencerModule = this.resolve(moduleName);
81-
82106
log.info(
83-
`Starting sequencer module ${moduleName} (${sequencerModule.constructor.name})`
107+
`Resolving sequencer module ${moduleName} (${sequencerModule.constructor.name})`
84108
);
109+
}
110+
111+
// Iteration #3: We now iterate though the orderedModules list
112+
// and start the modules in the order they were resolved.
113+
for (const moduleName of orderedModules) {
114+
const sequencerModule = this.resolve(moduleName);
85115
// eslint-disable-next-line no-await-in-loop
86116
await sequencerModule.start();
117+
118+
log.info(
119+
`Starting sequencer module ${moduleName} (${sequencerModule.constructor.name})`
120+
);
87121
}
88122
}
89123
}

packages/sequencer/test/settlement/MinaActionsHashList.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "reflect-metadata";
12
import {
23
ACTIONS_EMPTY_HASH,
34
MinaActions,

packages/stack/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@proto-kit/stack",
33
"version": "0.1.1-develop.833+397881ed",
44
"license": "MIT",
5-
"private": false,
5+
"private": true,
66
"type": "module",
77
"scripts": {
88
"build": "tsc -p tsconfig.json",

0 commit comments

Comments
 (0)