Skip to content

Commit 5e95b5d

Browse files
Fix oracle error patterns and oracle e2e tests (#585)
1 parent 6e1f574 commit 5e95b5d

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ jobs:
205205
- name: Login to docker registry
206206
run: docker login ${DOCKER_REGISTRY} -u ${{ github.actor }} -p ${{ github.token }}
207207
- name: Deploy contracts
208-
run: ${{ steps.cache-repo.outputs.cache-hit }} && e2e-commons/up.sh deploy blocks
208+
run: ${{ steps.cache-repo.outputs.cache-hit }} && e2e-commons/up.sh deploy generate-amb-tx blocks
209209
- name: Pull e2e oracle image
210210
run: |
211211
docker-compose -f ./e2e-commons/docker-compose.yml pull oracle-amb

oracle-e2e/test/amb.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,19 @@ describe('arbitrary message bridging', () => {
6363
}
6464
})
6565
})
66-
describe('Confirm Relay', () => {
67-
it('should process lost affirmation-request via confirm relay', async () => {
68-
const value = await homeBox.methods.value().call()
69-
assert(value === '789', 'incorrect value')
70-
})
66+
if (process.env.ULTIMATE !== 'true') {
67+
describe('Confirm Relay', () => {
68+
it('should process lost affirmation-request via confirm relay', async () => {
69+
const value = await homeBox.methods.value().call()
70+
assert(value === '789', 'incorrect value')
71+
})
7172

72-
it('should process lost signature-request & collected-signatures via confirm relay', async () => {
73-
const value = await foreignBox.methods.value().call()
74-
assert(value === '123', 'incorrect value')
73+
it('should process lost signature-request & collected-signatures via confirm relay', async () => {
74+
const value = await foreignBox.methods.value().call()
75+
assert(value === '123', 'incorrect value')
76+
})
7577
})
76-
})
78+
}
7779
describe('Home to Foreign', () => {
7880
describe('Subsidized Mode', () => {
7981
it('should bridge message', async () => {

oracle/src/sender.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ const {
1414
waitForFunds,
1515
waitForUnsuspend,
1616
watchdog,
17-
nonceError
17+
isGasPriceError,
18+
isSameTransactionError,
19+
isInsufficientBalanceError,
20+
isNonceError
1821
} = require('./utils/utils')
1922
const { EXIT_CODES, EXTRA_GAS_PERCENTAGE, MAX_GAS_LIMIT } = require('./utils/constants')
2023

@@ -189,12 +192,11 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
189192
e.message
190193
)
191194

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

206-
if (message.includes('insufficient funds')) {
208+
if (isInsufficientBalanceError(e)) {
207209
insufficientFunds = true
208210
const currentBalance = await web3.eth.getBalance(config.validatorAddress)
209211
minimumBalance = gasLimit.multipliedBy(gasPrice)
210212
logger.error(
211213
`Insufficient funds: ${currentBalance}. Stop processing messages until the balance is at least ${minimumBalance}.`
212214
)
213-
} else if (nonceError(e)) {
215+
} else if (isNonceError(e)) {
214216
nonce = await readNonce(true)
215217
}
216218
}

oracle/src/utils/utils.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,22 @@ function privateKeyToAddress(privateKey) {
9999
return privateKey ? new Web3().eth.accounts.privateKeyToAccount(add0xPrefix(privateKey)).address : null
100100
}
101101

102-
function nonceError(e) {
102+
function isGasPriceError(e) {
103+
const message = e.message.toLowerCase()
104+
return message.includes('replacement transaction underpriced')
105+
}
106+
107+
function isSameTransactionError(e) {
108+
const message = e.message.toLowerCase()
109+
return message.includes('transaction with the same hash was already imported') || message.includes('already known')
110+
}
111+
112+
function isInsufficientBalanceError(e) {
113+
const message = e.message.toLowerCase()
114+
return message.includes('insufficient funds')
115+
}
116+
117+
function isNonceError(e) {
103118
const message = e.message.toLowerCase()
104119
return (
105120
message.includes('transaction nonce is too low') ||
@@ -155,7 +170,10 @@ module.exports = {
155170
watchdog,
156171
add0xPrefix,
157172
privateKeyToAddress,
158-
nonceError,
173+
isGasPriceError,
174+
isSameTransactionError,
175+
isInsufficientBalanceError,
176+
isNonceError,
159177
getRetrySequence,
160178
promiseAny,
161179
readAccessListFile,

0 commit comments

Comments
 (0)