Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9115130
Implement transaction selector
sebastijankuzner May 11, 2026
a17245f
Add selector
sebastijankuzner May 11, 2026
37f2674
Register selector
sebastijankuzner May 11, 2026
9f081f5
Update worker
sebastijankuzner May 11, 2026
f25c206
Clean packages on ts:token
sebastijankuzner May 11, 2026
707ee3b
Update forger
sebastijankuzner May 11, 2026
c3f94fa
Pass transaction data
sebastijankuzner May 11, 2026
3003748
Use block-round identifier
sebastijankuzner May 11, 2026
bcdc9ee
Use iterator
sebastijankuzner May 11, 2026
f4849ca
Inline
sebastijankuzner May 11, 2026
e40f3a2
Use initializer
sebastijankuzner May 11, 2026
55dc5d5
Reduce complexity
sebastijankuzner May 11, 2026
f136237
Improve code
sebastijankuzner May 11, 2026
577b761
Improve code
sebastijankuzner May 11, 2026
dddf459
Handle gasLeft < 0
sebastijankuzner May 11, 2026
29cb226
Gas used as number
sebastijankuzner May 11, 2026
ce58319
Remove identifier
sebastijankuzner May 11, 2026
8ae5da0
Clear selector on commit
sebastijankuzner May 11, 2026
7282261
Merge branch 'develop' into feat/transacation-pool-service/featch-tx-…
sebastijankuzner May 14, 2026
0dccc00
Cleanup worker
sebastijankuzner May 15, 2026
02eb2d8
Fix consensus tests
sebastijankuzner May 15, 2026
20aa1b0
Fix workers
sebastijankuzner May 15, 2026
1b00770
Cleanup worker
sebastijankuzner May 15, 2026
4e2c13b
Fix pool workers
sebastijankuzner May 15, 2026
298b715
style: resolve style guide violations [ci-lint-fix]
sebastijankuzner May 15, 2026
7ad3dbb
Fix validator unit tests
sebastijankuzner May 15, 2026
477f6d4
Fix functional tests
sebastijankuzner May 15, 2026
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build:rs": "lerna run build-rs --scope=@mainsail/evm",
"build:rs:token": "echo \"force-rs $(date +%s)\" > .build-rs",
"build:ts": "lerna run build",
"build:ts:token": "echo \"force-ts $(date +%s)\" > .build-ts",
"build:ts:token": "echo \"force-ts $(date +%s)\" > .build-ts && pnpm run clean:packages",
"clean": "pnpm run clean:packages && rm -r .nx",
"clean:all": "pnpm run clean && pnpm run clean:node_modules",
"clean:node_modules": "rm -rf packages/*/node_modules && rm -rf node_modules",
Expand Down
2 changes: 1 addition & 1 deletion packages/constants/source/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ export const Identifiers = {
},
Forger: {
Block: Symbol("Forger<Block>"),
Transaction: Symbol("Forger<Transaction>"),
},
P2P: {
ApiNode: {
Expand Down Expand Up @@ -301,6 +300,7 @@ export const Identifiers = {
Processor: Symbol("TransactionPool<Processor>"),
ProcessorExtension: Symbol("TransactionPool<ProcessorExtension>"),
Query: Symbol("TransactionPool<Query>"),
Selector: Symbol("TransactionPool<Selector>"),
SenderMempool: {
Factory: Symbol("TransactionPool<SenderMempool.Factory>"),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from "./client.js";
export * from "./mempool.js";
export * from "./processor.js";
export * from "./query.js";
export * from "./selector.js";
export * from "./sender-mempool.js";
export * from "./sender-state.js";
export * from "./service.js";
Expand Down
17 changes: 17 additions & 0 deletions packages/contracts/source/contracts/transaction-pool/selector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { TransactionData } from "../crypto/index.js";

export type GetBatchOptions = {
blockRound: string;
maxSize: number;
maxBytes: number;
};

export type GetBatchResult = {
transactions: TransactionData[];
remaining: number;
};

export interface Selector {
getBatch(options: GetBatchOptions): Promise<GetBatchResult>;
clear(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import type { CommitHandler } from "../crypto/index.js";
import type { EventListener } from "../kernel/index.js";
import type { EventCallback, Subprocess } from "../kernel/ipc.js";
import type { KeyValuePair } from "../types/index.js";
import type { GetBatchResult, GetBatchOptions } from "./selector.js";

export type WorkerFlags = KeyValuePair;

export interface WorkerScriptHandler {
boot(flags: WorkerFlags): Promise<void>;
getTransactions(): Promise<string[]>;
getTransactions(options: GetBatchOptions): Promise<GetBatchResult>;
removeTransaction(address: string, id: string): Promise<void>;
commit(height: number, sendersAddresses: string[], consumedGas: number, isSyncing: boolean): Promise<void>;
setPeer(ip: string): Promise<void>;
Expand All @@ -22,9 +23,8 @@ export type WorkerSubprocess = Subprocess<WorkerScriptHandler>;

export type WorkerSubprocessFactory = () => WorkerSubprocess;

export interface Worker extends Omit<WorkerScriptHandler, "commit" | "getTransactions">, CommitHandler, EventListener {
export interface Worker extends Omit<WorkerScriptHandler, "commit">, CommitHandler, EventListener {
getQueueSize(): number;
kill(): Promise<number>;
getTransactionBytes(): Promise<Buffer[]>;
registerEventHandler<T>(event: string, callback: EventCallback<T>): void;
}
22 changes: 11 additions & 11 deletions packages/forger/source/block-forger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import { Identifiers } from "@mainsail/constants";
import { inject, injectable } from "@mainsail/container";
import { assert } from "@mainsail/utils";

import { TransactionForger } from "./transaction-forger.js";

@injectable()
export class BlockForger implements Contracts.Forger.BlockForger {
@inject(Identifiers.Application.Instance)
private readonly app!: Contracts.Kernel.Application;

@inject(Identifiers.Cryptography.Configuration)
private readonly cryptoConfiguration!: Contracts.Crypto.Configuration;

Expand All @@ -18,9 +23,6 @@ export class BlockForger implements Contracts.Forger.BlockForger {
@inject(Identifiers.Cryptography.Hash.Factory)
private readonly hashFactory!: Contracts.Crypto.HashFactory;

@inject(Identifiers.Forger.Transaction)
protected readonly transactionForger!: Contracts.Forger.TransactionForger;

@inject(Identifiers.BlockchainUtils.FeeCalculator)
protected readonly gasFeeCalculator!: Contracts.BlockchainUtils.FeeCalculator;

Expand All @@ -32,14 +34,12 @@ export class BlockForger implements Contracts.Forger.BlockForger {
const previousBlock = this.stateStore.getLastBlock();
const blockNumber = previousBlock.number + 1;

const { fee, gasUsed, logsBloom, stateRoot, transactions } = await this.transactionForger.getTransactions(
generatorAddress,
timestamp,
{
blockNumber: BigInt(blockNumber),
round: BigInt(round),
},
);
const transactionForger = this.app.resolve(TransactionForger).initialize(generatorAddress, timestamp, {
blockNumber: BigInt(blockNumber),
round: BigInt(round),
});

const { fee, gasUsed, logsBloom, stateRoot, transactions } = await transactionForger.getTransactions();
return this.#makeBlock(round, generatorAddress, logsBloom, stateRoot, transactions, timestamp, gasUsed, fee);
}

Expand Down
2 changes: 0 additions & 2 deletions packages/forger/source/service-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import { Providers } from "@mainsail/kernel";
import Joi from "joi";

import { BlockForger } from "./block-forger.js";
import { TransactionForger } from "./transaction-forger.js";

@injectable()
export class ServiceProvider extends Providers.ServiceProvider {
public async register(): Promise<void> {
this.app.bind(Identifiers.Forger.Transaction).to(TransactionForger).inSingletonScope();
this.app.bind(Identifiers.Forger.Block).to(BlockForger).inSingletonScope();
}

Expand Down
Loading
Loading