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
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ SERVICE_AUTH_SECRET=S...
# AUTH
CHALLENGE_TTL=900 #15m
SESSION_TTL=21600 #6h

# MEMPOOL CONFIGURATION
MEMPOOL_SLOT_CAPACITY=100
MEMPOOL_EXPENSIVE_OP_WEIGHT=10
MEMPOOL_CHEAP_OP_WEIGHT=1
MEMPOOL_EXECUTOR_INTERVAL_MS=5000
MEMPOOL_VERIFIER_INTERVAL_MS=10000
MEMPOOL_TTL_CHECK_INTERVAL_MS=60000
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"nodeModulesDir": "auto",
"imports": {
"@/": "./src/",
"@colibri/core": "jsr:@colibri/core@^0.6.0",
"@colibri/core": "jsr:@colibri/core@^0.15.0",
"@drizzle-team/brocli": "npm:@drizzle-team/brocli@^0.11.0",
"@fifo/convee": "jsr:@fifo/convee@^0.10.0",
"@moonlight/moonlight-sdk": "jsr:@moonlight/moonlight-sdk@^0.6.0",
"@moonlight/moonlight-sdk": "jsr:@moonlight/moonlight-sdk@^0.6.1",
"@types/pg": "npm:@types/pg@^8.15.6",
"@zaubrik/djwt": "jsr:@zaubrik/djwt@^3.0.2",
"drizzle-kit": "npm:drizzle-kit@^0.31.6",
Expand Down
107 changes: 63 additions & 44 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const NETWORK_FEE = requireBaseFee("NETWORK_FEE");
export const NETWORK_RPC_SERVER = new Server(NETWORK_CONFIG.rpcUrl as string);

export const OPEX_SIGNER = LocalSigner.fromSecret(OPEX_SK);
export const PROVIDER_SIGNER = LocalSigner.fromSecret(PROVIDER_SK);

export const TX_CONFIG: TransactionConfig = {
source: OPEX_PK,
Expand Down
4 changes: 2 additions & 2 deletions src/config/network.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ContractId, type NetworkConfig, TestNet } from "@colibri/core";
import { NetworkConfig, NetworkProviders, type ContractId } from "@colibri/core";
import { StellarNetworkId } from "@moonlight/moonlight-sdk";
import * as E from "@/config/error.ts";
import { logAndThrow } from "@/utils/error/log-and-throw.ts";
Expand All @@ -13,7 +13,7 @@ export function selectNetwork(envNetwork: string): {
switch (envNetwork) {
case "testnet":
return {
NETWORK_CONFIG: TestNet(),
NETWORK_CONFIG: NetworkProviders.Nodies.TestNet(),
NETWORK: StellarNetworkId.Testnet,
CHANNEL_ASSET: {
code: requireEnv("CHANNEL_ASSET_CODE"),
Expand Down
80 changes: 79 additions & 1 deletion src/core/mempool/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import { Mempool } from "@/core/service/mempool/mempool.process.ts";
import { MEMPOOL_SLOT_CAPACITY } from "@/config/env.ts";
import { Executor } from "@/core/service/executor/executor.process.ts";
import { Verifier } from "@/core/service/verifier/verifier.process.ts";
import { MEMPOOL_SLOT_CAPACITY, MEMPOOL_TTL_CHECK_INTERVAL_MS } from "@/config/env.ts";
import { LOG } from "@/config/logger.ts";

/**
* Singleton instance of the Mempool
* Will be initialized during application startup
*/
export let mempool: Mempool;

/**
* Singleton instance of the Executor
* Will be initialized during application startup
*/
export let executor: Executor;

/**
* Singleton instance of the Verifier
* Will be initialized during application startup
*/
export let verifier: Verifier;

/**
* Interval ID for TTL check
*/
let ttlCheckIntervalId: number | null = null;

/**
* Initializes the mempool singleton instance
* Should be called during application startup
Expand All @@ -29,3 +49,61 @@ export function getMempool(): Mempool {
return mempool;
}

/**
* Initializes the complete mempool system
* - Initializes Mempool and loads pending bundles from database
* - Starts Executor service
* - Starts Verifier service
* - Starts periodic TTL check
*/
export async function initializeMempoolSystem(): Promise<void> {
LOG.info("Initializing mempool system...");

// Initialize Mempool
initializeMempool();
await mempool.initialize();

// Initialize Executor
executor = new Executor();
executor.start();

// Initialize Verifier
verifier = new Verifier();
verifier.start();

// Start periodic TTL check
ttlCheckIntervalId = setInterval(async () => {
try {
await mempool.expireBundles();
} catch (error) {
LOG.error("Error during TTL check", {
error: error instanceof Error ? error.message : String(error),
});
}
}, MEMPOOL_TTL_CHECK_INTERVAL_MS) as unknown as number;

LOG.info("Mempool system initialized successfully");
}

/**
* Shuts down the mempool system gracefully
* Stops all services and clears intervals
*/
export function shutdownMempoolSystem(): void {
LOG.info("Shutting down mempool system...");

if (executor) {
executor.stop();
}

if (verifier) {
verifier.stop();
}

if (ttlCheckIntervalId !== null) {
clearInterval(ttlCheckIntervalId);
ttlCheckIntervalId = null;
}

LOG.info("Mempool system shut down successfully");
}
Loading