Skip to content

Commit

Permalink
log blacklisted jobs to explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
defi-dev committed Nov 3, 2023
1 parent 1c19ee6 commit 16b744f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
3 changes: 2 additions & 1 deletion app/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export interface Executor {
push(key: string, tx: TxEnvelope);
sendBlockDelayLog(agent: IAgent, delay, blockNumber);
sendNewBlockDelayLog(agent: IAgent, delay, blockNumber);
sendAddBlacklistedJob(agent: IAgent, jobKey, errMessage);
}

export interface ClientWrapper {
Expand Down Expand Up @@ -400,7 +401,7 @@ export interface IAgent {

exitIfStrictTopic(topic): void;

addJobToBlacklist(jobKey);
addJobToBlacklist(jobKey, errMessage);

getIsAgentUp(): boolean;

Expand Down
5 changes: 3 additions & 2 deletions app/agents/AbstractAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,10 @@ export abstract class AbstractAgent implements IAgent {
this.network.exitIfStrictTopic(topic);
}

public addJobToBlacklist(jobKey) {
this.clog('info', `addJobToBlacklist: ${jobKey}`);
public addJobToBlacklist(jobKey, errMessage) {
this.clog('info', `addJobToBlacklist: ${jobKey}, errMessage ${errMessage}`);
this.blacklistedJobs.add(jobKey);
this.executor.sendAddBlacklistedJob(this, jobKey, errMessage);
}

public getJobOwnerBalance(address: string): BigNumber {
Expand Down
32 changes: 28 additions & 4 deletions app/executors/AbstractExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,22 @@ export abstract class AbstractExecutor {
}
this.lastDelaySentAtMs = this.network.nowMs();

return this.logBlockDelay(agent, delay, blockNumber);
return this.logBlockDelay(agent, delay, blockNumber, false);
}

async sendNewBlockDelayLog(agent: IAgent, delay, blockNumber) {
return this.logBlockDelay(agent, delay, blockNumber);
return this.logBlockDelay(agent, delay, blockNumber, true);
}

async logBlockDelay(agent: IAgent, delay, blockNumber) {
async logBlockDelay(agent: IAgent, delay, blockNumber, isNotEmitted) {
const types = {
Mail: [{ name: 'metadataJson', type: 'string' }],
};
const networkStatusObj = this.network.getStatusObjectForApi();
const blockData = {
metadataJson: JSON.stringify({
delay,
isNotEmitted: true,
isNotEmitted,
keeperId: agent.keeperId,
rpc: networkStatusObj['rpc'],
rpcClient: await this.network.getClientVersion(),
Expand All @@ -172,4 +172,28 @@ export abstract class AbstractExecutor {
const txLogEndpoint = process.env.TX_LOG_ENDPOINT || 'https://tx-log.powerpool.finance';
return axios.post(`${txLogEndpoint}/log-block-delay`, { blockData, signature, signatureVersion: 1 });
}

async sendAddBlacklistedJob(agent: IAgent, jobKey, errorMessage) {
const types = {
Mail: [{ name: 'metadataJson', type: 'string' }],
};
const networkStatusObj = this.network.getStatusObjectForApi();
const blockData = {
metadataJson: JSON.stringify({
jobKey,
errorMessage,
keeperId: agent.keeperId,
rpc: networkStatusObj['rpc'],
rpcClient: await this.network.getClientVersion(),
blockNumber: networkStatusObj.latestBlockNumber,

Check failure on line 188 in app/executors/AbstractExecutor.ts

View workflow job for this annotation

GitHub Actions / build

Property 'latestBlockNumber' does not exist on type 'object'.

Check failure on line 188 in app/executors/AbstractExecutor.ts

View workflow job for this annotation

GitHub Actions / build

Property 'latestBlockNumber' does not exist on type 'object'.
agent: agent.address.toLowerCase(),
chainId: networkStatusObj['chainId'],
appVersion: this.network.getAppVersion(),
appEnv: process.env.APP_ENV,
}),
};
const signature = await this.workerSigner._signTypedData({}, types, blockData);
const txLogEndpoint = process.env.TX_LOG_ENDPOINT || 'https://tx-log.powerpool.finance';
return axios.post(`${txLogEndpoint}/log-blacklist-job`, { blockData, signature, signatureVersion: 1 });
}
}
7 changes: 6 additions & 1 deletion app/executors/FlashbotsExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ export class FlashbotsExecutor extends AbstractExecutor implements Executor {
let txSimulation;
try {
txSimulation = await this.genericProvider.call(prepareTx(tx));
printSolidityCustomError(this.clog.bind(this), this.agentContract.decodeError.bind(this.agentContract), txSimulation, tx.data as string);
printSolidityCustomError(
this.clog.bind(this),
this.agentContract.decodeError.bind(this.agentContract),
txSimulation,
tx.data as string,
);
} catch (e) {
this.clog('error', 'TX node simulation error', e);
}
Expand Down
12 changes: 9 additions & 3 deletions app/executors/PGAExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ export class PGAExecutor extends AbstractExecutor implements Executor {
envelope.executorCallbacks.txEstimationFailed(e, tx.data as string);
return callback(this.err(`gasLimitEstimation failed with error: ${e.message}`));
}
printSolidityCustomError(this.clog.bind(this), this.agentContract.decodeError.bind(this.agentContract), txSimulation, tx.data as string);
printSolidityCustomError(
this.clog.bind(this),
this.agentContract.decodeError.bind(this.agentContract),
txSimulation,
tx.data as string,
);

envelope.executorCallbacks.txEstimationFailed(e, tx.data as string);

Expand Down Expand Up @@ -190,25 +195,26 @@ export class PGAExecutor extends AbstractExecutor implements Executor {
confirmedAtBlockDateTime: new Date(parseInt(this.network.getLatestBlockTimestamp().toString()) * 1000),
};
}
const chainId = networkStatusObj['chainId'];
const txData = {
transactionJson: JSON.stringify(prepareTx(transaction)),
metadataJson: JSON.stringify({
appEnv: process.env.APP_ENV,
appVersion: this.network.getAppVersion(),
baseFeeGwei: weiValueToGwei(networkStatusObj['baseFee']),
maxPriorityFeeGwei: weiValueToGwei(BigInt(await this.network.getMaxPriorityFeePerGas().catch(() => 0))),
chainId: networkStatusObj['chainId'],
keeperId: agent ? agent.keeperId : null,
rpc: networkStatusObj['rpc'],
rpcClient: await this.network.getClientVersion(),
resendCount,
chainId,
txHash,
prevTxHash,
...timeData,
}),
};
const signature = await this.workerSigner._signTypedData({}, types, txData);
const txLogEndpoint = process.env.TX_LOG_ENDPOINT || 'https://tx-log.powerpool.finance';
const txLogEndpoint = process.env.TX_LOG_ENDPOINT || 'https://tx-log.powerpool.finance'; // TODO: add ${chainId}.
return axios.post(`${txLogEndpoint}/log-transaction`, { txData, signature, signatureVersion: 1 });
}
}
4 changes: 2 additions & 2 deletions app/jobs/RandaoJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class RandaoJob extends AbstractJob {

if (this.failedInitiateSlashingEstimationsInARow > this.BLACKLIST_ESTIMATIONS_LIMIT) {
this.applyClearResolverTimeouts();
this.agent.addJobToBlacklist(this.key);
this.agent.addJobToBlacklist(this.key, err.message);
this.failedInitiateSlashingEstimationsInARow = 0;
} else {
this._unlockInitiateSlashing();
Expand Down Expand Up @@ -311,7 +311,7 @@ export class RandaoJob extends AbstractJob {
// Assume that a failed execution behaviour is equal to a failed estimation
this.failedExecuteEstimationsInARow += 1;
if (this.failedExecuteEstimationsInARow > this.BLACKLIST_ESTIMATIONS_LIMIT) {
this.agent.addJobToBlacklist(this.key);
this.agent.addJobToBlacklist(this.key, err.message);
this.failedExecuteEstimationsInARow = 0;
}
}
Expand Down

0 comments on commit 16b744f

Please sign in to comment.