Skip to content
Merged
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
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,16 @@ async function preMainLoop() {
getSharedState.lastBlockHash = lastBlock.hash
}

// ANCHOR Entry point
/**
* Bootstraps the node and starts its network services and background managers.
*
* Performs chain setup, warmup, time calibration, and pre-main-loop initialization; then ensures peer availability, starts the signaling server, optionally starts the MCP server, and initializes the DTR relay retry service when running in production.
*
* Side effects:
* - May call process.exit(1) if the signaling server fails to start.
* - Sets shared-state flags such as `isSignalingServerStarted` and `isMCPServerStarted`.
* - Starts background services (MCP server and DTRManager) when configured.
*/
async function main() {
await Chain.setup()
// INFO Warming up the node (including arguments digesting)
Expand Down Expand Up @@ -403,4 +412,4 @@ process.on("SIGTERM", () => {
})

// INFO Starting the main routine
main()
main()
8 changes: 7 additions & 1 deletion src/libs/consensus/v2/routines/getShard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import { getSharedState } from "src/utilities/sharedState"
import log from "src/utilities/logger"
import Chain from "src/libs/blockchain/chain"

/**
* Retrieve the current list of online peers.
*
* @param seed - Seed intended for deterministic shard selection; currently not used and has no effect
* @returns An array of peers that are currently considered online
*/
export default async function getShard(seed: string): Promise<Peer[]> {
// ! we need to get the peers from the last 3 blocks too
const allPeers = await PeerManager.getInstance().getOnlinePeers()
Expand Down Expand Up @@ -55,4 +61,4 @@ export default async function getShard(seed: string): Promise<Peer[]> {
true,
)
return shard
}
}
9 changes: 8 additions & 1 deletion src/libs/consensus/v2/routines/isValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import { Peer } from "@/libs/peer"
import { getSharedState } from "@/utilities/sharedState"
import getCommonValidatorSeed from "./getCommonValidatorSeed"

/**
* Determines whether the local node is included in the validator shard for the next block.
*
* @returns An object containing:
* - `isValidator`: `true` if the local node's public key is present among the shard validators, `false` otherwise.
* - `validators`: the array of `Peer` objects representing the validators for the computed shard.
*/
export default async function isValidatorForNextBlock(): Promise<{
isValidator: boolean
validators: Peer[]
Expand All @@ -16,4 +23,4 @@ export default async function isValidatorForNextBlock(): Promise<{
),
validators,
}
}
}
9 changes: 7 additions & 2 deletions src/libs/network/manageNodeCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ export interface NodeCall {
muid: string
}

// REVIEW Is this module too big?
/**
* Dispatches an incoming NodeCall message to the appropriate handler and produces an RPCResponse.
*
* @param content - NodeCall containing `message` (the RPC action to perform), `data` (payload for the action), and `muid` (message unique id)
* @returns An RPCResponse containing the numeric status, the response payload for the requested action, and optional `extra` diagnostic data
*/
export async function manageNodeCall(content: NodeCall): Promise<RPCResponse> {
// Basic Node API handling logic
// ...
Expand Down Expand Up @@ -486,4 +491,4 @@ export async function manageNodeCall(content: NodeCall): Promise<RPCResponse> {

// REVIEW Is this ok? Follow back and see
return response
}
}