Skip to content

Commit

Permalink
Merge the develop branch to the master branch, preparation to v1.0.0 #…
Browse files Browse the repository at this point in the history
…230

* Support alternative receiver in Oracle (#221)
* Support alternative receiver feature in Monitor (#223)
* Support token migration (#224)
* Fix suggested gas price in transaction for ui production build (#222)
* Updated links to new repo with tokenbridge contracts (#226)
* Update the contract's submodule to the release 3.2.0 (#228)
  • Loading branch information
akolotov authored Nov 12, 2019
2 parents 9884b4b + 4fd4ac3 commit db89d1c
Show file tree
Hide file tree
Showing 31 changed files with 1,169 additions and 1,637 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "contracts"]
path = contracts
url = https://github.com/poanetwork/poa-bridge-contracts.git
url = https://github.com/poanetwork/tokenbridge-contracts.git
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Sub-repositories maintained within this monorepo are listed below.
| [Commons](commons/README.md) | Interfaces, constants and utilities shared between the sub-repositories |
| [E2E-Commons](e2e-commons/README.md) | Common utilities and configuration used in end to end tests |

Additionally there are [Smart Contracts](https://github.com/poanetwork/poa-bridge-contracts) used to manage bridge validators, collect signatures, and confirm asset relay and disposal.
Additionally there are [Smart Contracts](https://github.com/poanetwork/tokenbridge-contracts) used to manage bridge validators, collect signatures, and confirm asset relay and disposal.

## Available deployments

Expand Down
5 changes: 4 additions & 1 deletion commons/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ const FEE_MANAGER_MODE = {
UNDEFINED: 'UNDEFINED'
}

const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000'

module.exports = {
BRIDGE_MODES,
ERC_TYPES,
FEE_MANAGER_MODE
FEE_MANAGER_MODE,
ZERO_ADDRESS
}
2 changes: 1 addition & 1 deletion contracts
26 changes: 26 additions & 0 deletions deployment-e2e/molecule/ultimate-commons/oracle-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,31 @@
content: "{{ docker_compose_parsed | to_yaml }}"
dest: "/home/poadocker/bridge/oracle/docker-compose.yml"

- name: Slurp docker compose extended file
slurp:
src: "/home/poadocker/bridge/oracle/docker-compose-transfer.yml"
register: docker_compose_extended_slurp
- name: Parse docker compose file
set_fact:
docker_compose_extended_parsed: "{{ docker_compose_extended_slurp['content'] | b64decode | from_yaml }}"

- name: Add the external network used to connect to Parity nodes in compose extended file
set_fact:
docker_compose_extended_parsed: "{{ docker_compose_extended_parsed |combine({'networks': {'ultimate': {'external': 'true'}}}, recursive=True) }}"

- name: Add all Oracle containers to the network in compose extended file
set_fact:
docker_compose_extended_parsed: "{{ docker_compose_extended_parsed | combine({'services': {item: {'networks': docker_compose_extended_parsed.services[item].networks | union(['ultimate'])}}}, recursive=True) }}"
with_items: "{{ docker_compose_extended_parsed.services }}"

- name: Expose Redis port to allow connecting from redis-cli in compose extended file
set_fact:
docker_compose_extended_parsed: "{{ docker_compose_extended_parsed | combine({'services': {'redis': {'ports': ['6379:6379']}}}, recursive=True) }}"

- name: Write new docker-compose extended file
copy:
content: "{{ docker_compose_extended_parsed | to_yaml }}"
dest: "/home/poadocker/bridge/oracle/docker-compose-transfer.yml"

- name: start the service
shell: service poabridge start
15 changes: 15 additions & 0 deletions deployment/roles/oracle/tasks/post_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
set_fact:
ORACLE_VALIDATOR_ADDRESS: "{{ VADDRESS.stdout }}"

- name: Get foreign erc type
become_user: "{{ compose_service_user }}"
shell: docker-compose run --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
set_fact: composefileoverride="-f docker-compose-transfer.yml"
when: ORACLE_BRIDGE_MODE == "ERC_TO_NATIVE" or ( ORACLE_BRIDGE_MODE == "ERC_TO_ERC" and FOREIGN_ERC_TYPE != "ERC677")

- name: Install .key config
template:
src: key.j2
Expand Down
17 changes: 9 additions & 8 deletions deployment/roles/oracle/templates/poabridge.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ WORKDIR="{{ '/home/' + compose_service_user | default('poadocker') + '/' + bridg
keyfile="{{ keyfile_path }}"
vaddr="ORACLE_VALIDATOR_ADDRESS="
vkey="ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY="
composefileoverride="{{ composefileoverride | default('') }}"

#Parsing file content and add key to variable
while read -r line
Expand All @@ -33,30 +34,30 @@ done < $keyfile
start(){
echo "Starting bridge.."
cd $WORKDIR
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose down -v
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose rm -fv
sudo -u "{{ compose_service_user }}" ORACLE_VALIDATOR_ADDRESS=$vaddr ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=$vkey /usr/local/bin/docker-compose up --detach
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose $composefileoverride down -v
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose $composefileoverride rm -fv
sudo -u "{{ compose_service_user }}" ORACLE_VALIDATOR_ADDRESS=$vaddr ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=$vkey /usr/local/bin/docker-compose $composefileoverride up --detach
}

stop(){
echo "Stopping bridge.."
cd $WORKDIR
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose down -v
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose $composefileoverride down -v
sleep 2
}

status(){
echo "Bridge status:"
cd $WORKDIR
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose ps
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose $composefileoverride ps
}

rebuild(){
echo "Rebuild bridge.."
cd $WORKDIR
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose down -v
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose rm -fv
sudo -u "{{ compose_service_user }}" ORACLE_VALIDATOR_ADDRESS=$vaddr ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=$vkey /usr/local/bin/docker-compose up --detach --force-recreate --no-deps --build
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose $composefileoverride down -v
sudo -u "{{ compose_service_user }}" /usr/local/bin/docker-compose $composefileoverride rm -fv
sudo -u "{{ compose_service_user }}" ORACLE_VALIDATOR_ADDRESS=$vaddr ORACLE_VALIDATOR_ADDRESS_PRIVATE_KEY=$vkey /usr/local/bin/docker-compose $composefileoverride up --detach --force-recreate --no-deps --build
}


Expand Down
2 changes: 2 additions & 0 deletions e2e-commons/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ while [ "$1" != "" ]; do
docker-compose run -d oracle-erc20 yarn watcher:signature-request
docker-compose run -d oracle-erc20 yarn watcher:collected-signatures
docker-compose run -d oracle-erc20 yarn watcher:affirmation-request
docker-compose run -d oracle-erc20 yarn watcher:transfer
docker-compose run -d oracle-erc20-native yarn watcher:signature-request
docker-compose run -d oracle-erc20-native yarn watcher:collected-signatures
docker-compose run -d oracle-erc20-native yarn watcher:affirmation-request
docker-compose run -d oracle-erc20-native yarn watcher:transfer
docker-compose run -d oracle-amb yarn watcher:signature-request
docker-compose run -d oracle-amb yarn watcher:collected-signatures
docker-compose run -d oracle-amb yarn watcher:affirmation-request
Expand Down
3 changes: 3 additions & 0 deletions monitor/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"rules": {
"no-use-before-define": "off",
"node/no-unpublished-require": "off"
},
"env": {
"mocha": true
}
}
47 changes: 6 additions & 41 deletions monitor/alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Web3 = require('web3')
const logger = require('./logger')('alerts')
const eventsInfo = require('./utils/events')
const { getBlockNumber } = require('./utils/contract')
const { processedMsgNotDelivered } = require('./utils/message')
const { processedMsgNotDelivered, eventWithoutReference } = require('./utils/message')
const { BRIDGE_MODES } = require('../commons')

const { COMMON_HOME_RPC_URL, COMMON_FOREIGN_RPC_URL } = process.env
Expand All @@ -29,10 +29,9 @@ async function main() {
xSignatures = homeToForeignConfirmations.filter(processedMsgNotDelivered(homeToForeignRequests))
xAffirmations = foreignToHomeConfirmations.filter(processedMsgNotDelivered(foreignToHomeRequests))
} else {
xSignatures = homeToForeignConfirmations.filter(findDifferences(homeToForeignRequests))
xAffirmations = foreignToHomeConfirmations.filter(findDifferences(foreignToHomeRequests))
xSignatures = homeToForeignConfirmations.filter(eventWithoutReference(homeToForeignRequests))
xAffirmations = foreignToHomeConfirmations.filter(eventWithoutReference(foreignToHomeRequests))
}

logger.debug('building misbehavior blocks')
const [homeBlockNumber, foreignBlockNumber] = await getBlockNumber(web3Home, web3Foreign)

Expand All @@ -52,8 +51,8 @@ async function main() {
const foreignValidators = await Promise.all(xSignatures.map(event => findTxSender(web3Foreign)(event)))
const homeValidators = await Promise.all(xAffirmations.map(event => findTxSender(web3Home)(event)))

const xSignaturesTxs = xSignatures.map(normalizeEventInformation).reduce(buildTxList(foreignValidators), {})
const xAffirmationsTxs = xAffirmations.map(normalizeEventInformation).reduce(buildTxList(homeValidators), {})
const xSignaturesTxs = xSignatures.reduce(buildTxList(foreignValidators), {})
const xAffirmationsTxs = xAffirmations.reduce(buildTxList(homeValidators), {})

logger.debug('Done')

Expand Down Expand Up @@ -150,7 +149,7 @@ const findTxSender = web3 => async ({ transactionHash }) => {
* }}}
*/
const buildTxList = validatorsList => (acc, event, index) => {
acc[event.txHash] = {
acc[event.transactionHash] = {
value: event.value,
block: event.blockNumber,
referenceTx: event.referenceTx,
Expand All @@ -160,38 +159,4 @@ const buildTxList = validatorsList => (acc, event, index) => {
return acc
}

/**
* Finds a missing destDeposit in src list if there's any
* @param {Array} src
* @returns {function(*=): boolean}
*/
const findDifferences = src => dest => {
const b = normalizeEventInformation(dest)

return (
src
.map(normalizeEventInformation)
.filter(a => a.referenceTx === b.referenceTx && a.recipient === b.recipient && a.value === b.value).length === 0
)
}

/**
* Normalizes the different event objects to facilitate data processing
* @param {Object} event
* @returns {{
* txHash: string,
* blockNumber: number,
* referenceTx: string,
* recipient: string | *,
* value: *
* }}
*/
const normalizeEventInformation = event => ({
txHash: event.transactionHash,
blockNumber: event.blockNumber,
referenceTx: event.returnValues.transactionHash || event.transactionHash,
recipient: event.returnValues.recipient || event.returnValues.from,
value: event.returnValues.value
})

module.exports = main
71 changes: 5 additions & 66 deletions monitor/eventsStats.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,14 @@
require('dotenv').config()
const eventsInfo = require('./utils/events')
const { processedMsgNotDelivered, deliveredMsgNotProcessed } = require('./utils/message')
const { processedMsgNotDelivered, deliveredMsgNotProcessed, eventWithoutReference } = require('./utils/message')
const { BRIDGE_MODES } = require('../commons')

function compareDepositsHome(foreign) {
return homeDeposit => {
return (
foreign.filter(foreignDeposit => {
return (
foreignDeposit.returnValues.transactionHash === homeDeposit.transactionHash &&
foreignDeposit.returnValues.recipient === homeDeposit.returnValues.recipient &&
foreignDeposit.returnValues.value === homeDeposit.returnValues.value
)
}).length === 0
)
}
}
function compareDepositsForeign(home) {
return foreignDeposit => {
return (
home.filter(homeDeposit => {
return (
homeDeposit.transactionHash === foreignDeposit.returnValues.transactionHash &&
homeDeposit.returnValues.recipient === foreignDeposit.returnValues.recipient &&
homeDeposit.returnValues.value === foreignDeposit.returnValues.value
)
}).length === 0
)
}
}

function compareTransferHome(foreign) {
return homeDeposit => {
return (
foreign.filter(foreignDeposit => {
return (
homeDeposit.returnValues.transactionHash === foreignDeposit.transactionHash &&
homeDeposit.returnValues.recipient === foreignDeposit.returnValues.from &&
homeDeposit.returnValues.value === foreignDeposit.returnValues.value
)
}).length === 0
)
}
}
function compareTransferForeign(home) {
return foreignDeposit => {
return (
home.filter(homeDeposit => {
return (
foreignDeposit.transactionHash === homeDeposit.returnValues.transactionHash &&
foreignDeposit.returnValues.from === homeDeposit.returnValues.recipient &&
foreignDeposit.returnValues.value === homeDeposit.returnValues.value
)
}).length === 0
)
}
}

async function main() {
const {
homeToForeignRequests,
homeToForeignConfirmations,
foreignToHomeConfirmations,
foreignToHomeRequests,
isExternalErc20,
bridgeMode
} = await eventsInfo()

Expand All @@ -88,17 +33,11 @@ async function main() {
lastChecked: Math.floor(Date.now() / 1000)
}
} else {
const onlyInHomeDeposits = homeToForeignRequests.filter(compareDepositsHome(homeToForeignConfirmations))
const onlyInForeignDeposits = homeToForeignConfirmations
.concat([])
.filter(compareDepositsForeign(homeToForeignRequests))
const onlyInHomeDeposits = homeToForeignRequests.filter(eventWithoutReference(homeToForeignConfirmations))
const onlyInForeignDeposits = homeToForeignConfirmations.filter(eventWithoutReference(homeToForeignRequests))

const onlyInHomeWithdrawals = isExternalErc20
? foreignToHomeConfirmations.filter(compareTransferHome(foreignToHomeRequests))
: foreignToHomeConfirmations.filter(compareDepositsForeign(foreignToHomeRequests))
const onlyInForeignWithdrawals = isExternalErc20
? foreignToHomeRequests.filter(compareTransferForeign(foreignToHomeConfirmations))
: foreignToHomeRequests.filter(compareDepositsHome(foreignToHomeConfirmations))
const onlyInHomeWithdrawals = foreignToHomeConfirmations.filter(eventWithoutReference(foreignToHomeRequests))
const onlyInForeignWithdrawals = foreignToHomeRequests.filter(eventWithoutReference(foreignToHomeConfirmations))

return {
onlyInHomeDeposits,
Expand Down
4 changes: 3 additions & 1 deletion monitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start": "node index.js",
"check-and-start": "yarn check-all && yarn start",
"lint": "eslint . --ignore-path ../.eslintignore",
"lint:fix": "eslint . --fix"
"lint:fix": "eslint . --fix",
"test": "NODE_ENV=test mocha"
},
"author": "",
"license": "ISC",
Expand All @@ -23,5 +24,6 @@
"node": ">=8.9"
},
"devDependencies": {
"chai": "^4.2.0"
}
}
Loading

0 comments on commit db89d1c

Please sign in to comment.