Skip to content

Commit

Permalink
Handle ExecutionReverted event
Browse files Browse the repository at this point in the history
  • Loading branch information
polipaul committed Jul 14, 2023
1 parent 31faef0 commit 22d7d9c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
7 changes: 6 additions & 1 deletion app/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,12 @@ export class Network {
public registerTimeout(key: string, triggerCallbackAfter: number, callback: (blockTimestamp: number) => void) {
this._validateKeyLength(key, 'interval');
this._validateKeyNotInMap(key, this.timeoutData, 'interval');
this.clog('SET Timeout', key, `at: ${triggerCallbackAfter}`, `now: ${nowS()}`);
this.clog(
'SET Timeout',
key,
`at: ${triggerCallbackAfter}`,
`now: ${nowS()}, in: ${triggerCallbackAfter - nowS()}`,
);
this.timeoutData[key] = {
triggerCallbackAfter,
callback,
Expand Down
2 changes: 1 addition & 1 deletion app/agents/AbstractAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export abstract class AbstractAgent implements IAgent {
private keeperConfig: number;

protected jobs: Map<string, LightJob | RandaoJob>;
private ownerBalances: Map<string, BigNumber>;
protected ownerBalances: Map<string, BigNumber>;
private ownerJobs: Map<string, Set<string>>;
private keyAddress: string;
private keyPass: string;
Expand Down
24 changes: 24 additions & 0 deletions app/agents/Agent.2.3.0.randao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ export class AgentRandao_2_3_0 extends AbstractAgent implements IRandaoAgent {
}

_afterInitializeListeners() {
this.contract.on('ExecutionReverted', event => {
const { actualKeeperId, compensation, executionReturndata, jobKey } = event.args;

this.clog(
`'ExecutionReverted' event 🔈: (block=${event.blockNumber},jobKey=${jobKey},actualKeeperId=${actualKeeperId},compensation=${compensation},executionReturndata=${executionReturndata})`,
);

const job = this.jobs.get(jobKey);
job.applyWasExecuted();

if (job.creditsSourceIsJobOwner()) {
const ownerCreditsBefore = this.ownerBalances.get(job.getOwner());
const ownerCreditsAfter = ownerCreditsBefore.sub(compensation);
this.clog(
`Owner balance credited: (jobOwner=${job.getOwner()},amount=${compensation.toString()},before=${ownerCreditsBefore},after=${ownerCreditsAfter}`,
);
this.ownerBalances.set(job.getOwner(), ownerCreditsAfter);
} else {
job.applyJobCreditsCredit(compensation);
}

// The keeper was unassigned earlier with JobKeeperChanged event, thus no need to call watch() here
});

this.contract.on(['JobKeeperChanged'], async event => {
const { keeperFrom, keeperTo, jobKey } = event.args;

Expand Down
6 changes: 5 additions & 1 deletion app/jobs/AbstractJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ export abstract class AbstractJob {
this.details.credits = this.details.credits.sub(credits);
}

public applyJobCreditsCredit(credits: BigNumber) {
this.details.credits = this.details.credits.sub(credits);
}

public applyResolver(resolverAddress: string, resolverCalldata: string) {
this.resolver = { resolverAddress, resolverCalldata };
}
Expand Down Expand Up @@ -422,7 +426,7 @@ export abstract class AbstractJob {
});
}

private nextExecutionTimestamp(): number {
protected nextExecutionTimestamp(): number {
if (this.details.intervalSeconds === 0) {
throw this.err(`Unexpected nextExecutionTimestamp() callback for job ${this.key}`);
}
Expand Down
12 changes: 11 additions & 1 deletion app/jobs/RandaoJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,23 @@ export class RandaoJob extends AbstractJob {
this._unlockInitiateSlashing();
}

protected nextExecutionTimestamp(): number {
if (this.details.intervalSeconds === 0) {
throw this.err(`Unexpected nextExecutionTimestamp() callback for job ${this.key}`);
}

return (this.details.lastExecutionAt || this.createdAt) + this.details.intervalSeconds;
}

private intervalPeriod2StartsAt(): number {
if (this.details.intervalSeconds === 0) {
throw this.err(`Unexpected slashingAvailableTimestamp() callback for job ${this.key}`);
}

return (
this.details.lastExecutionAt + this.details.intervalSeconds + (this.agent as IRandaoAgent).getPeriod1Duration()
(this.details.lastExecutionAt || this.createdAt) +
this.details.intervalSeconds +
(this.agent as IRandaoAgent).getPeriod1Duration()
);
}

Expand Down

0 comments on commit 22d7d9c

Please sign in to comment.