diff --git a/.env.example b/.env.example index b8a3dda..86967e8 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,5 @@ NET_ID=1 HTTP_RPC_URL=https://mainnet.infura.io -WS_RPC_URL=wss://mainnet.infura.io/ws/v3/ # ORACLE_RPC_URL should always point to the mainnet ORACLE_RPC_URL=https://mainnet.infura.io REDIS_URL=redis://127.0.0.1:6379 @@ -14,8 +13,7 @@ APP_PORT=8000 PRIVATE_KEY= # 0.05 means 0.05% REGULAR_TORNADO_WITHDRAW_FEE=0.05 -MINING_SERVICE_FEE=0.05 -REWARD_ACCOUNT= +REWARD_ACCOUNT=0x... CONFIRMATIONS=4 # in GWEI diff --git a/src/queue/worker.ts b/src/queue/worker.ts index 9116298..29fe859 100644 --- a/src/queue/worker.ts +++ b/src/queue/worker.ts @@ -8,8 +8,9 @@ export const priceWorker = async () => { const healthService = getHealthService(); const price = new PriceQueueHelper(); + console.log(price.queue.name, 'worker started'); + price.scheduler.on('stalled', (jobId, prev) => console.log({ jobId, prev })); - console.log('price worker', price.queue.name); price.worker.on('active', () => console.log('worker active')); price.worker.on('completed', async (job, result) => { console.log(`Job ${job.name} completed with result: `, result); @@ -22,6 +23,7 @@ export const relayerWorker = async () => { const relayer = new RelayerQueueHelper(); const healthService = getHealthService(); console.log(relayer.queue.name, 'worker started'); + relayer.worker.on('completed', (job, result) => { console.log(`Job ${job.id} completed with result: `, result); }); @@ -33,7 +35,6 @@ export const relayerWorker = async () => { }; export const healthWorker = async () => { - console.log('health worker starting'); await configService.init(); const health = new HealthQueueHelper(); console.log(health.queue.name, 'worker started'); diff --git a/src/services/config.service.ts b/src/services/config.service.ts index 5893667..e8fe5c7 100644 --- a/src/services/config.service.ts +++ b/src/services/config.service.ts @@ -12,7 +12,7 @@ import { tornadoGoerliProxy, tornToken, } from '../config'; -import { Token } from '../types'; +import { ChainIds, Token } from '../types'; import { getProvider, getTornadoProxyContract, getTornadoProxyLightContract, getTornTokenContract } from '../modules/contracts'; import { resolve } from '../modules'; import { ERC20Abi, ProxyLightABI, TornadoProxyABI } from '../contracts'; @@ -56,7 +56,7 @@ export class ConfigService { constructor(private store: RedisStore) { this.netIdKey = `netId${this.netId}`; this.queueName = `relayer_${this.netId}`; - this.isLightMode = ![1, 5].includes(netId); + this.isLightMode = ![ChainIds.ethereum, ChainIds.goerli].includes(netId); this.host = host; this.instances = instances[this.netIdKey]; this.provider = getProvider(false); @@ -85,7 +85,6 @@ export class ConfigService { private _fillInstanceMap() { if (!this.instances) throw new Error('config mismatch, check your environment variables'); - // TODO for (const [currency, { instanceAddress, symbol, decimals }] of Object.entries(this.instances)) { for (const [amount, address] of Object.entries(instanceAddress)) { if (address) @@ -123,23 +122,23 @@ export class ConfigService { } else { this._proxyAddress = tornadoGoerliProxy; this.nativeCurrency = 'eth'; - if (this.netId === 1) { + if (this.netId === ChainIds.ethereum) { this._proxyAddress = await resolve(torn.tornadoRouter.address); } this._proxyContract = getTornadoProxyContract(this._proxyAddress); + this.tokens = [tornToken, ...Object.values(torn.instances['netId1'])] + .map( + (el) => + el.tokenAddress && { + address: getAddress(el.tokenAddress), + decimals: el.decimals, + symbol: el.symbol, + }, + ) + .filter(Boolean); } // TODO get instances from registry - this.tokens = [tornToken, ...Object.values(torn.instances['netId1'])] - .map( - (el) => - el.tokenAddress && { - address: getAddress(el.tokenAddress), - decimals: el.decimals, - symbol: el.symbol, - }, - ) - .filter(Boolean); console.log( 'Configuration completed\n', `-- netId: ${this.netId}\n`, @@ -156,9 +155,9 @@ export class ConfigService { async clearRedisState() { const queueKeys = (await this.store.client.keys('bull:*')).filter((s) => s.indexOf('relayer') === -1); const errorKeys = await this.store.client.keys('errors:*'); - // const alertKeys = await this.store.client.keys('alerts:*'); - const keys = [...queueKeys, ...errorKeys]; - if (keys.length) await this.store.client.del([...queueKeys, ...errorKeys]); + const alertKeys = await this.store.client.keys('alerts:*'); + const keys = [...queueKeys, ...errorKeys, ...alertKeys]; + if (keys.length) await this.store.client.del(keys); } getInstance(address: string) { diff --git a/src/services/health.service.ts b/src/services/health.service.ts index 6afdfe3..7c0eecb 100644 --- a/src/services/health.service.ts +++ b/src/services/health.service.ts @@ -80,10 +80,10 @@ export class HealthService { } async saveError(e, jobId?: string) { - await this.store.client.zadd('errors:code', 'INCR', 1, e?.code || 'RUNTIME_ERROR'); + await this.store.client.zadd('errors:code', 'INCR', 1, e.code || 'RUNTIME_ERROR'); await this.store.client.zadd('errors:log', 'INCR', 1, e.message); - if (e?.code === 'REVERTED' || e?.code === 'SEND_ERROR') { + if (e.code === 'REVERTED' || e.code === 'SEND_ERROR') { const jobUrl = `${this.config.host}/v1/jobs/${jobId}`; await this.pushAlert({ message: `${e.message} \n ${jobUrl}`, diff --git a/src/services/job.service.ts b/src/services/job.service.ts index db19179..3ceec7c 100644 --- a/src/services/job.service.ts +++ b/src/services/job.service.ts @@ -38,15 +38,6 @@ export class JobService { return await this.relayer.queue.getJobCountByTypes('active', 'waiting', 'delayed'); } - private async _clearSchedulerJobs() { - try { - const jobs = await Promise.all([this.price.queue.getJobs(), this.health.queue.getJobs()]); - await Promise.all(jobs.flat().map((job) => job?.remove())); - } catch (e) { - console.log(e); - } - } - async setupRepeatableJobs() { if (!this.config.isLightMode) { await this.price.addRepeatable(this.config.tokens); diff --git a/src/services/price.service.ts b/src/services/price.service.ts index e90c65d..595bf0f 100644 --- a/src/services/price.service.ts +++ b/src/services/price.service.ts @@ -51,15 +51,15 @@ export class PriceService { } async getPrice(currency: string) { - return await this.store.client.hget('prices', currency); + return this.store.client.hget('prices', currency); } async getPrices() { - return await this.store.client.hgetall('prices'); + return this.store.client.hgetall('prices'); } async savePrices(prices: Record) { - return await this.store.client.hset('prices', prices); + return this.store.client.hset('prices', prices); } } diff --git a/src/services/tx.service.ts b/src/services/tx.service.ts index fb92c1f..2da515d 100644 --- a/src/services/tx.service.ts +++ b/src/services/tx.service.ts @@ -60,6 +60,7 @@ export class TxService { provider: this.provider, }); this.oracle = new GasPriceOracle(gasPriceOracleConfig); + switch (netId) { case ChainIds.ethereum: case ChainIds.goerli: