From 80d5bce093f05abeffe2c63dc6f2ce666ac93a7f Mon Sep 17 00:00:00 2001 From: Troy Kessler Date: Thu, 10 Aug 2023 15:54:04 +0200 Subject: [PATCH] fix: new version check requires that patch version has to be at least equal or bigger --- .../src/methods/checks/isValidVersion.ts | 13 ++++++++++++- .../src/methods/setups/setupValidator.ts | 18 +++++++++++++----- .../test/checks/is_valid_version.test.ts | 2 +- integrations/tendermint/package.json | 2 +- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/common/protocol/src/methods/checks/isValidVersion.ts b/common/protocol/src/methods/checks/isValidVersion.ts index b0f95db5..c2223351 100644 --- a/common/protocol/src/methods/checks/isValidVersion.ts +++ b/common/protocol/src/methods/checks/isValidVersion.ts @@ -1,5 +1,5 @@ import { Validator, standardizeJSON } from "../.."; -import { valid, major, minor, prerelease } from "semver"; +import { valid, major, minor, patch, prerelease } from "semver"; /** * isValidVersion checks if the major and minor version of the pool matches @@ -61,6 +61,17 @@ export function isValidVersion(this: Validator): boolean { return false; } + // exit if local patch version is behind remote + if (patch(remoteVersion) > patch(localVersion)) { + this.logger.fatal(`Running an invalid version. Exiting ...`); + this.logger.fatal( + `Found Runtime version = ${this.runtime.version} required = ${ + this.pool.data!.protocol!.version + }` + ); + return false; + } + // exit if prerelease version does not match if ( JSON.stringify(prerelease(remoteVersion)) !== diff --git a/common/protocol/src/methods/setups/setupValidator.ts b/common/protocol/src/methods/setups/setupValidator.ts index 433da881..d7317c80 100644 --- a/common/protocol/src/methods/setups/setupValidator.ts +++ b/common/protocol/src/methods/setups/setupValidator.ts @@ -5,7 +5,7 @@ import { colors, uniqueNamesGenerator, } from "unique-names-generator"; -import { major, minor, prerelease } from "semver"; +import { major, minor, patch, prerelease } from "semver"; import { Validator, standardizeError } from "../.."; @@ -28,12 +28,20 @@ export async function setupValidator(this: Validator): Promise { this.logger.info(`${this.runtime.name} = v${this.runtime.version}`); this.logger.info(`@kyvejs/protocol = v${this.protocolVersion}\n`); - // generate deterministic valname based on chainId, pool id, - // runtime, runtime version and valaddress + // A Valname is likea human readable hash based on chainId, pool id, + // runtime, runtime version and valaddress. + + // for the version we take the major, minor and prerelease version, + // because if one of those changes the valname should not match anymore, + // with the patch version it is different, here the remote version dictates + // the min patch version, the valname should only differ, if the local patch + // version is smaller, therefore we take the min out of remote and local + // patch version const valnameSeed = `${this.chainId}-${this.poolId}-${ this.runtime.name - }-${major(this.runtime.version)}-${minor( - this.runtime.version + }-${major(this.runtime.version)}-${minor(this.runtime.version)}-${Math.min( + patch(this.runtime.version), + patch(this.pool.data!.protocol!.version) )}-${JSON.stringify(prerelease(this.runtime.version))}-${ this.client[0].account.address }`; diff --git a/common/protocol/test/checks/is_valid_version.test.ts b/common/protocol/test/checks/is_valid_version.test.ts index 893ca4ca..fbc11a8c 100644 --- a/common/protocol/test/checks/is_valid_version.test.ts +++ b/common/protocol/test/checks/is_valid_version.test.ts @@ -114,7 +114,7 @@ describe("isValidVersion", () => { const result = isValidVersion.call(v); // ASSERT - expect(result).toBeTruthy(); + expect(result).toBeFalsy(); }); test("assert remote and local with higher minor version", async () => { diff --git a/integrations/tendermint/package.json b/integrations/tendermint/package.json index 9c958c20..a7cdd672 100644 --- a/integrations/tendermint/package.json +++ b/integrations/tendermint/package.json @@ -1,6 +1,6 @@ { "name": "@kyvejs/tendermint", - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "scripts": { "build": "rimraf dist && tsc",