From 79b62ae85fc6b716d6c935c17946699d502ebe5d Mon Sep 17 00:00:00 2001 From: Zachary Belford Date: Wed, 21 May 2025 22:41:05 -0600 Subject: [PATCH] Remove deprecated accepted route --- docs/join-protocol-v2/join-protocol-v2.md | 5 +- src/config/server.ts | 1 + src/p2p/Join/routes.ts | 15 ++++- src/p2p/Join/v2/index.ts | 11 ++-- src/p2p/Join/v2/select.ts | 79 ----------------------- src/shardus/shardus-types.ts | 2 + 6 files changed, 22 insertions(+), 91 deletions(-) diff --git a/docs/join-protocol-v2/join-protocol-v2.md b/docs/join-protocol-v2/join-protocol-v2.md index 31ae49223..86b52ad38 100644 --- a/docs/join-protocol-v2/join-protocol-v2.md +++ b/docs/join-protocol-v2/join-protocol-v2.md @@ -62,8 +62,9 @@ The existing join code is in the repository "shardus-global-server", aka "Shardu - On each cycle the active nodes decide how many nodes to add (already implemented). - On each cycle the needed number of nodes N are selected from the standby node list based on a deterministic-but-unpredictable score that is a function of the node public key and the current cycle marker. - The N nodes with the best score are added as joining nodes to the next cycle record. -- When a node is selected to join, some active nodes in the network send the cycle number to the selected node; letting it know that it has been selected. -- The selected standby node queries one of the active nodes for this cycle record and verifies that it is included as a joining node in the cycle record. +- When a node is selected to join it checks the `joined` route to verify + inclusion in the cycle record. The old notification via the `/accepted` + endpoint has been removed. - robustQuery to ask if this node is in the `pendingJoinRequestList` ## Unjoining diff --git a/src/config/server.ts b/src/config/server.ts index e95e4fac7..5baf1f26b 100644 --- a/src/config/server.ts +++ b/src/config/server.ts @@ -120,6 +120,7 @@ const SERVER_CONFIG: StrictServerConfiguration = { validateArchiverAppData: false, useNetworkModes: true, useJoinProtocolV2: true, + enableAcceptedRoute: false, randomJoinRequestWait: 2000, //todo set this to 1000 before release standbyListCyclesTTL: 10, //todo release should be > 1000 standbyListMaxRemoveTTL: 100, //todo set this be 100 for production diff --git a/src/p2p/Join/routes.ts b/src/p2p/Join/routes.ts index cb846b262..392f4a580 100644 --- a/src/p2p/Join/routes.ts +++ b/src/p2p/Join/routes.ts @@ -380,8 +380,9 @@ const joinedRoute: P2P.P2PTypes.Route = { } /** - * todo deprecate this or, finish it - * for now deprecating the accepted path. does not seem to have any value + * Deprecated route used by early join protocol implementations. It is now + * disabled by default and can be enabled for legacy testing via the + * `enableAcceptedRoute` config flag. */ const acceptedRoute: P2P.P2PTypes.Route = { method: 'POST', @@ -784,7 +785,15 @@ const gossipStandbyRefresh: P2P.P2PTypes.GossipHandler< } export const routes = { - external: [cycleMarkerRoute, joinRoute, joinedRoute, joinedV2Route, acceptedRoute, unjoinRoute, standbyRefreshRoute], + external: [ + cycleMarkerRoute, + joinRoute, + joinedRoute, + joinedV2Route, + ...(config?.p2p?.enableAcceptedRoute ? [acceptedRoute] : []), + unjoinRoute, + standbyRefreshRoute, + ], gossip: { 'gossip-join': gossipJoinRoute, 'gossip-valid-join-requests': gossipValidJoinRequests, diff --git a/src/p2p/Join/v2/index.ts b/src/p2p/Join/v2/index.ts index ff11606a8..041ae626f 100644 --- a/src/p2p/Join/v2/index.ts +++ b/src/p2p/Join/v2/index.ts @@ -9,7 +9,7 @@ import { config, crypto, shardus } from '../../Context' import * as CycleChain from '../../CycleChain' import * as Self from '../../Self' import rfdc from 'rfdc' -import { executeNodeSelection, notifyNewestJoinedConsensors } from './select' +import { executeNodeSelection } from './select' import { attempt } from '../../Utils' import { submitUnjoin } from './unjoin' import { ResultAsync } from 'neverthrow' @@ -43,12 +43,9 @@ export function init(): void { // set up event listeners for cycle quarters Self.emitter.on('cycle_q1_start', () => { if (config.p2p.useJoinProtocolV2) { - //TODO clean out the accepted route or is it still useful? - //accepted endpoint does not return any more - // The accepted flow is deprecated - // notifyNewestJoinedConsensors().catch((e) => { - // console.error('failed to notify selected nodes:', e) - // }) + // The old "accepted" route has been removed. Nodes should query + // the joined routes to verify selection instead of waiting for an + // acceptance notification. } }) Self.emitter.on('cycle_q2_start', () => { diff --git a/src/p2p/Join/v2/select.ts b/src/p2p/Join/v2/select.ts index 13885347c..19d796b2e 100644 --- a/src/p2p/Join/v2/select.ts +++ b/src/p2p/Join/v2/select.ts @@ -109,85 +109,6 @@ export function selectNodes(maxAllowed: number): void { } } } -/** - * Notifies the nodes that have been selected that they have been selected by - * calling their `accepted` endpoints.` - */ -export async function notifyNewestJoinedConsensors(): Promise { - return //accepted endpoint seem deprecated and always fails! - - // const counter = CycleChain.getNewest().counter - - // if (!Self.isActive) { - // if (Self.isRestartNetwork && Self.isFirst) { - // nestedCountersInstance.countEvent('joinV2', `C${counter}: notifyNewestJoinedConsensors: isRestartNetwork && isFirst`) - // notifyingNewestJoinedConsensors() - // // // decide if we should be in charge of notifying joining nodes - // // const params = { - // // getOurNodeIndex: CycleChain.getNewest().mode === 'restart' ? 0 : getOurNodeIndex(), - // // activeByIdOrderLength: - // // CycleChain.getNewest().mode === 'restart' ? 1 : NodeList.activeByIdOrder.length, - // // NUM_NOTIFYING_NODES, - // // CycleChainNewestCounter: CycleChain.newest.counter, - // // } - // // console.log(`C${counter} fastIsPicked params: ${JSON.stringify(params)}`) - // // const shouldNotify = fastIsPicked( - // // CycleChain.getNewest().mode === 'restart' ? 1 : getOurNodeIndex(), - // // CycleChain.getNewest().mode === 'restart' ? 0 : NodeList.activeByIdOrder.length, - // // NUM_NOTIFYING_NODES, - // // CycleChain.newest.counter - // // ) - // // console.log(`C${counter} shouldNotify: ${shouldNotify}`) - // } else console.warn(`C${counter} not notifying nodes because we are not active yet`) - // return - // } - - // // decide if we should be in charge of notifying joining nodes - // const params = { - // getOurNodeIndex: getOurNodeIndex(), - // activeByIdOrderLength: NodeList.activeByIdOrder.length, - // NUM_NOTIFYING_NODES, - // CycleChainNewestCounter: CycleChain.newest.counter - // } - // console.log(`C${counter} fastIsPicked params: ${JSON.stringify(params)}`) - // const shouldNotify = fastIsPicked( - // getOurNodeIndex(), - // NodeList.activeByIdOrder.length, - // NUM_NOTIFYING_NODES, - // CycleChain.newest.counter - // ) - - // // if so, do so - // if (shouldNotify) { - // nestedCountersInstance.countEvent('joinV2', `C${counter}: notifyNewestJoinedConsensors: shouldNotify`) - // notifyingNewestJoinedConsensors() - // } -} - -export async function notifyingNewestJoinedConsensors(): Promise { - const marker = CycleChain.getCurrentCycleMarker() - const counter = CycleChain.getNewest().counter - - for (const joinedConsensor of CycleChain.newest.joinedConsensors) { - const publicKey = joinedConsensor.publicKey - - // no need to notify ourselves - if (publicKey === crypto.keypair.publicKey) continue - console.log(`C${counter} notifying node`, publicKey, 'that it has been selected') - - // sign an acceptance offer - const offer = crypto.sign({ - cycleMarker: marker, - activeNodePublicKey: crypto.keypair.publicKey, - }) - - // make the call, but don't await. it might take a while. - http.post(`http://${joinedConsensor.externalIp}:${joinedConsensor.externalPort}/accepted`, offer).catch((e) => { - nestedCountersInstance.countEvent('joinV2', `C${counter}: notifyingNewestJoinedConsensors: http post failed`) - console.error(`C${counter} failed to notify node ${publicKey} that it has been selected:`, e) - }) - } -} /** * Returns the list of public keys of the nodes that have been selected and * empties the list. diff --git a/src/shardus/shardus-types.ts b/src/shardus/shardus-types.ts index 0eaa33daa..eb37a7ad6 100644 --- a/src/shardus/shardus-types.ts +++ b/src/shardus/shardus-types.ts @@ -876,6 +876,8 @@ export interface ServerConfiguration { useNetworkModes: boolean /** Use the new join protocol that gossips all valid join requests to validators. */ useJoinProtocolV2: boolean + /** Enable the deprecated `/accepted` route for legacy tests */ + enableAcceptedRoute: boolean /** Add a random wait before sending the join effect. Should not need this but may be a safet valve if timing in the network gets off * for example the nodes trying to join do not have the same cycle time as the network */