From 24aca3268b7930065c1edd48bc217fc8f1ad6c53 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Fri, 5 Dec 2025 12:35:30 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`dtr`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @tcsenpai. * https://github.com/kynesyslabs/node/pull/517#issuecomment-3616750620 The following files were modified: * `src/index.ts` * `src/libs/consensus/v2/routines/getShard.ts` * `src/libs/consensus/v2/routines/isValidator.ts` * `src/libs/network/manageNodeCall.ts` --- src/index.ts | 13 +++++++++++-- src/libs/consensus/v2/routines/getShard.ts | 8 +++++++- src/libs/consensus/v2/routines/isValidator.ts | 9 ++++++++- src/libs/network/manageNodeCall.ts | 9 +++++++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index a9ffc23f6..cf67365cc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) @@ -403,4 +412,4 @@ process.on("SIGTERM", () => { }) // INFO Starting the main routine -main() +main() \ No newline at end of file diff --git a/src/libs/consensus/v2/routines/getShard.ts b/src/libs/consensus/v2/routines/getShard.ts index 29013545c..c4ed88851 100644 --- a/src/libs/consensus/v2/routines/getShard.ts +++ b/src/libs/consensus/v2/routines/getShard.ts @@ -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 { // ! we need to get the peers from the last 3 blocks too const allPeers = await PeerManager.getInstance().getOnlinePeers() @@ -55,4 +61,4 @@ export default async function getShard(seed: string): Promise { true, ) return shard -} +} \ No newline at end of file diff --git a/src/libs/consensus/v2/routines/isValidator.ts b/src/libs/consensus/v2/routines/isValidator.ts index 0e1e85bb9..5cfeb2b41 100644 --- a/src/libs/consensus/v2/routines/isValidator.ts +++ b/src/libs/consensus/v2/routines/isValidator.ts @@ -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[] @@ -16,4 +23,4 @@ export default async function isValidatorForNextBlock(): Promise<{ ), validators, } -} +} \ No newline at end of file diff --git a/src/libs/network/manageNodeCall.ts b/src/libs/network/manageNodeCall.ts index 96540510b..5e82937a1 100644 --- a/src/libs/network/manageNodeCall.ts +++ b/src/libs/network/manageNodeCall.ts @@ -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 { // Basic Node API handling logic // ... @@ -486,4 +491,4 @@ export async function manageNodeCall(content: NodeCall): Promise { // REVIEW Is this ok? Follow back and see return response -} +} \ No newline at end of file