Skip to content

Commit

Permalink
Fix oracle error patterns and oracle e2e tests (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev authored Jul 8, 2021
1 parent 6e1f574 commit 5e95b5d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ jobs:
- name: Login to docker registry
run: docker login ${DOCKER_REGISTRY} -u ${{ github.actor }} -p ${{ github.token }}
- name: Deploy contracts
run: ${{ steps.cache-repo.outputs.cache-hit }} && e2e-commons/up.sh deploy blocks
run: ${{ steps.cache-repo.outputs.cache-hit }} && e2e-commons/up.sh deploy generate-amb-tx blocks
- name: Pull e2e oracle image
run: |
docker-compose -f ./e2e-commons/docker-compose.yml pull oracle-amb
Expand Down
20 changes: 11 additions & 9 deletions oracle-e2e/test/amb.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,19 @@ describe('arbitrary message bridging', () => {
}
})
})
describe('Confirm Relay', () => {
it('should process lost affirmation-request via confirm relay', async () => {
const value = await homeBox.methods.value().call()
assert(value === '789', 'incorrect value')
})
if (process.env.ULTIMATE !== 'true') {
describe('Confirm Relay', () => {
it('should process lost affirmation-request via confirm relay', async () => {
const value = await homeBox.methods.value().call()
assert(value === '789', 'incorrect value')
})

it('should process lost signature-request & collected-signatures via confirm relay', async () => {
const value = await foreignBox.methods.value().call()
assert(value === '123', 'incorrect value')
it('should process lost signature-request & collected-signatures via confirm relay', async () => {
const value = await foreignBox.methods.value().call()
assert(value === '123', 'incorrect value')
})
})
})
}
describe('Home to Foreign', () => {
describe('Subsidized Mode', () => {
it('should bridge message', async () => {
Expand Down
14 changes: 8 additions & 6 deletions oracle/src/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const {
waitForFunds,
waitForUnsuspend,
watchdog,
nonceError
isGasPriceError,
isSameTransactionError,
isInsufficientBalanceError,
isNonceError
} = require('./utils/utils')
const { EXIT_CODES, EXTRA_GAS_PERCENTAGE, MAX_GAS_LIMIT } = require('./utils/constants')

Expand Down Expand Up @@ -189,12 +192,11 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
e.message
)

const message = e.message.toLowerCase()
if (message.includes('replacement transaction underpriced')) {
if (isGasPriceError(e)) {
logger.info('Replacement transaction underpriced, forcing gas price update')
GasPrice.start(config.id)
failedTx.push(job)
} else if (isResend || message.includes('transaction with the same hash was already imported')) {
} else if (isResend || isSameTransactionError(e)) {
resendJobs.push(job)
} else {
// if initial transaction sending has failed not due to the same hash error
Expand All @@ -203,14 +205,14 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
failedTx.push(job)
}

if (message.includes('insufficient funds')) {
if (isInsufficientBalanceError(e)) {
insufficientFunds = true
const currentBalance = await web3.eth.getBalance(config.validatorAddress)
minimumBalance = gasLimit.multipliedBy(gasPrice)
logger.error(
`Insufficient funds: ${currentBalance}. Stop processing messages until the balance is at least ${minimumBalance}.`
)
} else if (nonceError(e)) {
} else if (isNonceError(e)) {
nonce = await readNonce(true)
}
}
Expand Down
22 changes: 20 additions & 2 deletions oracle/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,22 @@ function privateKeyToAddress(privateKey) {
return privateKey ? new Web3().eth.accounts.privateKeyToAccount(add0xPrefix(privateKey)).address : null
}

function nonceError(e) {
function isGasPriceError(e) {
const message = e.message.toLowerCase()
return message.includes('replacement transaction underpriced')
}

function isSameTransactionError(e) {
const message = e.message.toLowerCase()
return message.includes('transaction with the same hash was already imported') || message.includes('already known')
}

function isInsufficientBalanceError(e) {
const message = e.message.toLowerCase()
return message.includes('insufficient funds')
}

function isNonceError(e) {
const message = e.message.toLowerCase()
return (
message.includes('transaction nonce is too low') ||
Expand Down Expand Up @@ -155,7 +170,10 @@ module.exports = {
watchdog,
add0xPrefix,
privateKeyToAddress,
nonceError,
isGasPriceError,
isSameTransactionError,
isInsufficientBalanceError,
isNonceError,
getRetrySequence,
promiseAny,
readAccessListFile,
Expand Down

0 comments on commit 5e95b5d

Please sign in to comment.