Skip to content
Merged
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
9 changes: 2 additions & 7 deletions packages/api/src/graphql/modules/BatchStorageResolver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { inject } from "tsyringe";
import { Arg, Field, ObjectType, Query } from "type-graphql";
import {
Batch,
BatchStorage,
HistoricalBatchStorage,
} from "@proto-kit/sequencer";
import { Batch, BatchStorage } from "@proto-kit/sequencer";
import { MOCK_PROOF } from "@proto-kit/common";

import { graphqlModule, GraphqlModule } from "../GraphqlModule";
Expand Down Expand Up @@ -39,10 +35,9 @@ export class ComputedBlockModel {

@graphqlModule()
export class BatchStorageResolver extends GraphqlModule {
// TODO seperate these two block interfaces
public constructor(
@inject("BatchStorage")
private readonly batchStorage: BatchStorage & HistoricalBatchStorage,
private readonly batchStorage: BatchStorage,
private readonly blockResolver: BlockResolver
) {
super();
Expand Down
8 changes: 2 additions & 6 deletions packages/api/src/graphql/modules/BlockResolver.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { inject } from "tsyringe";
import {
HistoricalBlockStorage,
Block,
BlockStorage,
} from "@proto-kit/sequencer";
import { Block, BlockStorage } from "@proto-kit/sequencer";
import { Arg, Field, ObjectType, Query } from "type-graphql";

import { GraphqlModule, graphqlModule } from "../GraphqlModule";
Expand Down Expand Up @@ -62,7 +58,7 @@ export class BlockModel {
export class BlockResolver extends GraphqlModule<object> {
public constructor(
@inject("BlockStorage")
private readonly blockStorage: HistoricalBlockStorage & BlockStorage
private readonly blockStorage: BlockStorage
) {
super();
}
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/graphql/modules/QueryGraphqlModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import {
QueryTransportModule,
NetworkStateQuery,
BlockStorage,
HistoricalBlockStorage,
NetworkStateTransportModule,
} from "@proto-kit/sequencer";
import {
Expand Down Expand Up @@ -80,7 +79,7 @@ export class QueryGraphqlModule<
MandatoryProtocolModulesRecord & ProtocolModulesRecord
>,
@inject("BlockStorage")
private readonly blockStorage: BlockStorage & HistoricalBlockStorage
private readonly blockStorage: BlockStorage
) {
super();
}
Expand Down
8 changes: 2 additions & 6 deletions packages/persistance/src/services/prisma/PrismaBatchStore.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
Batch,
HistoricalBatchStorage,
BatchStorage,
} from "@proto-kit/sequencer";
import { Batch, BatchStorage } from "@proto-kit/sequencer";
import { Prisma } from "@prisma/client";
import { inject, injectable } from "tsyringe";

Expand All @@ -11,7 +7,7 @@ import type { PrismaConnection } from "../../PrismaDatabaseConnection";
import { BatchMapper } from "./mappers/BatchMapper";

@injectable()
export class PrismaBatchStore implements BatchStorage, HistoricalBatchStorage {
export class PrismaBatchStore implements BatchStorage {
public constructor(
@inject("Database") private readonly connection: PrismaConnection,
private readonly batchMapper: BatchMapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
HistoricalBlockStorage,
TransactionExecutionResult,
Block,
BlockResult,
Expand Down Expand Up @@ -27,9 +26,7 @@ import { BlockResultMapper } from "./mappers/BlockResultMapper";
import { BlockMapper } from "./mappers/BlockMapper";

@injectable()
export class PrismaBlockStorage
implements BlockQueue, BlockStorage, HistoricalBlockStorage
{
export class PrismaBlockStorage implements BlockQueue, BlockStorage {
public constructor(
@inject("Database") private readonly connection: PrismaConnection,
private readonly transactionResultMapper: TransactionExecutionResultMapper,
Expand Down
18 changes: 8 additions & 10 deletions packages/sdk/src/query/BlockStorageNetworkStateModule.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { inject, injectable } from "tsyringe";
import {
BlockStorage,
HistoricalBlockStorage,
HistoricalBatchStorage,
NetworkStateTransportModule,
Sequencer,
SequencerModulesRecord,
Expand All @@ -29,16 +27,16 @@ export class BlockStorageNetworkStateModule
return this.sequencer.dependencyContainer.resolve<BlockQueue>("BlockQueue");
}

private get unprovenStorage(): BlockStorage & HistoricalBlockStorage {
return this.sequencer.dependencyContainer.resolve<
BlockStorage & HistoricalBlockStorage
>("BlockStorage");
private get unprovenStorage(): BlockStorage {
return this.sequencer.dependencyContainer.resolve<BlockStorage>(
"BlockStorage"
);
}

private get provenStorage(): BatchStorage & HistoricalBatchStorage {
return this.sequencer.dependencyContainer.resolve<
BatchStorage & HistoricalBatchStorage
>("BatchStorage");
private get provenStorage(): BatchStorage {
return this.sequencer.dependencyContainer.resolve<BatchStorage>(
"BatchStorage"
);
}

public async getUnprovenNetworkState(): Promise<NetworkState | undefined> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { OutgoingMessageEvent } from "@proto-kit/protocol";
import { filterNonUndefined } from "@proto-kit/common";

import { Block } from "../../../storage/model/Block";
import {
BlockStorage,
HistoricalBlockStorage,
} from "../../../storage/repositories/BlockStorage";
import { BlockStorage } from "../../../storage/repositories/BlockStorage";
import { Batch } from "../../../storage/model/Batch";

/**
Expand All @@ -25,7 +22,7 @@ export interface OutgoingMessageAdapter<T> {
export class OutgoingMessageCollector {
public constructor(
@inject("BlockStorage")
private readonly blockStorage: BlockStorage & HistoricalBlockStorage,
private readonly blockStorage: BlockStorage,
@inject("OutgoingMessageAdapter")
private readonly messageAdapter: OutgoingMessageAdapter<any>
) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { log } from "@proto-kit/common";

import {
BatchStorage,
HistoricalBatchStorage,
} from "../repositories/BatchStorage";
import { BatchStorage } from "../repositories/BatchStorage";
import { Batch } from "../model/Batch";

export class InMemoryBatchStorage
implements BatchStorage, HistoricalBatchStorage
{
export class InMemoryBatchStorage implements BatchStorage {
private readonly batches: Batch[] = [];

public async getCurrentBatchHeight(): Promise<number> {
Expand Down
10 changes: 2 additions & 8 deletions packages/sequencer/src/storage/inmemory/InMemoryBlockStorage.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { inject, injectable } from "tsyringe";

import {
HistoricalBlockStorage,
BlockQueue,
BlockStorage,
} from "../repositories/BlockStorage";
import { BlockQueue, BlockStorage } from "../repositories/BlockStorage";
import type {
Block,
BlockResult,
Expand All @@ -14,9 +10,7 @@ import type {
import { BatchStorage } from "../repositories/BatchStorage";

@injectable()
export class InMemoryBlockStorage
implements BlockStorage, HistoricalBlockStorage, BlockQueue
{
export class InMemoryBlockStorage implements BlockStorage, BlockQueue {
public constructor(
@inject("BatchStorage") private readonly batchStorage: BatchStorage
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { Field } from "o1js";

import { TransactionStorage } from "../repositories/TransactionStorage";
import { PendingTransaction } from "../../mempool/PendingTransaction";
import {
HistoricalBlockStorage,
BlockStorage,
} from "../repositories/BlockStorage";
import { BlockStorage } from "../repositories/BlockStorage";

import { InMemoryBatchStorage } from "./InMemoryBatchStorage";

Expand All @@ -18,7 +15,7 @@ export class InMemoryTransactionStorage implements TransactionStorage {

public constructor(
@inject("BlockStorage")
private readonly blockStorage: BlockStorage & HistoricalBlockStorage,
private readonly blockStorage: BlockStorage,
@inject("BatchStorage") private readonly batchStorage: InMemoryBatchStorage
) {}

Expand Down
4 changes: 0 additions & 4 deletions packages/sequencer/src/storage/repositories/BatchStorage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { Batch } from "../model/Batch";

export interface BatchStorage {
// TODO Rename to getCurrentChainLength(), blockheight seems misleading here
getCurrentBatchHeight: () => Promise<number>;
getLatestBatch: () => Promise<Batch | undefined>;
pushBatch: (block: Batch) => Promise<void>;
}

export interface HistoricalBatchStorage {
getBatchAt: (height: number) => Promise<Batch | undefined>;
}
3 changes: 1 addition & 2 deletions packages/sequencer/src/storage/repositories/BlockStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ export interface BlockQueue {
}

export interface BlockStorage {
// TODO Rename to getCurrentChainLength(), blockheight seems misleading here
getCurrentBlockHeight: () => Promise<number>;
getLatestBlock: () => Promise<BlockWithResult | undefined>;
pushBlock: (block: Block) => Promise<void>;
}

export interface HistoricalBlockStorage {
getBlockAt: (height: number) => Promise<Block | undefined>;
getBlock: (hash: string) => Promise<Block | undefined>;
}
4 changes: 1 addition & 3 deletions packages/sequencer/test/integration/BlockProduction-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { afterEach } from "@jest/globals";

import {
BatchStorage,
HistoricalBatchStorage,
Sequencer,
SequencerModule,
VanillaTaskWorkerModules,
Expand Down Expand Up @@ -251,8 +250,7 @@ export function testBlockProduction<
).toStrictEqual(batch!.toNetworkState.hash().toString());

// Check if the batchstorage has received the block
const batchStorage = sequencer.resolve("BatchStorage") as BatchStorage &
HistoricalBatchStorage;
const batchStorage = sequencer.resolve("BatchStorage") as BatchStorage;
const retrievedBatch = await batchStorage.getBatchAt(0);
expect(retrievedBatch).toBeDefined();

Expand Down
10 changes: 2 additions & 8 deletions packages/sequencer/test/integration/StorageIntegration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { TypedClass, expectDefined } from "@proto-kit/common";
import {
AsyncStateService,
BatchStorage,
HistoricalBatchStorage,
HistoricalBlockStorage,
InMemoryDatabase,
Sequencer,
SequencerModule,
Expand Down Expand Up @@ -158,9 +156,7 @@ describe.each([["InMemory", InMemoryDatabase]])(
generatedBlock.hash.toBigInt()
);

const blockStorage = sequencer.resolve(
"BlockStorage"
) as HistoricalBlockStorage & BlockStorage;
const blockStorage = sequencer.resolve("BlockStorage") as BlockStorage;
const block2 = await blockStorage.getBlockAt(
Number(blocks[0].block.height.toString())
);
Expand Down Expand Up @@ -196,9 +192,7 @@ describe.each([["InMemory", InMemoryDatabase]])(
const blocks = await sequencer.resolve("BlockQueue").getNewBlocks();
expect(blocks).toHaveLength(0);

const batchStorage = sequencer.resolve(
"BatchStorage"
) as HistoricalBatchStorage & BatchStorage;
const batchStorage = sequencer.resolve("BatchStorage") as BatchStorage;
const batch = await batchStorage.getBatchAt(0);

expectDefined(batch);
Expand Down