From e1259ab445e4a6f3fad9f8874a2044044408a0ae Mon Sep 17 00:00:00 2001 From: Tanuj Soni Date: Tue, 13 Aug 2024 16:27:36 +0530 Subject: [PATCH] Add shardeum version check for seed node in restore network --- src/API.ts | 21 +++++++++++++++++++-- src/GlobalAccount.ts | 2 +- src/NodeList.ts | 28 ++++++++++++++++++++++++++++ src/P2P.ts | 8 ++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/API.ts b/src/API.ts index 5335754c..810a532c 100644 --- a/src/API.ts +++ b/src/API.ts @@ -60,7 +60,17 @@ export function registerRoutes(server: FastifyInstance server.get('/myip', function (request, reply) { @@ -69,9 +79,10 @@ export function registerRoutes(server: FastifyInstance { + console.log(':>> nodeList request', request.body) profilerInstance.profileSectionStart('POST_nodelist') nestedCountersInstance.countEvent('consensor', 'POST_nodelist', 1) - const signedFirstNodeInfo = request.body + const signedFirstNodeInfo = request.body.nodeInfo if (State.isFirst && NodeList.isEmpty() && !NodeList.foundFirstNode) { try { @@ -102,6 +113,12 @@ export function registerRoutes(server: FastifyInstance() const appliedConfigChanges = new Set() -export function getGlobalNetworkAccount(hash: boolean): object | string { +export function getGlobalNetworkAccount(hash: boolean): AccountDB.AccountCopy | string { if (hash) { return cachedGlobalNetworkAccountHash } diff --git a/src/NodeList.ts b/src/NodeList.ts index d64719ba..70b88f4c 100644 --- a/src/NodeList.ts +++ b/src/NodeList.ts @@ -416,3 +416,31 @@ export function toggleFirstNode(): void { foundFirstNode = !foundFirstNode Logger.mainLogger.debug('foundFirstNode', foundFirstNode) } + +export function isEqualOrNewerVersion(minimumVersion: string, testVersion: string): boolean { + if (minimumVersion === testVersion) { + return true + } + + const minVerParts = minimumVersion.split('.') + const testVerParts = testVersion.split('.') + /* eslint-disable security/detect-object-injection */ + for (let i = 0; i < testVerParts.length; i++) { + const testV = ~~testVerParts[i] // parse int + const minV = ~~minVerParts[i] // parse int + if (testV > minV) return true + if (testV < minV) return false + } + /* eslint-enable security/detect-object-injection */ + return false +} + +export function isEqualOrOlderVersion(maximumVersion: string, testVersion: string): boolean { + return isEqualOrNewerVersion(testVersion, maximumVersion) +} + +export function isValidVersion(minimumVersion: string, latestVersion: string, testVersion: string): boolean { + const equalOrNewer = isEqualOrNewerVersion(minimumVersion, testVersion) + const equalOrOlder = isEqualOrOlderVersion(latestVersion, testVersion) + return equalOrNewer && equalOrOlder +} diff --git a/src/P2P.ts b/src/P2P.ts index cdfb5e04..08c6e807 100644 --- a/src/P2P.ts +++ b/src/P2P.ts @@ -38,6 +38,14 @@ export interface FirstNodeInfo { externalPort: number publicKey: string } + appJoinData: { + shardeumVersion: string + minVersion: string + activeVersion: string + latestVersion: string + operatorCLIVersion: string + operatorGUIVersion: string + } } export interface FirstNodeResponse { nodeList: NodeList.ConsensusNodeInfo[]