Skip to content

Commit

Permalink
improve agent version check
Browse files Browse the repository at this point in the history
  • Loading branch information
defi-dev committed Dec 13, 2023
1 parent 1227aa1 commit 6ef222a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ export class App {
}
let agent;

if (version === '2.3.0' && strategy === 'randao') {
if (version.startsWith('2.') && strategy === 'randao') {
agent = new AgentRandao_2_3_0(checksummedAddress, agentConfig, networkName);
} else if (version === '2.2.0' && strategy === 'light') {
} else if (version.startsWith('2.') && strategy === 'light') {
agent = new AgentLight_2_2_0(checksummedAddress, agentConfig, networkName);
} else {
throw new Error(
Expand Down
5 changes: 2 additions & 3 deletions app/agents/AbstractAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export abstract class AbstractAgent implements IAgent {
// blacklisting by a job key
protected blacklistedJobs: Set<string>;

abstract _getSupportedAgentVersions(): string[];
abstract _isVersionSupported(version): boolean;

protected toString(): string {
return `(network: ${this.networkName}, address: ${this.address}, keeperId: ${this.keeperId || 'Fetching...'})`;
Expand Down Expand Up @@ -184,7 +184,7 @@ export abstract class AbstractAgent implements IAgent {
// Ensure version matches
// TODO: extract check
const version = await this.queryContractVersion();
if (!this._getSupportedAgentVersions().includes(version)) {
if (!this._isVersionSupported(version)) {
throw this.err(`Invalid version: ${version}`);
}

Expand Down Expand Up @@ -401,7 +401,6 @@ export abstract class AbstractAgent implements IAgent {
workerAddress: this.keyAddress,
keeperId: this.keeperId,
keeperConfigNumeric: this.keeperConfig,
supportedAgentVersions: this._getSupportedAgentVersions(),
fullSyncFrom: this.fullSyncFrom,
minKeeperCvpWei: this.minKeeperCvp?.toString(),
minKeeperCvp: weiValueToEth(this.minKeeperCvp),
Expand Down
6 changes: 2 additions & 4 deletions app/agents/Agent.2.2.0.light.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ export class AgentLight_2_2_0 extends AbstractAgent {
// jobKey => keeper
private assignedKeepers: Map<string, number>;

// jobKeys

_getSupportedAgentVersions(): string[] {
return ['2.2.0'];
_isVersionSupported(version): boolean {
return version.startsWith('2.');
}

async _beforeInit() {
Expand Down
4 changes: 2 additions & 2 deletions app/agents/Agent.2.3.0.randao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class AgentRandao_2_3_0 extends AbstractAgent implements IRandaoAgent {

private jobMinCreditsFinney: bigint;

_getSupportedAgentVersions(): string[] {
return ['2.3.0'];
_isVersionSupported(version): boolean {
return version.startsWith('2.');
}

async _beforeInit() {
Expand Down

0 comments on commit 6ef222a

Please sign in to comment.