Skip to content

Commit

Permalink
hotfix: do not log connection errors
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsmith-gooddollar committed Jan 16, 2024
1 parent d7d518a commit 7c95d33
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
49 changes: 18 additions & 31 deletions src/lib/wallet/GoodWalletClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import { signTypedData } from '@metamask/eth-sig-util'
import Mutex from 'await-mutex'
import { pRateLimit } from 'p-ratelimit'
import Config from '../../config/config'
import logger from '../logger/js-logger'
import { ExceptionCategory } from '../exceptions/utils'
import { tryJson } from '../utils/string'
import API from '../API'
Expand All @@ -58,6 +57,8 @@ import WalletFactory from './WalletFactory'
import {
fromDecimals,
getTxLogArgs,
log,
logError,
NULL_ADDRESS,
safeCall,
toDecimals,
Expand All @@ -77,8 +78,6 @@ const ZERO = new BN('0')
const POKT_MAX_EVENTSBLOCKS = 40000
const FIXED_SEND_GAS = 21000

const log = logger.child({ from: 'GoodWalletV2' })

type EventLog = {
event: string,
address: string,
Expand Down Expand Up @@ -374,7 +373,7 @@ export class GoodWallet {
const currentBlock = await this.getBlockNumber()

const lastBlock = await this.syncTxFromExplorer(startBlock, currentBlock).catch(e => {
log.error('syncTxFromExplorer failed', e.message, e, {
logError('syncTxFromExplorer failed', e, {
networkId: this.networkId,
startBlock,
})
Expand Down Expand Up @@ -443,7 +442,7 @@ export class GoodWallet {
return Promise.all(
uniqEvents.map(event =>
this._notifyReceipt(event.transactionHash).catch(err =>
log.error('_notifyEvents event get/send receipt failed:', err.message, err, {
logError('_notifyEvents event get/send receipt failed:', err, {
category: ExceptionCategory.Blockhain,
}),
),
Expand Down Expand Up @@ -545,7 +544,7 @@ export class GoodWallet {

return lastBlock
} catch (e) {
log.error('syncTxWithBlockchain failed', e.message, e, { startBlock, lastBlock, networkId: this.networkId })
logError('syncTxWithBlockchain failed', e, { startBlock, lastBlock, networkId: this.networkId })
}
}

Expand Down Expand Up @@ -741,9 +740,7 @@ export class GoodWallet {
.then(parseInt),
)
} catch (exception) {
const { message } = exception

log.error('checkEntitlement failed', message, exception)
logError('checkEntitlement failed', exception)
return 0
}
}
Expand Down Expand Up @@ -903,9 +900,7 @@ export class GoodWallet {

return balanceValue
} catch (exception) {
const { message } = exception

log.error('BalanceOf failed', message, exception)
logError('BalanceOf failed', exception)
return toBN(0)
}
}
Expand Down Expand Up @@ -988,9 +983,7 @@ export class GoodWallet {
try {
return retryCall(() => this.identityContract.methods.isWhitelisted(address).call())
} catch (exception) {
const { message } = exception

log.error('isVerified failed', message, exception)
logError('isVerified failed', exception)
return false
}
}
Expand Down Expand Up @@ -1073,9 +1066,7 @@ export class GoodWallet {

return amountWithFee.lte(new BN(String(balance)))
} catch (exception) {
const { message } = exception

log.error('canSend failed', message, exception)
logError('canSend failed', exception)
}
return false
}
Expand All @@ -1095,9 +1086,7 @@ export class GoodWallet {

return amountWithFee.lte(new BN(String(balance)))
} catch (exception) {
const { message } = exception

log.error('canSendNative failed', message, exception)
logError('canSendNative failed', exception)
}
return false
}
Expand Down Expand Up @@ -1179,9 +1168,7 @@ export class GoodWallet {
try {
return retryCall(() => this.oneTimePaymentsContract.methods.hasPayment(link).call())
} catch (exception) {
const { message } = exception

log.error('isPaymentLinkAvailable failed', message, exception)
logError('isPaymentLinkAvailable failed', exception)
return false
}
}
Expand Down Expand Up @@ -1343,7 +1330,7 @@ export class GoodWallet {

return registered !== NULL_ADDRESS
} catch (e) {
log.error('isInviterCodeValid failed:', e.message, e)
logError('isInviterCodeValid failed:', e)
return false
}
}
Expand All @@ -1354,7 +1341,7 @@ export class GoodWallet {

return [parseInt(user.joinedAt) > 0, user.invitedBy, user.inviteCode]
} catch (e) {
log.error('hasJoinedInvites failed:', e.message, e)
logError('hasJoinedInvites failed:', e)
return [false, null, null]
}
}
Expand Down Expand Up @@ -1407,7 +1394,7 @@ export class GoodWallet {
log.debug('joinInvites registering:', { inviter, myCode, inviteCode, hasJoined, codeLength, registered })

await this.sendTransaction(tx).catch(e => {
log.error('joinInvites failed:', e.message, e, { inviter, myCode, codeLength, registered })
logError('joinInvites failed:', e, { inviter, myCode, codeLength, registered })
throw e
})
}
Expand Down Expand Up @@ -1472,7 +1459,7 @@ export class GoodWallet {
gasPrice = networkGasPrice.toString()
}
} catch (e) {
log.error('failed to retrieve gas price from network', e.message, e, { category: ExceptionCategory.Blockhain })
logError('failed to retrieve gas price from network', e, { category: ExceptionCategory.Blockhain })
}

return gasPrice
Expand Down Expand Up @@ -1571,7 +1558,7 @@ export class GoodWallet {
})
.then(_ => true)
.catch(e => {
log.error('verifyHasGas faucet failed', e.message, e)
logError('verifyHasGas faucet failed', e)
return false
})

Expand Down Expand Up @@ -1606,7 +1593,7 @@ export class GoodWallet {
ok: data.ok && nativeBalance > minWei,
}
} catch (e) {
log.error('verifyHasGas failed:', e.message, e, { minWei })
logError('verifyHasGas failed:', e, { minWei })

return {
ok: false,
Expand Down Expand Up @@ -1753,7 +1740,7 @@ export class GoodWallet {
onConfirmation(confirmation)
})
.on('error', exception => {
log.error('sendNativeTransaction error:', exception.message, exception, {
logError('sendNativeTransaction error:', exception, {
tx: txData,
category: ExceptionCategory.Blockhain,
})
Expand Down
14 changes: 10 additions & 4 deletions src/lib/wallet/MultipleHttpProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import Web3 from 'web3'
import { assign, has, shuffle } from 'lodash'
import { fallback, makePromiseWrapper, retry } from '../utils/async'
import logger from '../logger/js-logger'
import { isConnectionError } from './utils'

const { providers } = Web3
const { HttpProvider } = providers
const log = logger.child({ from: 'MultipleHttpProvider' })
const connectionErrorRe = /connection (error|timeout)|invalid json rpc/i

export class MultipleHttpProvider extends HttpProvider {
constructor(endpoints, config) {
Expand Down Expand Up @@ -51,7 +51,10 @@ export class MultipleHttpProvider extends HttpProvider {
}

const onFailed = error => {
log.error('Failed with last error', error.message, error, payload.id)
if (!isConnectionError(error)) {
log.error('Failed with last error', error.message, error, payload.id)
}

callback(error, null)
}

Expand All @@ -60,9 +63,12 @@ export class MultipleHttpProvider extends HttpProvider {
const { message, code } = error

// retry on network error or if rpc responded with error (error.error)
const willFallback = !!(code || error.error || !message || connectionErrorRe.test(message))
const willFallback = !!(code || error.error || !message || isConnectionError(message))

if (!willFallback) {
log.warn('send: got error', { message, error, willFallback })
}

log.warn('send: got error', { message, error, willFallback })
return willFallback
}

Expand Down
22 changes: 17 additions & 5 deletions src/lib/wallet/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { formatUnits, parseUnits } from '@ethersproject/units'
import { ExceptionCategory } from '../exceptions/utils'
import type { TransactionEvent } from '../../userStorage/UserStorageClass'
import { getNetworkName, type NETWORK, NETWORK_ID } from '../constants/network'
import pino from '../logger/js-logger'
import logger from '../logger/js-logger'
import { retry } from '../utils/async'
import Config from '../../config/config'

export const log = logger.child({ from: 'GoodWalletV2' })

const DECIMALS = 2
const log = pino.child({ from: 'withdraw' })
const ethAddressRegex = /(\w+)?:?(0x[a-fA-F0-9]{40})/
const { env, showAllChainsEth } = Config

Expand Down Expand Up @@ -168,6 +169,8 @@ export const getTxLogArgs = tx => {
}
}

const wdLog = logger.child({ from: 'withdraw' })

/**
* Execute withdraw from a transaction hash, and handle dialogs with process information using Undux
*
Expand All @@ -187,7 +190,7 @@ export const executeWithdraw = async (
const { amount, sender, status, hashedCode } = await goodWallet.getWithdrawDetails(code)
let response = { status }

log.info('executeWithdraw', { code, reason, category, amount, sender, status, hashedCode })
wdLog.info('executeWithdraw', { code, reason, category, amount, sender, status, hashedCode })

if (sender.toLowerCase() === goodWallet.account.toLowerCase()) {
throw new Error("You can't withdraw your own payment link.")
Expand Down Expand Up @@ -245,9 +248,9 @@ export const executeWithdraw = async (
]

if (isOwnLinkIssue) {
log.warn(...logArgs)
wdLog.warn(...logArgs)
} else {
log.error(...logArgs)
wdLog.error(...logArgs)
}

throw e
Expand Down Expand Up @@ -282,3 +285,12 @@ export const isDuplicateTxError = message =>
message
.toLowerCase()
.search('same nonce|same hash|alreadyknown|already known|feetoolow|nonce is too low|underpriced') >= 0

export const isConnectionError = error =>
/connection (error|timeout)|invalid json rpc/i.test(error instanceof Error ? error.message : error || '')

export const logError = (label, error, data = undefined) => {
if (!isConnectionError) {
log.error(label, error.message, error, data)
}
}

0 comments on commit 7c95d33

Please sign in to comment.