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
4 changes: 3 additions & 1 deletion packages/sdk/src/query/BlockStorageNetworkStateModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class BlockStorageNetworkStateModule
}

public async getUnprovenNetworkState(): Promise<NetworkState | undefined> {
const latestBlock = await this.unprovenStorage.getLatestBlock();
const latestBlock = await this.unprovenQueue.getLatestBlockAndResult();
return latestBlock?.block.networkState.during;
}

Expand All @@ -47,6 +47,8 @@ export class BlockStorageNetworkStateModule
* with afterBundle() hooks executed
*/
public async getStagedNetworkState(): Promise<NetworkState | undefined> {
// TODO Result could be null here, add method that specifically looks for the
// last block with a result
const result = await this.unprovenStorage.getLatestBlock();
return result?.result.afterNetworkState;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sequencer/src/logging/ConsoleTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type StoreType = Record<string, { duration: number }[]>;
@closeable()
export class ConsoleTracer implements Tracer {
// Hard-code this for the moment. Needs to be configured.
timeInterval: number = 60000;
timeInterval: number = 180000;

store: StoreType = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ export class BlockProducerModule extends SequencerModule<BlockConfig> {

@ensureNotBusy()
public async tryProduceBlock(): Promise<Block | undefined> {
// Check if previous result has been computed, and if not, compute it
await this.blockResultCompleteCheck();

const block = await this.produceBlock();

if (block === undefined) {
Expand Down Expand Up @@ -239,19 +242,23 @@ export class BlockProducerModule extends SequencerModule<BlockConfig> {
return blockResult?.block;
}

public async blockResultCompleteCheck() {
public async blockResultCompleteCheck(): Promise<
"genesis" | "existent" | "generated"
> {
// Check if metadata height is behind block production.
// This can happen when the sequencer crashes after a block has been produced
// but before the metadata generation has finished
const latestBlock = await this.blockQueue.getLatestBlockAndResult();
// eslint-disable-next-line sonarjs/no-collapsible-if
if (latestBlock !== undefined) {
if (latestBlock.result === undefined) {
await this.generateMetadata(latestBlock.block);
return "generated";
}
// Here, the metadata has been computed already
return "existent";
}
// If we reach here, its a genesis startup, no blocks exist yet
return "genesis";
}

public async start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ACTIONS_EMPTY_HASH } from "@proto-kit/protocol";

import { SettlementStorage } from "../../storage/repositories/SettlementStorage";
import { MessageStorage } from "../../storage/repositories/MessageStorage";
import { BlockStorage } from "../../storage/repositories/BlockStorage";
import { BlockQueue } from "../../storage/repositories/BlockStorage";
import { PendingTransaction } from "../../mempool/PendingTransaction";
import type { BridgingModule } from "../BridgingModule";

Expand All @@ -18,8 +18,8 @@ export class IncomingMessagesService {
private readonly messageStorage: MessageStorage,
@inject("IncomingMessageAdapter")
private readonly messagesAdapter: IncomingMessageAdapter,
@inject("BlockStorage")
private readonly blockStorage: BlockStorage,
@inject("BlockQueue")
private readonly blockStorage: BlockQueue,
@inject("BridgingModule")
private readonly bridgingModule: BridgingModule
) {}
Expand Down Expand Up @@ -102,7 +102,7 @@ export class IncomingMessagesService {

public async getPendingMessages() {
const latestSettlement = await this.settlementStorage.getLatestSettlement();
const latestBlock = await this.blockStorage.getLatestBlock();
const latestBlock = await this.blockStorage.getLatestBlockAndResult();

const messagesHashCursor =
latestBlock?.block?.toMessagesHash?.toString() ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe("atomic block production", () => {
* the second block production can succeed
*/
it("should recover from non-generated metadata", async () => {
expect.assertions(6);
expect.assertions(5);

const module =
appchain.sequencer.dependencyContainer.resolve(BlockResultService);
Expand All @@ -102,9 +102,6 @@ describe("atomic block production", () => {

await expect(() => trigger.produceBlock()).rejects.toThrow();

// This checks that it correctly throws when producing a block with no previous result existing
await expect(() => trigger.produceBlock()).rejects.toThrow();

await appchain.sequencer
.resolve("BlockProducerModule")
.blockResultCompleteCheck();
Expand Down
Loading