Skip to content

Commit

Permalink
add max_new_block_delay and logs
Browse files Browse the repository at this point in the history
  • Loading branch information
defi-dev committed Oct 30, 2023
1 parent fa05f20 commit b119d88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
18 changes: 12 additions & 6 deletions app/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class Network {
setConfigDefaultValues(networkConfig, getDefaultNetworkConfig());
this.rpc = networkConfig.rpc;
this.maxBlockDelay = networkConfig.max_block_delay;
this.maxNewBlockDelay = networkConfig.max_block_delay;
this.maxNewBlockDelay = networkConfig.max_new_block_delay;
this.networkConfig = networkConfig;
this.agents = agents;

Expand Down Expand Up @@ -300,7 +300,8 @@ export class Network {
setTimeout(() => {
this._onNewBlockCallback(blockNumber);
}, 1000);
return this.clog('error', `⚠️ Block not found (number=${blockNumber},nowMs=${this.nowMs()})`);
this.clog('error', `⚠️ Block not found (number=${blockNumber},nowMs=${this.nowMs()})`);
return null;
}
const fetchBlockDelay = this.nowMs() - before;
if (process.env.NODE_ENV !== 'test') {
Expand All @@ -311,7 +312,7 @@ export class Network {
}

if (this.latestBlockNumber && blockNumber <= this.latestBlockNumber) {
return;
return null;
}
this.latestBlockNumber = blockNumber;
this.latestBaseFee = BigInt(block.baseFeePerGas.toString());
Expand All @@ -331,7 +332,7 @@ export class Network {
this.walkThroughTheJobs(blockNumber, block.timestamp);
}

setTimeout(() => {
setTimeout(async () => {
if (this.latestBlockNumber > blockNumber) {
return;
}
Expand All @@ -342,16 +343,21 @@ export class Network {
})`,
);
this.newBlockEventEmitter.emit('newBlockDelay', blockNumber);
this._onNewBlockCallback(++blockNumber);
let block;
do {
block = await this._onNewBlockCallback(++blockNumber);
} while (block);
}, this.maxNewBlockDelay * 1000);

return block;
}

public isBlockDelayAboveMax() {
return this.currentBlockDelay && this.currentBlockDelay > this.maxBlockDelay;
}

public blockDelay() {
return this.currentBlockDelay - this.maxBlockDelay;
return this.currentBlockDelay;
}

public getMaxNewBlockDelay() {
Expand Down
1 change: 1 addition & 0 deletions app/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface NetworkConfig {
rpc: string;
ws_timeout?: number;
max_block_delay?: number;
max_new_block_delay?: number;
resolve_min_success_count?: number;
flashbots?: {
rpc: string;
Expand Down
2 changes: 1 addition & 1 deletion app/agents/AbstractAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export abstract class AbstractAgent implements IAgent {
'info',
`Terminate agent, minKeeperCvp: ${ethers.utils.formatEther(
this.minKeeperCvp,
)}, myStake: ${ethers.utils.formatEther(this.myStake)}`,
)}, myStake: ${ethers.utils.formatEther(this.myStake)}, delay: ${this.network.blockDelay()}`,
);
this.isAgentUp = false;
this.stopAllJobs();
Expand Down

0 comments on commit b119d88

Please sign in to comment.