Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/sequencer/src/protocol/production/flow/BatchFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
StateTransitionProverPublicOutput,
TransactionProverPublicInput,
} from "@proto-kit/protocol";
import { isFull, mapSequential, Nullable } from "@proto-kit/common";
import { isFull, mapSequential, Nullable, dependencyFactory, DependencyRecord } from "@proto-kit/common";

import { FlowCreator } from "../../../worker/flow/Flow";
import { NewBlockProvingParameters, NewBlockTask } from "../tasks/NewBlockTask";
Expand All @@ -22,6 +22,7 @@ import { BlockFlow } from "./BlockFlow";

@injectable()
@scoped(Lifecycle.ContainerScoped)
@dependencyFactory()
export class BatchFlow {
public constructor(
private readonly flowCreator: FlowCreator,
Expand All @@ -35,6 +36,17 @@ export class BatchFlow {
public readonly tracer: Tracer
) {}

public static dependencies(): DependencyRecord {
return {
blockProvingTask: {
useClass: NewBlockTask,
},
blockReductionTask: {
useClass: BlockReductionTask,
},
};
}

private isBlockProofsMergable(a: BlockProof, b: BlockProof): boolean {
// TODO Proper replication of merge logic
return a.publicOutput.stateRoot
Expand Down
14 changes: 13 additions & 1 deletion packages/sequencer/src/protocol/production/flow/BlockFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Protocol,
TransactionProof,
} from "@proto-kit/protocol";
import { mapSequential } from "@proto-kit/common";
import { mapSequential, dependencyFactory, DependencyRecord } from "@proto-kit/common";
// eslint-disable-next-line import/no-extraneous-dependencies
import chunk from "lodash/chunk";

Expand All @@ -19,6 +19,7 @@ import { TransactionFlow } from "./TransactionFlow";
// TODO Rename to TransactionFlow
@injectable()
@scoped(Lifecycle.ContainerScoped)
@dependencyFactory()
export class BlockFlow {
public constructor(
private readonly flowCreator: FlowCreator,
Expand All @@ -29,6 +30,17 @@ export class BlockFlow {
private readonly transactionMergeTask: TransactionReductionTask
) {}

public static dependencies(): DependencyRecord {
return {
transactionTask: {
useClass: TransactionProvingTask,
},
transactionMergeTask: {
useClass: TransactionReductionTask,
},
};
}

private dummyProof: TransactionProof | undefined = undefined;

private async dummyTransactionProof() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import {
import { StateTransitionReductionTask } from "../tasks/StateTransitionReductionTask";

import { ReductionTaskFlow } from "./ReductionTaskFlow";
import { dependencyFactory, DependencyRecord } from "@proto-kit/common";

@injectable()
@scoped(Lifecycle.ContainerScoped)
@dependencyFactory()
export class StateTransitionFlow {
public constructor(
@inject("Protocol")
Expand All @@ -27,7 +29,16 @@ export class StateTransitionFlow {
private readonly stateTransitionTask: StateTransitionTask,
private readonly stateTransitionReductionTask: StateTransitionReductionTask
) {}

public static dependencies(): DependencyRecord {
return {
stateTransitionTask: {
useClass: StateTransitionTask,
},
stateTransitionReductionTask: {
useClass: StateTransitionReductionTask,
},
};
}
private async dummySTProof(): Promise<StateTransitionProof> {
const emptyInputOutput: StateTransitionProverPublicInput &
StateTransitionProverPublicOutput = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { injectable } from "tsyringe";
import { assertSizeOneOrTwo } from "@proto-kit/common";
import { assertSizeOneOrTwo, dependencyFactory, DependencyRecord } from "@proto-kit/common";

import { Flow, FlowCreator } from "../../../worker/flow/Flow";
import {
Expand All @@ -10,12 +10,21 @@ import { RuntimeProvingTask } from "../tasks/RuntimeProvingTask";
import { TransactionTrace } from "../tracing/TransactionTracingService";

@injectable()
@dependencyFactory()
export class TransactionFlow {
public constructor(
private readonly flowCreator: FlowCreator,
private readonly runtimeProvingTask: RuntimeProvingTask
) {}

public static dependencies(): DependencyRecord {
return {
runtimeProvingTask: {
useClass: RuntimeProvingTask,
},
};
}

private async resolveTransactionFlow(
flow: Flow<{
runtimeProofs: { proof: RuntimeProof; index: number }[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {
CompileRegistry,
ProvableMethodExecutionContext,
implement,
} from "@proto-kit/common";

import { TaskWorkerModule } from "../../../worker/worker/TaskWorkerModule";
Expand All @@ -21,6 +22,7 @@ import {

@injectable()
@scoped(Lifecycle.ContainerScoped)
@implement("Task")
export class BlockReductionTask
extends TaskWorkerModule
implements Task<PairTuple<BlockProof>, BlockProof>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
CompilableModule,
safeParseJson,
reduceSequential,
implement,
} from "@proto-kit/common";
import {
MandatorySettlementModulesRecord,
Expand Down Expand Up @@ -40,6 +41,7 @@ export type CompilerTaskParams = {

@injectable()
@scoped(Lifecycle.ContainerScoped)
@implement("Task")
export class CircuitCompilerTask extends UnpreparingTask<
CompilerTaskParams,
ArtifactRecord
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { inject, injectable, Lifecycle, scoped } from "tsyringe";
import { implement } from "@proto-kit/common";
import {
BlockProvable,
BlockProverPublicInput,
Expand Down Expand Up @@ -55,6 +56,7 @@ export type NewBlockProvingParameters = PairingDerivedInput<

@injectable()
@scoped(Lifecycle.ContainerScoped)
@implement("Task")
export class NewBlockTask
extends TaskWorkerModule
implements Task<NewBlockProvingParameters, BlockProof>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
RuntimeMethodExecutionContext,
} from "@proto-kit/protocol";
import { Proof } from "o1js";
import { CompileRegistry } from "@proto-kit/common";
import { CompileRegistry, implement } from "@proto-kit/common";

import { Task, TaskSerializer } from "../../../worker/flow/Task";
import { ProofTaskSerializer } from "../../../helpers/utils";
Expand All @@ -31,6 +31,7 @@ export interface RuntimeProofParameters {

@injectable()
@scoped(Lifecycle.ContainerScoped)
@implement("Task")
export class RuntimeProvingTask
extends TaskWorkerModule
implements Task<RuntimeProofParameters, RuntimeProof>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {
CompileRegistry,
ProvableMethodExecutionContext,
implement,
} from "@proto-kit/common";

import { TaskWorkerModule } from "../../../worker/worker/TaskWorkerModule";
Expand All @@ -21,6 +22,7 @@ import {

@injectable()
@scoped(Lifecycle.ContainerScoped)
@implement("Task")
export class StateTransitionReductionTask
extends TaskWorkerModule
implements Task<PairTuple<StateTransitionProof>, StateTransitionProof>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ProvableMethodExecutionContext,
CompileRegistry,
LinkedMerkleTreeWitness,
implement,
} from "@proto-kit/common";

import { Task, TaskSerializer } from "../../../worker/flow/Task";
Expand All @@ -31,6 +32,7 @@ export interface StateTransitionProofParameters {

@injectable()
@scoped(Lifecycle.ContainerScoped)
@implement("Task")
export class StateTransitionTask
extends TaskWorkerModule
implements Task<StateTransitionProofParameters, StateTransitionProof>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { inject, injectable, Lifecycle, scoped } from "tsyringe";
import {
ProvableMethodExecutionContext,
CompileRegistry,
implement,
} from "@proto-kit/common";

import { ProofTaskSerializer } from "../../../helpers/utils";
Expand Down Expand Up @@ -49,6 +50,7 @@ export async function executeWithPrefilledStateService<Return>(

@injectable()
@scoped(Lifecycle.ContainerScoped)
@implement("Task")
export class TransactionProvingTask
extends TaskWorkerModule
implements Task<TransactionProvingTaskParameters, TransactionProof>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {
CompileRegistry,
ProvableMethodExecutionContext,
implement,
} from "@proto-kit/common";

import { TaskWorkerModule } from "../../../worker/worker/TaskWorkerModule";
Expand All @@ -21,6 +22,7 @@ import {

@injectable()
@scoped(Lifecycle.ContainerScoped)
@implement("Task")
export class TransactionReductionTask
extends TaskWorkerModule
implements Task<PairTuple<TransactionProof>, TransactionProof>
Expand Down
15 changes: 15 additions & 0 deletions packages/sequencer/src/sequencer/SequencerStartupModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
ChildVerificationKeyService,
CompileRegistry,
AreProofsEnabled,
dependencyFactory,
DependencyRecord,
} from "@proto-kit/common";

import { Flow, FlowCreator } from "../worker/flow/Flow";
Expand All @@ -23,12 +25,14 @@ import {
import { VerificationKeyService } from "../protocol/runtime/RuntimeVerificationKeyService";
import type { MinaBaseLayer } from "../protocol/baselayer/MinaBaseLayer";
import { NoopBaseLayer } from "../protocol/baselayer/NoopBaseLayer";
import { WorkerRegistrationTask } from "../worker/worker/startup/WorkerRegistrationTask";

import { SequencerModule, sequencerModule } from "./builder/SequencerModule";
import { Closeable, closeable } from "./builder/Closeable";

@sequencerModule()
@closeable()
@dependencyFactory()
export class SequencerStartupModule
extends SequencerModule
implements Closeable
Expand All @@ -50,6 +54,17 @@ export class SequencerStartupModule
super();
}

public static dependencies(): DependencyRecord {
return {
compileTask: {
useClass: CircuitCompilerTask,
},
workerRegistrationTask: {
useClass: WorkerRegistrationTask,
},
};
}

private async pushCompileTask(
flow: Flow<{}>,
payload: CompilerTaskParams
Expand Down
4 changes: 4 additions & 0 deletions packages/sequencer/src/settlement/SettlementModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
AddressRegistry,
InMemoryAddressRegistry,
} from "./interactions/AddressRegistry";
import { SettlementProvingTask } from "./tasks/SettlementProvingTask";

export type SettlementModuleConfig = {
addresses?: {
Expand Down Expand Up @@ -83,6 +84,9 @@ export class SettlementModule
AddressRegistry: {
useClass: InMemoryAddressRegistry,
},
settlementProvingTask: {
useClass: SettlementProvingTask,
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
fetchLastBlock,
} from "o1js";
import { inject, injectable, Lifecycle, scoped } from "tsyringe";
import { implement } from "@proto-kit/common";

import {
ProofTaskSerializer,
Expand Down Expand Up @@ -74,6 +75,7 @@ export class SomeProofSubclass extends Proof<Field, Void> {
*/
@injectable()
@scoped(Lifecycle.ContainerScoped)
@implement("Task")
export class SettlementProvingTask
extends TaskWorkerModule
implements Task<TransactionTaskArgs, TransactionTaskResult>
Expand Down
Loading
Loading