Skip to content

Commit

Permalink
Implemented automatic block trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
rpanic committed Nov 7, 2023
1 parent 9eaf510 commit 7dded84
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/sequencer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from "./protocol/production/tasks/StateTransitionTaskParameters";
export * from "./protocol/production/trigger/BlockTrigger";
export * from "./protocol/production/trigger/ManualBlockTrigger";
export * from "./protocol/production/trigger/TimedBlockTrigger";
export * from "./protocol/production/trigger/AutomaticBlockTrigger";
export * from "./protocol/production/BlockProducerModule";
export * from "./protocol/production/BlockTaskFlowService";
export * from "./protocol/production/TransactionTraceService";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { inject } from "tsyringe";
import { log } from "@proto-kit/common";

import { SequencerModule } from "../../../sequencer/builder/SequencerModule";
import { UnprovenProducerModule } from "../unproven/UnprovenProducerModule";
import { Mempool } from "../../../mempool/Mempool";

import { BlockTrigger } from "./BlockTrigger";

/**
* Only unproven invocation at the moment, because
* this is primarily for development and testing purposes
*/
export class AutomaticBlockTrigger
extends SequencerModule<Record<string, never>>
implements BlockTrigger
{
public constructor(
@inject("UnprovenProducerModule")
private readonly unprovenProducerModule: UnprovenProducerModule,
@inject("Mempool")
private readonly mempool: Mempool
) {
super();
}

public async start(): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
this.mempool.events.on("transactionAdded", async () => {
log.info("Transaction received, creating block...");
await this.unprovenProducerModule.tryProduceUnprovenBlock();
});
}
}

0 comments on commit 7dded84

Please sign in to comment.