Skip to content

Commit 7dded84

Browse files
committed
Implemented automatic block trigger
1 parent 9eaf510 commit 7dded84

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

packages/sequencer/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export * from "./protocol/production/tasks/StateTransitionTaskParameters";
2828
export * from "./protocol/production/trigger/BlockTrigger";
2929
export * from "./protocol/production/trigger/ManualBlockTrigger";
3030
export * from "./protocol/production/trigger/TimedBlockTrigger";
31+
export * from "./protocol/production/trigger/AutomaticBlockTrigger";
3132
export * from "./protocol/production/BlockProducerModule";
3233
export * from "./protocol/production/BlockTaskFlowService";
3334
export * from "./protocol/production/TransactionTraceService";
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { inject } from "tsyringe";
2+
import { log } from "@proto-kit/common";
3+
4+
import { SequencerModule } from "../../../sequencer/builder/SequencerModule";
5+
import { UnprovenProducerModule } from "../unproven/UnprovenProducerModule";
6+
import { Mempool } from "../../../mempool/Mempool";
7+
8+
import { BlockTrigger } from "./BlockTrigger";
9+
10+
/**
11+
* Only unproven invocation at the moment, because
12+
* this is primarily for development and testing purposes
13+
*/
14+
export class AutomaticBlockTrigger
15+
extends SequencerModule<Record<string, never>>
16+
implements BlockTrigger
17+
{
18+
public constructor(
19+
@inject("UnprovenProducerModule")
20+
private readonly unprovenProducerModule: UnprovenProducerModule,
21+
@inject("Mempool")
22+
private readonly mempool: Mempool
23+
) {
24+
super();
25+
}
26+
27+
public async start(): Promise<void> {
28+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
29+
this.mempool.events.on("transactionAdded", async () => {
30+
log.info("Transaction received, creating block...");
31+
await this.unprovenProducerModule.tryProduceUnprovenBlock();
32+
});
33+
}
34+
}

0 commit comments

Comments
 (0)