Skip to content
Open
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
16 changes: 13 additions & 3 deletions packages/common/src/config/ModuleContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,18 @@ export type ResolvableModules<Modules extends ModulesRecord> = MergeObjects<
> &
Modules;

export interface ParentContainer {
get dependencyContainer(): DependencyContainer;
}

/**
* Reusable module container facilitating registration, resolution
* configuration, decoration and validation of modules
*/
export class ModuleContainer<
Modules extends ModulesRecord,
> extends ConfigurableModule<ModulesConfig<Modules>> {
export class ModuleContainer<Modules extends ModulesRecord>
extends ConfigurableModule<ModulesConfig<Modules>>
implements ParentContainer
{
/**
* Determines how often are modules decorated upon resolution
* from the tsyringe DI container
Expand Down Expand Up @@ -483,5 +488,10 @@ export class ModuleContainer<

// register all provided modules when the container is created
this.registerModules(this.definition.modules);
this.container.register("ParentContainer", { useValue: this });
}

public get dependencyContainer(): DependencyContainer {
return this.container;
}
}
5 changes: 2 additions & 3 deletions packages/sdk/src/query/BlockStorageNetworkStateModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import {
HistoricalBlockStorage,
HistoricalBatchStorage,
NetworkStateTransportModule,
Sequencer,
SequencerModulesRecord,
BlockQueue,
BatchStorage,
} from "@proto-kit/sequencer";
import { NetworkState } from "@proto-kit/protocol";
import { ParentContainer } from "@proto-kit/common";

import { AppChainModule } from "../appChain/AppChainModule";

Expand All @@ -20,7 +19,7 @@ export class BlockStorageNetworkStateModule
{
public constructor(
@inject("Sequencer")
private readonly sequencer: Sequencer<SequencerModulesRecord>
private readonly sequencer: ParentContainer
) {
super();
}
Expand Down
12 changes: 6 additions & 6 deletions packages/sdk/src/query/StateServiceQueryModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import {
AsyncStateService,
CachedMerkleTreeStore,
QueryTransportModule,
Sequencer,
SequencerModulesRecord,
AsyncMerkleTreeStore,
} from "@proto-kit/sequencer";
import { Field } from "o1js";
import { inject, injectable } from "tsyringe";
import { RollupMerkleTree, RollupMerkleTreeWitness } from "@proto-kit/common";
import {
ParentContainer,
RollupMerkleTree,
RollupMerkleTreeWitness,
} from "@proto-kit/common";

import { AppChainModule } from "../appChain/AppChainModule";

Expand All @@ -17,9 +19,7 @@ export class StateServiceQueryModule
extends AppChainModule
implements QueryTransportModule
{
public constructor(
@inject("Sequencer") public sequencer: Sequencer<SequencerModulesRecord>
) {
public constructor(@inject("Sequencer") public sequencer: ParentContainer) {
super();
}

Expand Down
12 changes: 4 additions & 8 deletions packages/sequencer/src/mempool/private/PrivateMempool.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter, log, noop } from "@proto-kit/common";
import { EventEmitter, log, noop, ParentContainer } from "@proto-kit/common";
import { container, inject } from "tsyringe";
import {
AccountStateHook,
Expand All @@ -22,10 +22,6 @@ import {
import { TransactionStorage } from "../../storage/repositories/TransactionStorage";
import { TransactionValidator } from "../verification/TransactionValidator";
import { BlockStorage } from "../../storage/repositories/BlockStorage";
import {
Sequencer,
SequencerModulesRecord,
} from "../../sequencer/executor/Sequencer";
import { CachedStateService } from "../../state/state/CachedStateService";
import { AsyncStateService } from "../../state/async/AsyncStateService";
import { distinctByPredicate } from "../../helpers/utils";
Expand All @@ -52,8 +48,8 @@ export class PrivateMempool
private readonly transactionStorage: TransactionStorage,
@inject("Protocol")
private readonly protocol: Protocol<MandatoryProtocolModulesRecord>,
@inject("Sequencer")
private readonly sequencer: Sequencer<SequencerModulesRecord>,
@inject("ParentContainer")
private readonly parentContainer: ParentContainer,
@inject("UnprovenStateService")
private readonly stateService: AsyncStateService
) {
Expand Down Expand Up @@ -91,7 +87,7 @@ export class PrivateMempool
}

private get unprovenQueue(): BlockStorage {
return this.sequencer.dependencyContainer.resolve<BlockStorage>(
return this.parentContainer.dependencyContainer.resolve<BlockStorage>(
"BlockStorage"
);
}
Expand Down
16 changes: 8 additions & 8 deletions packages/sequencer/src/protocol/baselayer/MinaBaseLayer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { AreProofsEnabled, DependencyFactory } from "@proto-kit/common";
import {
AreProofsEnabled,
DependencyFactory,
ParentContainer,
} from "@proto-kit/common";
import { Mina } from "o1js";
import { match } from "ts-pattern";
import { inject } from "tsyringe";
Expand All @@ -10,10 +14,6 @@ import {
} from "../../sequencer/builder/SequencerModule";
import { MinaTransactionSender } from "../../settlement/transactions/MinaTransactionSender";
import { WithdrawalQueue } from "../../settlement/messages/WithdrawalQueue";
import {
Sequencer,
SequencerModulesRecord,
} from "../../sequencer/executor/Sequencer";

import { BaseLayer } from "./BaseLayer";
import { LocalBlockchainUtils } from "./network-utils/LocalBlockchainUtils";
Expand Down Expand Up @@ -56,8 +56,8 @@ export class MinaBaseLayer
public constructor(
@inject("AreProofsEnabled")
private readonly areProofsEnabled: AreProofsEnabled,
@inject("Sequencer")
private readonly sequencer: Sequencer<SequencerModulesRecord>
@inject("ParentContainer")
private readonly parentContainer: ParentContainer
) {
super();
}
Expand Down Expand Up @@ -92,7 +92,7 @@ export class MinaBaseLayer
if (this.config.network.type === "remote") {
throw new Error("NetworkUtils not available for remote networks");
}
return this.sequencer.dependencyContainer.resolve("NetworkUtils");
return this.parentContainer.dependencyContainer.resolve("NetworkUtils");
}

public isLocalBlockChain(): boolean {
Expand Down
6 changes: 1 addition & 5 deletions packages/sequencer/src/sequencer/executor/Sequencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Protocol,
ProtocolModulesRecord,
} from "@proto-kit/protocol";
import { DependencyContainer, injectable } from "tsyringe";
import { injectable } from "tsyringe";

import { SequencerModule } from "../builder/SequencerModule";
import { Closeable } from "../builder/Closeable";
Expand Down Expand Up @@ -58,10 +58,6 @@ export class Sequencer<Modules extends SequencerModulesRecord>
>("Protocol");
}

public get dependencyContainer(): DependencyContainer {
return this.container;
}

/**
* Starts the sequencer by iterating over all provided
* modules to start each
Expand Down