Skip to content

Commit

Permalink
fix: new version check requires that patch version has to be at least…
Browse files Browse the repository at this point in the history
… equal or bigger
  • Loading branch information
troykessler committed Aug 10, 2023
1 parent 4683e76 commit 80d5bce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
13 changes: 12 additions & 1 deletion common/protocol/src/methods/checks/isValidVersion.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)) !==
Expand Down
18 changes: 13 additions & 5 deletions common/protocol/src/methods/setups/setupValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "../..";

Expand All @@ -28,12 +28,20 @@ export async function setupValidator(this: Validator): Promise<void> {
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
}`;
Expand Down
2 changes: 1 addition & 1 deletion common/protocol/test/checks/is_valid_version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion integrations/tendermint/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kyvejs/tendermint",
"version": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"scripts": {
"build": "rimraf dist && tsc",
Expand Down

0 comments on commit 80d5bce

Please sign in to comment.