Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
opaolini committed May 19, 2020
1 parent 2ff6977 commit 1608a50
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export const META_TXN_RELAY_EXPECTED_MINED_SEC: number = _.isEmpty(process.env.M
EnvVarType.Integer,
);
// Should TransactionWatcherSignerService sign transactions
// tslint:disable-next-line:boolean-naming
export const ENABLE_TRANSACTION_SIGNING: boolean = _.isEmpty(process.env.ENABLE_TRANSACTION_SIGNING)
? true
: assertEnvVarType('ENABLE_TRANSACTION_SIGNING', process.env.ENABLE_TRANSACTION_SIGNING, EnvVarType.Boolean);
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ export const NUMBER_OF_BLOCKS_UNTIL_CONFIRMED = 3;
export const TX_WATCHER_UPDATE_METRICS_INTERVAL_MS = 30 * 1000;
export const ETH_DECIMALS = 18;
export const GWEI_DECIMALS = 9;
export const SIGNER_ETH_BALANCE_CONSIDERED_CRITICAL = 0.1;
export const SIGNER_STATUS_DB_KEY = 'signer_status';
export const SIGNER_KILL_SWITCH_KEY = 'signer_kill_switch_on';
4 changes: 2 additions & 2 deletions src/handlers/meta_transaction_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ export class MetaTransactionHandlers {
}
public async getSignerStatusAsync(_req: express.Request, res: express.Response): Promise<void> {
try {
const live = await this._metaTransactionService.isSignerLiveAsync();
res.status(HttpStatus.OK).send({ live });
const isLive = await this._metaTransactionService.isSignerLiveAsync();
res.status(HttpStatus.OK).send({ isLive });
} catch (e) {
logger.error('Uncaught error: ', e);
throw new InternalServerError('failed to check signer status');
Expand Down
8 changes: 4 additions & 4 deletions src/services/meta_transaction_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ import {
ONE_SECOND_MS,
PUBLIC_ADDRESS_FOR_ETH_CALLS,
QUOTE_ORDER_EXPIRATION_BUFFER_MS,
SIGNER_KILL_SWITCH_KEY,
SIGNER_STATUS_DB_KEY,
SUBMITTED_TX_DB_POLLING_INTERVAL_MS,
TEN_MINUTES_MS,
TX_HASH_RESPONSE_WAIT_TIME_MS,
SIGNER_STATUS_DB_KEY,
SIGNER_KILL_SWITCH_KEY,
} from '../constants';
import { KeyValueEntity, TransactionEntity } from '../entities';
import { logger } from '../logger';
import { TransactionEntity, KeyValueEntity } from '../entities';
import {
CalculateMetaTransactionPriceResponse,
CalculateMetaTransactionQuoteParams,
GetMetaTransactionQuoteResponse,
PostTransactionResponse,
TransactionStates,
ZeroExTransactionWithoutDomain,
TransactionWatcherSignerStatus,
ZeroExTransactionWithoutDomain,
} from '../types';
import { ethGasStationUtils } from '../utils/gas_station_utils';
import { serviceUtils } from '../utils/service_utils';
Expand Down
32 changes: 20 additions & 12 deletions src/services/transaction_watcher_signer_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ import { Connection, Not, Repository } from 'typeorm';

import {
ENABLE_PROMETHEUS_METRICS,
ENABLE_TRANSACTION_SIGNING,
ETHEREUM_RPC_URL,
META_TXN_RELAY_EXPECTED_MINED_SEC,
META_TXN_RELAY_PRIVATE_KEYS,
ENABLE_TRANSACTION_SIGNING,
} from '../config';
import {
ETH_DECIMALS,
GWEI_DECIMALS,
NUMBER_OF_BLOCKS_UNTIL_CONFIRMED,
ONE_SECOND_MS,
SIGNER_ETH_BALANCE_CONSIDERED_CRITICAL,
SIGNER_STATUS_DB_KEY,
TX_HASH_RESPONSE_WAIT_TIME_MS,
TX_WATCHER_POLLING_INTERVAL_MS,
TX_WATCHER_UPDATE_METRICS_INTERVAL_MS,
UNSTICKING_TRANSACTION_GAS_MULTIPLIER,
SIGNER_STATUS_DB_KEY,
} from '../constants';
import { TransactionEntity, KeyValueEntity } from '../entities';
import { KeyValueEntity, TransactionEntity } from '../entities';
import { logger } from '../logger';
import { TransactionStates, TransactionWatcherSignerStatus } from '../types';
import { ethGasStationUtils } from '../utils/gas_station_utils';
Expand Down Expand Up @@ -212,9 +213,7 @@ export class TransactionWatcherSignerService {
if (txInBlockchain !== undefined && txInBlockchain !== null && txInBlockchain.hash !== undefined) {
if (txInBlockchain.blockNumber !== null) {
logger.trace({
message: `a transaction with a ${
txEntity.status
} status is already on the blockchain, updating status to TransactionStates.Included`,
message: `a transaction with a ${txEntity.status} status is already on the blockchain, updating status to TransactionStates.Included`,
hash: txInBlockchain.hash,
});
txEntity.status = TransactionStates.Included;
Expand All @@ -225,9 +224,7 @@ export class TransactionWatcherSignerService {
// Checks if the txn is in the mempool but still has it's status set to Unsubmitted or Submitted
} else if (!isExpired && txEntity.status !== TransactionStates.Mempool) {
logger.trace({
message: `a transaction with a ${
txEntity.status
} status is pending, updating status to TransactionStates.Mempool`,
message: `a transaction with a ${txEntity.status} status is pending, updating status to TransactionStates.Mempool`,
hash: txInBlockchain.hash,
});
txEntity.status = TransactionStates.Mempool;
Expand Down Expand Up @@ -479,10 +476,13 @@ export class TransactionWatcherSignerService {
this._signerBalancesGauge.set({ signer_address: signerAddress }, balanceInETH);
this._signerBalances.set(signerAddress, balanceInETH);
}
private async _isSignerLive(): boolean {
private _isSignerLive(): boolean {
// TODO: better signer liveliness checks, we just check if any address
// has more than 0.1 ETH available or signing has been explicitly disabled.
return this._signerBalances.values().filter(val => val > 0.1).length > 0 && ENABLE_TRANSACTION_SIGNING;
return (
[...this._signerBalances.values()].filter(val => val > SIGNER_ETH_BALANCE_CONSIDERED_CRITICAL).length > 0 &&
ENABLE_TRANSACTION_SIGNING
);
}
private async _updateSignerStatusAsync(): Promise<void> {
// TODO: do we need to find the entity first, for UPDATE?
Expand All @@ -492,9 +492,17 @@ export class TransactionWatcherSignerService {
}
const statusContent: TransactionWatcherSignerStatus = {
live: this._isSignerLive(),
balances: this._signerBalances,
// tslint:disable-next-line:no-inferred-empty-object-type
balances: [...this._signerBalances.entries()].reduce((acc: object, signerBalance: [string, number]): Record<
string,
number
> => {
const [from, balance] = signerBalance;
return { ...acc, [from]: balance };
}, {}),
};
statusKV.value = JSON.stringify(statusContent);
await this._kvRepository.save(statusKV);
}
}
// tslint:disable-line:max-file-line-count

0 comments on commit 1608a50

Please sign in to comment.