Refactor oracle configuration (#584)

This commit is contained in:
Kirill Fedoseev 2021-07-08 09:38:55 +03:00 committed by GitHub
parent 8ed6550635
commit 6e1f57493a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 81 additions and 121 deletions

@ -27,17 +27,6 @@
set_fact: set_fact:
ORACLE_VALIDATOR_ADDRESS: "{{ VADDRESS.stdout }}" ORACLE_VALIDATOR_ADDRESS: "{{ VADDRESS.stdout }}"
- name: Get foreign erc type
become_user: "{{ compose_service_user }}"
shell: docker-compose run --rm --entrypoint "node scripts/initialChecks.js" bridge_affirmation
args:
chdir: "{{ bridge_path }}/oracle"
register: ERCTYPE
- name: Set FOREIGN_ERC_TYPE variable
set_fact:
FOREIGN_ERC_TYPE: "{{ (ERCTYPE.stdout).foreignERC | default('') }}"
- name: Extend docker compose file for erc to native - name: Extend docker compose file for erc to native
set_fact: composefileoverride="-f docker-compose-transfer.yml" set_fact: composefileoverride="-f docker-compose-transfer.yml"
when: ORACLE_BRIDGE_MODE == "ERC_TO_NATIVE" when: ORACLE_BRIDGE_MODE == "ERC_TO_NATIVE"

@ -6,8 +6,6 @@ COMMON_HOME_RPC_URL=http://parity1:8545
COMMON_FOREIGN_RPC_URL=http://parity2:8545 COMMON_FOREIGN_RPC_URL=http://parity2:8545
COMMON_HOME_BRIDGE_ADDRESS=0x8397be90BCF57b0B71219f555Fe121b22e5a994C COMMON_HOME_BRIDGE_ADDRESS=0x8397be90BCF57b0B71219f555Fe121b22e5a994C
COMMON_FOREIGN_BRIDGE_ADDRESS=0x1feB40aD9420b186F019A717c37f5546165d411E COMMON_FOREIGN_BRIDGE_ADDRESS=0x1feB40aD9420b186F019A717c37f5546165d411E
ORACLE_VALIDATOR_ADDRESS=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b
ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9
COMMON_HOME_GAS_PRICE_SUPPLIER_URL= COMMON_HOME_GAS_PRICE_SUPPLIER_URL=
COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard
COMMON_HOME_GAS_PRICE_FALLBACK=1000000000 COMMON_HOME_GAS_PRICE_FALLBACK=1000000000

@ -6,8 +6,6 @@ COMMON_HOME_RPC_URL=http://parity1:8545
COMMON_FOREIGN_RPC_URL=http://parity2:8545 COMMON_FOREIGN_RPC_URL=http://parity2:8545
COMMON_HOME_BRIDGE_ADDRESS=0x5118AC62AE912Dd5B51EEfF7338c4fcb0248Ba8c COMMON_HOME_BRIDGE_ADDRESS=0x5118AC62AE912Dd5B51EEfF7338c4fcb0248Ba8c
COMMON_FOREIGN_BRIDGE_ADDRESS=0x32198D570fffC7033641F8A9094FFDCaAEF42624 COMMON_FOREIGN_BRIDGE_ADDRESS=0x32198D570fffC7033641F8A9094FFDCaAEF42624
ORACLE_VALIDATOR_ADDRESS=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b
ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9
COMMON_HOME_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/ COMMON_HOME_GAS_PRICE_SUPPLIER_URL=https://gasprice.poa.network/
COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard COMMON_HOME_GAS_PRICE_SPEED_TYPE=standard
COMMON_HOME_GAS_PRICE_FALLBACK=1 COMMON_HOME_GAS_PRICE_FALLBACK=1

@ -15,42 +15,46 @@ docker network create --driver bridge ultimate || true
docker-compose up -d parity1 parity2 e2e docker-compose up -d parity1 parity2 e2e
startValidator () { startValidator () {
db_env="-e ORACLE_QUEUE_URL=amqp://$4 -e ORACLE_REDIS_URL=redis://$3" db_env="-e ORACLE_QUEUE_URL=amqp://$3 -e ORACLE_REDIS_URL=redis://$2"
docker-compose $1 run -d --name $3 redis docker-compose $1 run -d --name $2 redis
docker-compose $1 run -d --name $4 rabbit docker-compose $1 run -d --name $3 rabbit
if [[ -z "$MODE" || "$MODE" == erc-to-native ]]; then if [[ -z "$MODE" || "$MODE" == erc-to-native ]]; then
docker-compose $1 run $2 $db_env -d oracle-erc20-native yarn watcher:signature-request docker-compose $1 run $oraclePK $db_env -d oracle-erc20-native yarn watcher:signature-request
docker-compose $1 run $2 $db_env -d oracle-erc20-native yarn watcher:collected-signatures docker-compose $1 run $oracleAddr $db_env -d oracle-erc20-native yarn watcher:collected-signatures
docker-compose $1 run $2 $db_env -d oracle-erc20-native yarn watcher:affirmation-request docker-compose $1 run $oracleAddr $db_env -d oracle-erc20-native yarn watcher:affirmation-request
docker-compose $1 run $2 $db_env -d oracle-erc20-native yarn watcher:transfer docker-compose $1 run $oracleAddr $db_env -d oracle-erc20-native yarn watcher:transfer
fi fi
if [[ -z "$MODE" || "$MODE" == amb ]]; then if [[ -z "$MODE" || "$MODE" == amb ]]; then
docker-compose $1 run $2 $db_env -d oracle-amb yarn watcher:signature-request docker-compose $1 run $oraclePK $db_env -d oracle-amb yarn watcher:signature-request
docker-compose $1 run $2 $db_env -d oracle-amb yarn watcher:collected-signatures docker-compose $1 run $oracleAddr $db_env -d oracle-amb yarn watcher:collected-signatures
docker-compose $1 run $2 $db_env -d oracle-amb yarn watcher:affirmation-request docker-compose $1 run $oracleAddr $db_env -d oracle-amb yarn watcher:affirmation-request
docker-compose $1 run $2 $db_env -d oracle-amb yarn watcher:information-request docker-compose $1 run $oracleAddr $db_env -d oracle-amb yarn watcher:information-request
fi fi
docker-compose $1 run $2 $db_env -d oracle-amb yarn sender:home docker-compose $1 run $oraclePK $db_env -d oracle-amb yarn sender:home
docker-compose $1 run $2 $db_env -d oracle-amb yarn sender:foreign docker-compose $1 run $oraclePK $db_env -d oracle-amb yarn sender:foreign
docker-compose $1 run $2 $db_env -d oracle-amb yarn manager:shutdown docker-compose $1 run $oracleAddr $db_env -d oracle-amb yarn manager:shutdown
} }
while [ "$1" != "" ]; do while [ "$1" != "" ]; do
if [ "$1" == "oracle" ]; then if [ "$1" == "oracle" ]; then
startValidator "-p validator1" "" redis rabbit oracleAddr="-e ORACLE_VALIDATOR_ADDRESS=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b"
oraclePK="-e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9"
startValidator "-p validator1" redis rabbit
fi fi
if [ "$1" == "oracle-validator-2" ]; then if [ "$1" == "oracle-validator-2" ]; then
oracle2Values="-e ORACLE_VALIDATOR_ADDRESS=0xdCC784657C78054aa61FbcFFd2605F32374816A4 -e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=5a5c3645d0f04e9eb4f27f94ed4c244a225587405b8838e7456f7781ce3a9513" oracleAddr="-e ORACLE_VALIDATOR_ADDRESS=0xdCC784657C78054aa61FbcFFd2605F32374816A4"
startValidator "-p validator2" "$oracle2Values" redis2 rabbit2 oraclePK="-e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=5a5c3645d0f04e9eb4f27f94ed4c244a225587405b8838e7456f7781ce3a9513"
startValidator "-p validator2" redis2 rabbit2
fi fi
if [ "$1" == "oracle-validator-3" ]; then if [ "$1" == "oracle-validator-3" ]; then
oracle3Values="-e ORACLE_VALIDATOR_ADDRESS=0xDcef88209a20D52165230104B245803C3269454d -e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=f877f62a1c19f852cff1d29f0fb1ecac18821c0080d4cc0520c60c098293dca1" oracleAddr="-e ORACLE_VALIDATOR_ADDRESS=0xDcef88209a20D52165230104B245803C3269454d"
startValidator "-p validator3" "$oracle3Values" redis3 rabbit3 oraclePK="-e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=f877f62a1c19f852cff1d29f0fb1ecac18821c0080d4cc0520c60c098293dca1"
startValidator "-p validator3" redis3 rabbit3
fi fi
if [ "$1" == "alm" ]; then if [ "$1" == "alm" ]; then
@ -84,13 +88,17 @@ while [ "$1" != "" ]; do
if [ "$1" == "alm-e2e" ]; then if [ "$1" == "alm-e2e" ]; then
MODE=amb MODE=amb
startValidator "-p validator1" "" redis rabbit oracleAddr="-e ORACLE_VALIDATOR_ADDRESS=0xaaB52d66283F7A1D5978bcFcB55721ACB467384b"
oraclePK="-e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9"
startValidator "-p validator1" redis rabbit
oracle2Values="-e ORACLE_VALIDATOR_ADDRESS=0xdCC784657C78054aa61FbcFFd2605F32374816A4 -e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=5a5c3645d0f04e9eb4f27f94ed4c244a225587405b8838e7456f7781ce3a9513" oracleAddr="-e ORACLE_VALIDATOR_ADDRESS=0xdCC784657C78054aa61FbcFFd2605F32374816A4"
startValidator "-p validator2" "$oracle2Values" redis2 rabbit2 oraclePK="-e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=5a5c3645d0f04e9eb4f27f94ed4c244a225587405b8838e7456f7781ce3a9513"
startValidator "-p validator2" redis2 rabbit2
oracle3Values="-e ORACLE_VALIDATOR_ADDRESS=0xDcef88209a20D52165230104B245803C3269454d -e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=f877f62a1c19f852cff1d29f0fb1ecac18821c0080d4cc0520c60c098293dca1" oracleAddr="-e ORACLE_VALIDATOR_ADDRESS=0xDcef88209a20D52165230104B245803C3269454d"
startValidator "-p validator3" "$oracle3Values" redis3 rabbit3 oraclePK="-e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=f877f62a1c19f852cff1d29f0fb1ecac18821c0080d4cc0520c60c098293dca1"
startValidator "-p validator3" redis3 rabbit3
fi fi
if [ "$1" == "generate-amb-tx" ]; then if [ "$1" == "generate-amb-tx" ]; then
@ -98,19 +106,20 @@ while [ "$1" != "" ]; do
fi fi
if [ "$1" == "manual-amb-relay" ]; then if [ "$1" == "manual-amb-relay" ]; then
oraclePK="-e ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=8e829f695aed89a154550f30262f1529582cc49dc30eff74a6b491359e0230f9"
env="-e COMMON_HOME_BRIDGE_ADDRESS=0x5A42E119990c3F3A80Fea20aAF4c3Ff4DB240Cc9 -e COMMON_FOREIGN_BRIDGE_ADDRESS=0x897527391ad3837604973d78D3514f44c36AB9FC" env="-e COMMON_HOME_BRIDGE_ADDRESS=0x5A42E119990c3F3A80Fea20aAF4c3Ff4DB240Cc9 -e COMMON_FOREIGN_BRIDGE_ADDRESS=0x897527391ad3837604973d78D3514f44c36AB9FC"
# these tx hash are hardcoded and need to be updated manually # these tx hash are hardcoded and need to be updated manually
# once e2e environment setup process is changed # once e2e environment setup process is changed
echo '0xea625a823bc5018dc3a4efe349f623e5ebb8c987b55f44d50d6556f42af9a400' > txHashes.txt echo '0xea625a823bc5018dc3a4efe349f623e5ebb8c987b55f44d50d6556f42af9a400' > txHashes.txt
docker-compose -p validator1 run -v $(pwd)/txHashes.txt:/tmp/txHashes.txt $env oracle-amb yarn confirm:affirmation-request \ docker-compose -p validator1 run -v $(pwd)/txHashes.txt:/tmp/txHashes.txt $oraclePK $env oracle-amb yarn confirm:affirmation-request \
/tmp/txHashes.txt \ /tmp/txHashes.txt \
0x031c42e44485002c9215a5b1b75e9516131485ce29884a58765bf7a0038538f9 0x031c42e44485002c9215a5b1b75e9516131485ce29884a58765bf7a0038538f9
docker-compose -p validator1 run $env oracle-amb yarn confirm:signature-request \ docker-compose -p validator1 run $oraclePK $env oracle-amb yarn confirm:signature-request \
0x1506a18af91afe732167ccbc178b55fc2547da4a814d13c015b6f496cf171754 | tee .tmp.log 0x1506a18af91afe732167ccbc178b55fc2547da4a814d13c015b6f496cf171754 | tee .tmp.log
tx_hash=$(cat .tmp.log | grep generatedTransactionHash | jq -r .generatedTransactionHash) tx_hash=$(cat .tmp.log | grep generatedTransactionHash | jq -r .generatedTransactionHash)
rm .tmp.log rm .tmp.log
rm txHashes.txt rm txHashes.txt
docker-compose -p validator1 run $env oracle-amb yarn confirm:collected-signatures $tx_hash docker-compose -p validator1 run $oraclePK $env oracle-amb yarn confirm:collected-signatures $tx_hash
fi fi
shift # Shift all the parameters down by one shift # Shift all the parameters down by one

@ -100,6 +100,8 @@ describe('erc to native', () => {
const transferValue = homeWeb3.utils.toWei('0.05') const transferValue = homeWeb3.utils.toWei('0.05')
// transfer that should not be processed by the filter
await erc20Token.methods.transfer(secondUser.address, transferValue).send({ from: user.address, gas: 100000 })
// send tokens to foreign bridge // send tokens to foreign bridge
await erc20Token.methods await erc20Token.methods
.transfer(COMMON_FOREIGN_BRIDGE_ADDRESS, transferValue) .transfer(COMMON_FOREIGN_BRIDGE_ADDRESS, transferValue)

@ -8,7 +8,8 @@ const {
FOREIGN_AMB_ABI FOREIGN_AMB_ABI
} = require('../../commons') } = require('../../commons')
const { web3Home, web3Foreign } = require('../src/services/web3') const { web3Home, web3Foreign } = require('../src/services/web3')
const { privateKeyToAddress } = require('../src/utils/utils') const { add0xPrefix, privateKeyToAddress } = require('../src/utils/utils')
const { EXIT_CODES } = require('../src/utils/constants')
const { const {
ORACLE_BRIDGE_MODE, ORACLE_BRIDGE_MODE,
@ -79,9 +80,22 @@ const foreignConfig = {
const maxProcessingTime = const maxProcessingTime =
parseInt(ORACLE_MAX_PROCESSING_TIME, 10) || 4 * Math.max(homeConfig.pollingInterval, foreignConfig.pollingInterval) parseInt(ORACLE_MAX_PROCESSING_TIME, 10) || 4 * Math.max(homeConfig.pollingInterval, foreignConfig.pollingInterval)
let validatorPrivateKey
if (ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY) {
validatorPrivateKey = add0xPrefix(ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY)
const derived = privateKeyToAddress(validatorPrivateKey)
if (ORACLE_VALIDATOR_ADDRESS && derived.toLowerCase() !== ORACLE_VALIDATOR_ADDRESS.toLowerCase()) {
console.error(
`Derived address from private key - ${derived} is different from ORACLE_VALIDATOR_ADDRESS=${ORACLE_VALIDATOR_ADDRESS}`
)
process.exit(EXIT_CODES.INCOMPATIBILITY)
}
}
module.exports = { module.exports = {
eventFilter: {}, eventFilter: {},
validatorAddress: ORACLE_VALIDATOR_ADDRESS || privateKeyToAddress(ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY), validatorPrivateKey,
validatorAddress: ORACLE_VALIDATOR_ADDRESS || privateKeyToAddress(validatorPrivateKey),
maxProcessingTime, maxProcessingTime,
shutdownKey: 'oracle-shutdown', shutdownKey: 'oracle-shutdown',
home: homeConfig, home: homeConfig,

@ -1,20 +1,7 @@
const baseConfig = require('./base.config') const baseConfig = require('./base.config')
const { ERC20_ABI } = require('../../commons') const { ERC20_ABI, ZERO_ADDRESS } = require('../../commons')
const { EXIT_CODES } = require('../src/utils/constants') const { EXIT_CODES } = require('../src/utils/constants')
const initialChecksJson = process.argv[3]
if (!initialChecksJson) {
throw new Error('initial check parameter was not provided.')
}
let initialChecks
try {
initialChecks = JSON.parse(initialChecksJson)
} catch (e) {
throw new Error('Error on decoding values from initial checks.')
}
const id = `${baseConfig.id}-transfer` const id = `${baseConfig.id}-transfer`
if (baseConfig.id !== 'erc-native') { if (baseConfig.id !== 'erc-native') {
@ -22,14 +9,14 @@ if (baseConfig.id !== 'erc-native') {
process.exit(EXIT_CODES.WATCHER_NOT_REQUIRED) process.exit(EXIT_CODES.WATCHER_NOT_REQUIRED)
} }
// exact address of the token contract is set in the watcher.js checkConditions() function
baseConfig.foreign.eventContract = new baseConfig.foreign.web3.eth.Contract(ERC20_ABI, ZERO_ADDRESS)
module.exports = { module.exports = {
...baseConfig, ...baseConfig,
main: { main: baseConfig.foreign,
...baseConfig.foreign,
eventContract: new baseConfig.foreign.web3.eth.Contract(ERC20_ABI, initialChecks.bridgeableTokenAddress)
},
event: 'Transfer', event: 'Transfer',
eventFilter: { to: process.env.COMMON_FOREIGN_BRIDGE_ADDRESS }, eventFilter: { to: baseConfig.foreign.bridgeAddress },
sender: 'home', sender: 'home',
queue: 'home-prioritized', queue: 'home-prioritized',
name: `watcher-${id}`, name: `watcher-${id}`,

@ -1,26 +0,0 @@
require('../env')
const { getTokensState } = require('../src/utils/tokenState')
const { FOREIGN_ERC_TO_NATIVE_ABI } = require('../../commons')
const { web3Foreign } = require('../src/services/web3')
const emptyLogger = {
debug: () => {},
info: () => {}
}
async function initialChecks() {
const { ORACLE_BRIDGE_MODE, COMMON_FOREIGN_BRIDGE_ADDRESS } = process.env
let result = {}
if (ORACLE_BRIDGE_MODE === 'ERC_TO_NATIVE') {
const bridge = new web3Foreign.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
result = await getTokensState(bridge, emptyLogger)
}
console.log(JSON.stringify(result))
return result
}
const result = initialChecks()
module.exports = result

@ -10,10 +10,8 @@ CONFIG="${2}.config.js"
LOG="${LOGS_DIR}${2}.txt" LOG="${LOGS_DIR}${2}.txt"
TX_HASH=${@:3} TX_HASH=${@:3}
CHECKS=$(node scripts/initialChecks.js)
if [ "${NODE_ENV}" = "production" ]; then if [ "${NODE_ENV}" = "production" ]; then
exec node "${WORKER}" "${CONFIG}" "$CHECKS" $TX_HASH exec node "${WORKER}" "${CONFIG}" $TX_HASH
else else
node "${WORKER}" "${CONFIG}" "$CHECKS" $TX_HASH | tee -a "${LOG}" | pino-pretty node "${WORKER}" "${CONFIG}" $TX_HASH | tee -a "${LOG}" | pino-pretty
fi fi

@ -9,9 +9,9 @@ const { sendTx } = require('./tx/sendTx')
const { checkHTTPS, watchdog, syncForEach, addExtraGas } = require('./utils/utils') const { checkHTTPS, watchdog, syncForEach, addExtraGas } = require('./utils/utils')
const { EXIT_CODES, EXTRA_GAS_PERCENTAGE, MAX_GAS_LIMIT } = require('./utils/constants') const { EXIT_CODES, EXTRA_GAS_PERCENTAGE, MAX_GAS_LIMIT } = require('./utils/constants')
const { ORACLE_VALIDATOR_ADDRESS, ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY, ORACLE_ALLOW_HTTP_FOR_RPC } = process.env const { ORACLE_ALLOW_HTTP_FOR_RPC } = process.env
if (process.argv.length < 5) { if (process.argv.length < 4) {
logger.error('Please check the number of arguments, transaction hash is not present') logger.error('Please check the number of arguments, transaction hash is not present')
process.exit(EXIT_CODES.GENERAL_ERROR) process.exit(EXIT_CODES.GENERAL_ERROR)
} }
@ -29,7 +29,7 @@ function readTxHashes(filePath) {
.filter(isTxHash) .filter(isTxHash)
} }
const txHashesArgs = process.argv.slice(4) const txHashesArgs = process.argv.slice(3)
const rawTxHashes = txHashesArgs.filter(isTxHash) const rawTxHashes = txHashesArgs.filter(isTxHash)
const txHashesFiles = txHashesArgs.filter(path => fs.existsSync(path)).flatMap(readTxHashes) const txHashesFiles = txHashesArgs.filter(path => fs.existsSync(path)).flatMap(readTxHashes)
const txHashes = [...rawTxHashes, ...txHashesFiles] const txHashes = [...rawTxHashes, ...txHashesFiles]
@ -152,7 +152,7 @@ async function sendJobTx(jobs) {
const { web3 } = config.sender === 'foreign' ? config.foreign : config.home const { web3 } = config.sender === 'foreign' ? config.foreign : config.home
const chainId = await getChainId(web3) const chainId = await getChainId(web3)
let nonce = await getNonce(web3, ORACLE_VALIDATOR_ADDRESS) let nonce = await getNonce(web3, config.validatorAddress)
await syncForEach(jobs, async job => { await syncForEach(jobs, async job => {
let gasLimit let gasLimit
@ -170,7 +170,7 @@ async function sendJobTx(jobs) {
gasPrice, gasPrice,
amount: '0', amount: '0',
gasLimit, gasLimit,
privateKey: ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY, privateKey: config.validatorPrivateKey,
to: job.to, to: job.to,
chainId, chainId,
web3 web3
@ -189,7 +189,7 @@ async function sendJobTx(jobs) {
) )
if (e.message.toLowerCase().includes('insufficient funds')) { if (e.message.toLowerCase().includes('insufficient funds')) {
const currentBalance = await web3.eth.getBalance(ORACLE_VALIDATOR_ADDRESS) const currentBalance = await web3.eth.getBalance(config.validatorAddress)
const minimumBalance = gasLimit.multipliedBy(gasPrice) const minimumBalance = gasLimit.multipliedBy(gasPrice)
logger.error( logger.error(
`Insufficient funds: ${currentBalance}. Stop processing messages until the balance is at least ${minimumBalance}.` `Insufficient funds: ${currentBalance}. Stop processing messages until the balance is at least ${minimumBalance}.`

@ -8,8 +8,6 @@ const estimateGas = require('../processSignatureRequests/estimateGas')
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors') const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants') const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
const { ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env
const limit = promiseLimit(MAX_CONCURRENT_EVENTS) const limit = promiseLimit(MAX_CONCURRENT_EVENTS)
function processSignatureRequestsBuilder(config) { function processSignatureRequestsBuilder(config) {
@ -37,7 +35,7 @@ function processSignatureRequestsBuilder(config) {
const { sender, executor } = parseAMBMessage(message) const { sender, executor } = parseAMBMessage(message)
logger.info({ sender, executor }, `Processing signatureRequest ${messageId}`) logger.info({ sender, executor }, `Processing signatureRequest ${messageId}`)
const signature = web3.eth.accounts.sign(message, `0x${ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY}`) const signature = web3.eth.accounts.sign(message, config.validatorPrivateKey)
let gasEstimate let gasEstimate
try { try {

@ -8,8 +8,6 @@ const estimateGas = require('./estimateGas')
const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors') const { AlreadyProcessedError, AlreadySignedError, InvalidValidatorError } = require('../../utils/errors')
const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants') const { EXIT_CODES, MAX_CONCURRENT_EVENTS } = require('../../utils/constants')
const { ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY } = process.env
const limit = promiseLimit(MAX_CONCURRENT_EVENTS) const limit = promiseLimit(MAX_CONCURRENT_EVENTS)
function processSignatureRequestsBuilder(config) { function processSignatureRequestsBuilder(config) {
@ -48,7 +46,7 @@ function processSignatureRequestsBuilder(config) {
expectedMessageLength expectedMessageLength
}) })
const signature = web3.eth.accounts.sign(message, `0x${ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY}`) const signature = web3.eth.accounts.sign(message, config.validatorPrivateKey)
let gasEstimate let gasEstimate
try { try {

@ -10,7 +10,6 @@ const { getNonce, getChainId } = require('./tx/web3')
const { const {
addExtraGas, addExtraGas,
checkHTTPS, checkHTTPS,
privateKeyToAddress,
syncForEach, syncForEach,
waitForFunds, waitForFunds,
waitForUnsuspend, waitForUnsuspend,
@ -19,9 +18,7 @@ const {
} = require('./utils/utils') } = require('./utils/utils')
const { EXIT_CODES, EXTRA_GAS_PERCENTAGE, MAX_GAS_LIMIT } = require('./utils/constants') const { EXIT_CODES, EXTRA_GAS_PERCENTAGE, MAX_GAS_LIMIT } = require('./utils/constants')
const { ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY, ORACLE_TX_REDUNDANCY } = process.env const { ORACLE_TX_REDUNDANCY } = process.env
const ORACLE_VALIDATOR_ADDRESS = privateKeyToAddress(ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY)
if (process.argv.length < 3) { if (process.argv.length < 3) {
logger.error('Please check the number of arguments, config file was not provided') logger.error('Please check the number of arguments, config file was not provided')
@ -84,7 +81,7 @@ async function readNonce(forceUpdate) {
logger.debug('Reading nonce') logger.debug('Reading nonce')
if (forceUpdate) { if (forceUpdate) {
logger.debug('Forcing update of nonce') logger.debug('Forcing update of nonce')
return getNonce(web3, ORACLE_VALIDATOR_ADDRESS) return getNonce(web3, config.validatorAddress)
} }
const nonce = await redis.get(nonceKey) const nonce = await redis.get(nonceKey)
@ -93,7 +90,7 @@ async function readNonce(forceUpdate) {
return Number(nonce) return Number(nonce)
} else { } else {
logger.warn("Nonce wasn't found in the DB") logger.warn("Nonce wasn't found in the DB")
return getNonce(web3, ORACLE_VALIDATOR_ADDRESS) return getNonce(web3, config.validatorAddress)
} }
} }
@ -168,7 +165,7 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
gasPrice, gasPrice,
amount: '0', amount: '0',
gasLimit, gasLimit,
privateKey: ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY, privateKey: config.validatorPrivateKey,
to: job.to, to: job.to,
chainId, chainId,
web3: web3Redundant web3: web3Redundant
@ -208,7 +205,7 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
if (message.includes('insufficient funds')) { if (message.includes('insufficient funds')) {
insufficientFunds = true insufficientFunds = true
const currentBalance = await web3.eth.getBalance(ORACLE_VALIDATOR_ADDRESS) const currentBalance = await web3.eth.getBalance(config.validatorAddress)
minimumBalance = gasLimit.multipliedBy(gasPrice) minimumBalance = gasLimit.multipliedBy(gasPrice)
logger.error( logger.error(
`Insufficient funds: ${currentBalance}. Stop processing messages until the balance is at least ${minimumBalance}.` `Insufficient funds: ${currentBalance}. Stop processing messages until the balance is at least ${minimumBalance}.`
@ -238,7 +235,7 @@ async function main({ msg, ackMsg, nackMsg, channel, scheduleForRetry, scheduleT
if (insufficientFunds) { if (insufficientFunds) {
logger.warn('Insufficient funds. Stop sending transactions until the account has the minimum balance') logger.warn('Insufficient funds. Stop sending transactions until the account has the minimum balance')
channel.close() channel.close()
waitForFunds(web3, ORACLE_VALIDATOR_ADDRESS, minimumBalance, resume, logger) waitForFunds(web3, config.validatorAddress, minimumBalance, resume, logger)
} }
} catch (e) { } catch (e) {
logger.error(e) logger.error(e)

@ -9,12 +9,9 @@ const logger = pino({
enabled: process.env.NODE_ENV !== 'test', enabled: process.env.NODE_ENV !== 'test',
name: config.name, name: config.name,
level: process.env.ORACLE_LOG_LEVEL || 'debug', level: process.env.ORACLE_LOG_LEVEL || 'debug',
base: base: {
process.env.NODE_ENV === 'production' validator: config.validatorAddress
? { }
validator: process.env.ORACLE_VALIDATOR_ADDRESS
}
: {}
}) })
setLogger(logger) setLogger(logger)

@ -11,7 +11,7 @@ async function sendTx({ privateKey, data, nonce, gasPrice, amount, gasLimit, to,
gasPrice, gasPrice,
gas: gasLimit gas: gasLimit
}, },
`0x${privateKey}` privateKey
) )
return new Promise((res, rej) => return new Promise((res, rej) =>

@ -153,6 +153,7 @@ module.exports = {
addExtraGas, addExtraGas,
setIntervalAndRun, setIntervalAndRun,
watchdog, watchdog,
add0xPrefix,
privateKeyToAddress, privateKeyToAddress,
nonceError, nonceError,
getRetrySequence, getRetrySequence,