diff --git a/app/Cli.ts b/app/Cli.ts index bb21d30..c440ef1 100644 --- a/app/Cli.ts +++ b/app/Cli.ts @@ -92,7 +92,7 @@ let app: App; resolve_min_success_count: process.env.NETWORK_MIN_SUCCESS_RESOLVE ? parseInt(process.env.NETWORK_MIN_SUCCESS_RESOLVE) : undefined, - block_logs_mode: process.env.NETWORK_BLOCK_LOG_MODE === 'true' || process.env.NETWORK_BLOCK_LOG_MODE === '1', + block_logs_mode: process.env.NETWORK_BLOCK_LOGS_MODE === 'true' || process.env.NETWORK_BLOCK_LOGS_MODE === '1', agents: { [agentAddress]: agentConfig, }, diff --git a/app/ConfigGetters.ts b/app/ConfigGetters.ts index 8269705..dcf00c8 100644 --- a/app/ConfigGetters.ts +++ b/app/ConfigGetters.ts @@ -73,17 +73,12 @@ export function getDefaultExecutorConfig() { gas_price_priority_add_gwei: 2, }; } -//TODO: use AVERAGE_BLOCK_TIME_SECONDS -const maxNewBlockDelayByNetwork = { - gnosis: 10, - sepolia: 20, - mainnet: 20, -}; export function getDefaultNetworkConfig(name) { + const avgBlockTime = AVERAGE_BLOCK_TIME_SECONDS[name]; return { max_block_delay: 60, - max_new_block_delay: maxNewBlockDelayByNetwork[name] || 10, + max_new_block_delay: avgBlockTime ? avgBlockTime * 3 : 10, resolve_min_success_count: 3, block_logs_mode: false, }; diff --git a/app/agents/AbstractAgent.ts b/app/agents/AbstractAgent.ts index c68ee6b..71ebca5 100644 --- a/app/agents/AbstractAgent.ts +++ b/app/agents/AbstractAgent.ts @@ -230,6 +230,9 @@ export abstract class AbstractAgent implements IAgent { const keeperConfig = await this.queryKeeperDetails(this.keeperId); this.myStake = keeperConfig.currentStake; this.myKeeperIsActive = keeperConfig.isActive; + if (!this.myKeeperIsActive) { + this.clog('warn', `Your keeper(${this.keeperId}) is not active in agent contract(${this.contract.address})`); + } if (toChecksummedAddress(this.workerSigner.address) !== toChecksummedAddress(keeperConfig.worker)) { throw this.err( diff --git a/app/services/ContractEventsEmitter.ts b/app/services/ContractEventsEmitter.ts index b4aaf14..9b058ff 100644 --- a/app/services/ContractEventsEmitter.ts +++ b/app/services/ContractEventsEmitter.ts @@ -9,6 +9,9 @@ export default class ContractEventsEmitter { contractByAddress = {}; eventByContractTopic = {}; + contractEmitterCount = {}; + emitByBlockCount = {}; + constructor(_blockLogsMode) { this.blockLogsMode = _blockLogsMode; } @@ -25,18 +28,31 @@ export default class ContractEventsEmitter { if (!this.blockLogsMode && !forceEmit) { return; } - console.log('emitByBlockLogs logs.length', logs.length); + let address, blockNumber; logs.forEach(l => { - const address = l.address.toLowerCase(); + address = l.address.toLowerCase(); if (!this.contractEmitterByAddress[address]) { return; } + if (!this.emitByBlockCount[address]) { + this.emitByBlockCount[address] = {}; + } const eventName = this.eventByContractTopic[address][l.topics[0]]; if (!eventName) { return; } + blockNumber = l.blockNumber; + this.emitByBlockCount[address][blockNumber] = (this.emitByBlockCount[address][blockNumber] || 0) + 1; this.emitByContractAddress(address, eventName, this.contractByAddress[address].parseLog(l)); }); + if (blockNumber && address) { + console.log( + blockNumber + ' block logs count(query:', + this.emitByBlockCount[address][blockNumber], + 'websocket:', + this.contractEmitterCount[address][blockNumber] + ')', + ); + } } on(contract: ContractWrapper, eventName, callback) { @@ -51,6 +67,9 @@ export default class ContractEventsEmitter { if (!this.eventByContractTopic[address][eventTopic]) { this.eventByContractTopic[address][eventTopic] = eventName; contract.on(eventName, value => { + const { blockNumber } = value; + this.contractEmitterCount[address][blockNumber] = (this.contractEmitterCount[address][blockNumber] || 0) + 1; + delete this.contractEmitterCount[address][blockNumber - 1]; if (this.blockLogsMode) { return; } @@ -61,6 +80,10 @@ export default class ContractEventsEmitter { } contractEmitter(contract): EventEmitter { + const address = contract.address.toLowerCase(); + if (!this.contractEmitterCount[address]) { + this.contractEmitterCount[address] = {}; + } return { on: (eventName, callback) => { this.on(contract, eventName, callback);