Skip to content

Commit

Permalink
remove blacklist job on execute
Browse files Browse the repository at this point in the history
  • Loading branch information
defi-dev committed Mar 3, 2024
1 parent 9f6dc01 commit c5badb8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
3 changes: 3 additions & 0 deletions app/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export interface Executor {
sendBlockDelayLog(agent: IAgent, delay, blockNumber);
sendNewBlockDelayLog(agent: IAgent, delay, blockNumber);
sendAddBlacklistedJob(agent: IAgent, jobKey, errMessage);
sendRemoveBlacklistedJob(agent: IAgent, jobKey, reason);
}

export interface ClientWrapper {
Expand Down Expand Up @@ -418,6 +419,8 @@ export interface IAgent {

addJobToBlacklist(jobKey, errMessage);

removeJobFromBlacklist(jobKey, reason);

getIsAgentUp(): boolean;

getBaseFeePerGas(): bigint;
Expand Down
6 changes: 6 additions & 0 deletions app/agents/AbstractAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ export abstract class AbstractAgent implements IAgent {
this.executor.sendAddBlacklistedJob(this, jobKey, errMessage);
}

public removeJobFromBlacklist(jobKey, reason) {
this.clog('info', `removeJobFromBlacklist: ${jobKey}, reason ${reason}`);
this.blacklistedJobs.delete(jobKey);
this.executor.sendRemoveBlacklistedJob(this, jobKey, reason);
}

public getJobOwnerBalance(address: string): BigNumber {
if (!this.ownerBalances.has(address)) {
throw this.err(`getJobOwnerBalance(): Address ${address} not tracked`);
Expand Down
32 changes: 24 additions & 8 deletions app/executors/AbstractExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,11 @@ export abstract class AbstractExecutor {
return axios.post(`${txLogEndpoint}/log-block-delay`, { blockData, signature, signatureVersion: 1 });
}

async sendAddBlacklistedJob(agent: IAgent, jobKey, errorMessage) {
const types = {
Mail: [{ name: 'metadataHash', type: 'string' }],
};
async getJobData(agent, jobKey, metaData = {}) {
const networkStatusObj = this.network.getStatusObjectForApi();
const blockData = {
return {
metadataJson: jsonStringify({
jobKey,
errorMessage,
keeperId: agent.keeperId,
rpc: networkStatusObj['rpc'],
rpcClient: await this.network.getClientVersion(),
Expand All @@ -191,12 +187,32 @@ export abstract class AbstractExecutor {
chainId: networkStatusObj['chainId'],
appVersion: this.network.getAppVersion(),
appEnv: process.env.APP_ENV,
...metaData,
}),
};
}

async sendAddBlacklistedJob(agent: IAgent, jobKey, errorMessage) {
const types = {
Mail: [{ name: 'metadataHash', type: 'string' }],
};
const jobData = await this.getJobData(agent, jobKey, { action: 'add', errorMessage });
const signature = await this.workerSigner._signTypedData({}, types, {
metadataHash: hashString(jobData.metadataJson),
});
const txLogEndpoint = process.env.TX_LOG_ENDPOINT || 'https://tx-log.powerpool.finance';
return axios.post(`${txLogEndpoint}/log-blacklist-job`, { jobData, signature, signatureVersion: 2 });
}

async sendRemoveBlacklistedJob(agent: IAgent, jobKey, reason) {
const types = {
Mail: [{ name: 'metadataHash', type: 'string' }],
};
const jobData = await this.getJobData(agent, jobKey, { action: 'remove', reason });
const signature = await this.workerSigner._signTypedData({}, types, {
metadataHash: hashString(blockData.metadataJson),
metadataHash: hashString(jobData.metadataJson),
});
const txLogEndpoint = process.env.TX_LOG_ENDPOINT || 'https://tx-log.powerpool.finance';
return axios.post(`${txLogEndpoint}/log-blacklist-job`, { blockData, signature, signatureVersion: 2 });
return axios.post(`${txLogEndpoint}/log-blacklist-job`, { jobData, signature, signatureVersion: 2 });
}
}
27 changes: 1 addition & 26 deletions app/jobs/AbstractJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
RegisterJobEventArgs,
Resolver,
UnsignedTransaction,
UpdateJobEventArgs,
} from '../Types.js';
import { BigNumber, Event } from 'ethers';
import { encodeExecute, parseConfig, parseRawJob, toNumber, weiValueToEth, weiValueToGwei } from '../Utils.js';
Expand Down Expand Up @@ -117,31 +116,6 @@ export abstract class AbstractJob {
}
}

// APPLIERS (only applies, but doesn't resubscribe).

// TODO: deprecate
public applyUpdateEvent(event: Event): boolean {
this.assertEvent(event, 'JobUpdate');

const args: UpdateJobEventArgs = event.args as never;
this.clog('debug', 'JobUpdateEvent: params, args (TODO: ensure types match):', this.details, args);

let requiresRestart = false;

if (this.details.intervalSeconds !== args.intervalSeconds) {
requiresRestart = true;
}

// TODO: ensure types match
this.details.maxBaseFeeGwei = args.maxBaseFeeGwei;
this.details.rewardPct = args.rewardPct;
this.details.fixedReward = args.fixedReward;
this.details.intervalSeconds = args.intervalSeconds;
this.jobLevelMinKeeperCvp = args.jobMinCvp;

return requiresRestart;
}

//assignFields

public applyJob(job: GetJobResponse): boolean {
Expand Down Expand Up @@ -245,6 +219,7 @@ export abstract class AbstractJob {
public applyWasExecuted() {
this.failedExecuteEstimationsInARow = 0;
this.failedResolverEstimationsInARow = 0;
this.agent.removeJobFromBlacklist(this.key, 'execute');
}

public applyUpdate(
Expand Down

0 comments on commit c5badb8

Please sign in to comment.