diff --git a/packages/api-transaction-pool/source/identifiers.ts b/packages/api-transaction-pool/source/identifiers.ts deleted file mode 100644 index 71022d993..000000000 --- a/packages/api-transaction-pool/source/identifiers.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const Identifiers = { - HTTP: Symbol.for("API"), - HTTPS: Symbol.for("API"), -}; diff --git a/packages/api-transaction-pool/source/index.ts b/packages/api-transaction-pool/source/index.ts index 575fd43b9..8db374446 100644 --- a/packages/api-transaction-pool/source/index.ts +++ b/packages/api-transaction-pool/source/index.ts @@ -1,3 +1,2 @@ -export * from "./identifiers.js"; export * from "./server.js"; export * from "./service-provider.js"; diff --git a/packages/api-transaction-pool/source/service-provider.ts b/packages/api-transaction-pool/source/service-provider.ts index 47c953446..0115a482d 100644 --- a/packages/api-transaction-pool/source/service-provider.ts +++ b/packages/api-transaction-pool/source/service-provider.ts @@ -1,16 +1,16 @@ import { AbstractServiceProvider, Plugins, ServerConstructor } from "@mainsail/api-common"; +import { Identifiers } from "@mainsail/contracts"; import Handlers from "./handlers.js"; -import { Identifiers as ApiTransactionPoolIdentifiers } from "./identifiers.js"; import { Server } from "./server.js"; export class ServiceProvider extends AbstractServiceProvider { protected httpIdentifier(): symbol { - return ApiTransactionPoolIdentifiers.HTTP; + return Identifiers.TransactionPool.API.HTTP; } protected httpsIdentifier(): symbol { - return ApiTransactionPoolIdentifiers.HTTPS; + return Identifiers.TransactionPool.API.HTTPS; } protected getServerConstructor(): ServerConstructor { @@ -21,6 +21,8 @@ export class ServiceProvider extends AbstractServiceProvider { return Handlers; } + public async boot(): Promise {} + protected getPlugins(): any[] { const config = this.config().get("plugins"); diff --git a/packages/bootstrap/source/bootstrapper.ts b/packages/bootstrap/source/bootstrapper.ts index d7018d0b2..79538cb4d 100644 --- a/packages/bootstrap/source/bootstrapper.ts +++ b/packages/bootstrap/source/bootstrapper.ts @@ -70,7 +70,7 @@ export class Bootstrapper { this.state.setBootstrap(false); this.validatorRepository.printLoadedValidators(); - await this.txPoolWorker.start(); + await this.txPoolWorker.start(this.stateStore.getHeight()); void this.runConsensus(); diff --git a/packages/contracts/source/contracts/api/api.ts b/packages/contracts/source/contracts/api/api.ts index 01dbd4ce3..a0be88a4e 100644 --- a/packages/contracts/source/contracts/api/api.ts +++ b/packages/contracts/source/contracts/api/api.ts @@ -5,6 +5,11 @@ import { Processor } from "./rpc.js"; export type ApiServer = Hapi.Server; +export interface Server { + boot(): Promise; + dispose(): Promise; +} + export enum ServerType { Http = "HTTP", Https = "HTTPS", diff --git a/packages/contracts/source/contracts/transaction-pool/worker.ts b/packages/contracts/source/contracts/transaction-pool/worker.ts index 28d4619e8..4dd8b17a2 100644 --- a/packages/contracts/source/contracts/transaction-pool/worker.ts +++ b/packages/contracts/source/contracts/transaction-pool/worker.ts @@ -11,7 +11,7 @@ export interface WorkerScriptHandler { commit(height: number, sendersAddresses: string[]): Promise; setPeer(ip: string): Promise; forgetPeer(ip: string): Promise; - start(): Promise; + start(height: number): Promise; reloadWebhooks(): Promise; } diff --git a/packages/contracts/source/identifiers.ts b/packages/contracts/source/identifiers.ts index 68d86aac8..90aa85cdf 100644 --- a/packages/contracts/source/identifiers.ts +++ b/packages/contracts/source/identifiers.ts @@ -253,6 +253,10 @@ export const Identifiers = { }, }, TransactionPool: { + API: { + HTTP: Symbol.for("API"), + HTTPS: Symbol.for("API"), + }, Broadcaster: Symbol("TransactionPoolBroadcaster"), ExpirationService: Symbol("TransactionPool"), Mempool: Symbol("TransactionPool"), diff --git a/packages/transaction-pool-worker/source/handlers/start.ts b/packages/transaction-pool-worker/source/handlers/start.ts index 7fa1b1f5b..84fd9234e 100644 --- a/packages/transaction-pool-worker/source/handlers/start.ts +++ b/packages/transaction-pool-worker/source/handlers/start.ts @@ -1,12 +1,32 @@ -import { inject, injectable } from "@mainsail/container"; +import { inject, injectable, tagged } from "@mainsail/container"; import { Contracts, Identifiers } from "@mainsail/contracts"; +import { Providers } from "@mainsail/kernel"; @injectable() export class StartHandler { + @inject(Identifiers.Application.Instance) + protected readonly app!: Contracts.Kernel.Application; + + @inject(Identifiers.State.Store) + protected readonly store!: Contracts.State.Store; + @inject(Identifiers.TransactionPool.Service) private readonly transactionPoolService!: Contracts.TransactionPool.Service; - public async handle(): Promise { + @inject(Identifiers.ServiceProvider.Configuration) + @tagged("plugin", "api-transaction-pool") + private readonly configuration!: Providers.PluginConfiguration; + + public async handle(height: number): Promise { + this.store.setHeight(height); await this.transactionPoolService.reAddTransactions(); + + if (this.configuration.get("server.http.enabled")) { + await this.app.get(Identifiers.TransactionPool.API.HTTP).boot(); + } + + if (this.configuration.get("server.https.enabled")) { + await this.app.get(Identifiers.TransactionPool.API.HTTPS).boot(); + } } } diff --git a/packages/transaction-pool-worker/source/worker-handler.ts b/packages/transaction-pool-worker/source/worker-handler.ts index 59ae3aadc..e345da53f 100644 --- a/packages/transaction-pool-worker/source/worker-handler.ts +++ b/packages/transaction-pool-worker/source/worker-handler.ts @@ -27,8 +27,8 @@ export class WorkerScriptHandler implements Contracts.TransactionPool.WorkerScri this.#app = app; } - public async start(): Promise { - await this.#app.resolve(StartHandler).handle(); + public async start(height: number): Promise { + await this.#app.resolve(StartHandler).handle(height); } public async commit(height: number, sendersAddresses: string[]): Promise { diff --git a/packages/transaction-pool-worker/source/worker.ts b/packages/transaction-pool-worker/source/worker.ts index 139cf0ff9..1a0761c34 100644 --- a/packages/transaction-pool-worker/source/worker.ts +++ b/packages/transaction-pool-worker/source/worker.ts @@ -60,8 +60,8 @@ export class Worker implements Contracts.TransactionPool.Worker { await this.ipcSubprocess.sendRequest("commit", unit.height, [...sendersAddresses.keys()]); } - public async start(): Promise { - await this.ipcSubprocess.sendRequest("start"); + public async start(height: number): Promise { + await this.ipcSubprocess.sendRequest("start", height); } public async getTransactionBytes(): Promise {