Skip to content

Commit

Permalink
Merge the develop branch to the master branch, preparation to v1.2.0-rc0
Browse files Browse the repository at this point in the history
  • Loading branch information
akolotov authored Dec 19, 2019
2 parents 303b02f + 1736fd6 commit afb601b
Show file tree
Hide file tree
Showing 28 changed files with 1,294 additions and 171 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ orbs:
- run:
name: Install Chrome
command: |
wget -O chrome.deb https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
wget -O chrome.deb https://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_77.0.3865.120-1_amd64.deb
sudo dpkg -i chrome.deb
install-node:
steps:
Expand Down
4 changes: 3 additions & 1 deletion commons/abis.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const REWARDABLE_VALIDATORS_ABI = require('../contracts/build/contracts/Rewardab
const HOME_AMB_ABI = require('../contracts/build/contracts/HomeAMB').abi
const FOREIGN_AMB_ABI = require('../contracts/build/contracts/ForeignAMB').abi
const BOX_ABI = require('../contracts/build/contracts/Box').abi
const SAI_TOP = require('../contracts/build/contracts/SaiTopMock').abi

const { HOME_V1_ABI, FOREIGN_V1_ABI } = require('./v1Abis')
const { BRIDGE_MODES } = require('./constants')
Expand Down Expand Up @@ -92,5 +93,6 @@ module.exports = {
ERC20_BYTES32_ABI,
HOME_AMB_ABI,
FOREIGN_AMB_ABI,
BOX_ABI
BOX_ABI,
SAI_TOP
}
2 changes: 1 addition & 1 deletion contracts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Slurp docker compose file
slurp:
src: "/home/poadocker/bridge/oracle/{{ item }}.yml"
register: docker_compose_slurp
- name: Parse docker compose file
set_fact:
docker_compose_parsed: "{{ docker_compose_slurp['content'] | b64decode | from_yaml }}"

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

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

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

- name: Write updated docker file
copy:
content: "{{ docker_compose_parsed | to_yaml }}"
dest: "/home/poadocker/bridge/oracle/{{ item }}.yml"
56 changes: 5 additions & 51 deletions deployment-e2e/molecule/ultimate-commons/oracle-docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,12 @@
tasks:
- name: stop the service
shell: service poabridge stop

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

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

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

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

- name: Write new docker-compose file
copy:
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"
- include_tasks: oracle-add-docker-external-network.yml
with_items:
- docker-compose
- docker-compose-transfer
- docker-compose-erc-native

- name: start the service
shell: service poabridge start
42 changes: 5 additions & 37 deletions deployment/roles/oracle/tasks/logging.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@
---
- name: Slurp docker compose file
slurp:
src: "{{ bridge_path }}/oracle/docker-compose.yml"
register: docker_compose_slurp

- name: Parse docker compose file
set_fact:
docker_compose_parsed: "{{ docker_compose_slurp['content'] | b64decode | from_yaml }}"

- name: Set logger to remote server
set_fact:
docker_compose_parsed: "{{ docker_compose_parsed |combine({'services': {item: {'logging': {'driver': 'syslog','options': {'tag': '{{.Name}}/{{.ID}}'}}}}}, recursive=True) }}"
with_items: "{{ docker_compose_parsed.services }}"

- name: Write new docker-compose file
copy:
content: "{{ docker_compose_parsed | to_yaml }}"
dest: "{{ bridge_path }}/oracle/docker-compose.yml"

- name: Slurp docker compose extended file
slurp:
src: "{{ bridge_path }}/oracle/docker-compose-transfer.yml"
register: docker_compose_extended_slurp

- name: Parse docker compose extended file
set_fact:
docker_compose_extended_parsed: "{{ docker_compose_extended_slurp['content'] | b64decode | from_yaml }}"

- name: Set logger to remote server for extended file
set_fact:
docker_compose_extended_parsed: "{{ docker_compose_extended_parsed |combine({'services': {item: {'logging': {'driver': 'syslog','options': {'tag': '{{.Name}}/{{.ID}}'}}}}}, recursive=True) }}"
with_items: "{{ docker_compose_extended_parsed.services }}"

- name: Write new docker-compose-extended file
copy:
content: "{{ docker_compose_extended_parsed | to_yaml }}"
dest: "{{ bridge_path }}/oracle/docker-compose-transfer.yml"
- include_tasks: logging_by_syslog.yml
with_items:
- docker-compose
- docker-compose-transfer
- docker-compose-erc-native

- name: Set the local container logs configuration file
template:
Expand Down
19 changes: 19 additions & 0 deletions deployment/roles/oracle/tasks/logging_by_syslog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Slurp docker compose file
slurp:
src: "{{ bridge_path }}/oracle/{{ item }}.yml"
register: docker_compose_slurp

- name: Parse docker compose file
set_fact:
docker_compose_parsed: "{{ docker_compose_slurp['content'] | b64decode | from_yaml }}"

- name: Set logger to remote server
set_fact:
docker_compose_parsed: "{{ docker_compose_parsed |combine({'services': {item: {'logging': {'driver': 'syslog','options': {'tag': '{{.Name}}/{{.ID}}'}}}}}, recursive=True) }}"
with_items: "{{ docker_compose_parsed.services }}"

- name: Write updated docker file
copy:
content: "{{ docker_compose_parsed | to_yaml }}"
dest: "{{ bridge_path }}/oracle/{{ item }}.yml"
6 changes: 5 additions & 1 deletion deployment/roles/oracle/tasks/post_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@

- 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")
when: ORACLE_BRIDGE_MODE == "ERC_TO_ERC" and FOREIGN_ERC_TYPE != "ERC677"

- name: Extend docker compose file for erc to native
set_fact: composefileoverride="-f docker-compose-erc-native.yml"
when: ORACLE_BRIDGE_MODE == "ERC_TO_NATIVE"

- name: Install .key config
template:
Expand Down
4 changes: 3 additions & 1 deletion e2e-commons/constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"ercToNativeBridge": {
"home": "0x488Af810997eD1730cB3a3918cD83b3216E6eAda",
"foreign": "0x488Af810997eD1730cB3a3918cD83b3216E6eAda",
"foreignToken": "0x3C665A31199694Bf723fD08844AD290207B5797f",
"foreignToken": "0x7cc4b1851c35959d34e635a470f6b5c43ba3c9c9",
"halfDuplexToken": "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359",
"saiTop": "0x9b0ccf7C8994E19F39b2B4CF708e0A7DF65fA8a3",
"ui": "http://localhost:3002",
"monitor": "http://monitor-erc20-native:3012"
},
Expand Down
2 changes: 1 addition & 1 deletion e2e-commons/contracts-envs/erc-to-native.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ FOREIGN_GAS_PRICE=10000000000
FOREIGN_REWARDABLE=false

BLOCK_REWARD_ADDRESS=0xF9698Eb93702dfdd0e2d802088d4c21822a8A977
ERC20_TOKEN_ADDRESS=0x3C665A31199694Bf723fD08844AD290207B5797f
ERC20_TOKEN_ADDRESS=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359

REQUIRED_NUMBER_OF_VALIDATORS=1
VALIDATORS="0xaaB52d66283F7A1D5978bcFcB55721ACB467384b"
Expand Down
2 changes: 2 additions & 0 deletions e2e-commons/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ while [ "$1" != "" ]; do
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-erc20-native yarn watcher:half-duplex-transfer
docker-compose run -d oracle-erc20-native yarn worker:swap-tokens
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
2 changes: 1 addition & 1 deletion monitor-e2e/test/ercToNative.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ERC TO NATIVE with changing state of contracts', () => {
})

it('should change balanceDiff', async () => {
await sendTokens(foreignRPC.URL, user, ercToNativeBridge.foreignToken, ercToNativeBridge.foreign)
await sendTokens(foreignRPC.URL, user, ercToNativeBridge.halfDuplexToken, ercToNativeBridge.foreign)

await waitUntil(async () => {
;({ data } = await axios.get(`${baseUrl}`))
Expand Down
50 changes: 45 additions & 5 deletions monitor/getBalances.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ async function main(bridgeMode) {
const foreignBridge = new web3Foreign.eth.Contract(FOREIGN_ERC_TO_NATIVE_ABI, COMMON_FOREIGN_BRIDGE_ADDRESS)
const erc20Address = await foreignBridge.methods.erc20token().call()
const erc20Contract = new web3Foreign.eth.Contract(ERC20_ABI, erc20Address)
let foreignHalfDuplexErc20Balance = 0
let displayHalfDuplexToken = false
let tokenSwapAllowed = false
try {
const halfDuplexTokenAddress = await foreignBridge.methods.halfDuplexErc20token().call()
if (halfDuplexTokenAddress !== erc20Address) {
const halfDuplexToken = new web3Foreign.eth.Contract(ERC20_ABI, halfDuplexTokenAddress)
logger.debug('calling halfDuplexToken.methods.balanceOf')
foreignHalfDuplexErc20Balance = await halfDuplexToken.methods.balanceOf(COMMON_FOREIGN_BRIDGE_ADDRESS).call()
logger.debug('getting last block numbers')
const block = await web3Foreign.eth.getBlock('latest')

logger.debug(`Checking if SCD Emergency Shutdown has happened`)
tokenSwapAllowed = await foreignBridge.methods.isTokenSwapAllowed(block.timestamp).call()
displayHalfDuplexToken = true
}
} catch (e) {
logger.debug('Methods for half duplex token are not present')
}

logger.debug('calling erc20Contract.methods.balanceOf')
const foreignErc20Balance = await erc20Contract.methods.balanceOf(COMMON_FOREIGN_BRIDGE_ADDRESS).call()

Expand All @@ -91,24 +111,44 @@ async function main(bridgeMode) {
const blockRewardAddress = await homeBridge.methods.blockRewardContract().call()
const blockRewardContract = new web3Home.eth.Contract(BLOCK_REWARD_ABI, blockRewardAddress)
logger.debug('calling blockReward.methods.mintedTotally')
const mintedCoins = await blockRewardContract.methods.mintedTotally().call()
const mintedCoins = await blockRewardContract.methods.mintedTotallyByBridge(COMMON_HOME_BRIDGE_ADDRESS).call()
logger.debug('calling homeBridge.methods.totalBurntCoins')
const burntCoins = await homeBridge.methods.totalBurntCoins().call()

const mintedCoinsBN = new BN(mintedCoins)
const burntCoinsBN = new BN(burntCoins)
const totalSupplyBN = mintedCoinsBN.minus(burntCoinsBN)
const foreignErc20BalanceBN = new BN(foreignErc20Balance)
const halfDuplexErc20BalanceBN =
displayHalfDuplexToken && tokenSwapAllowed ? new BN(foreignHalfDuplexErc20Balance) : new BN(0)

const diff = foreignErc20BalanceBN
.plus(halfDuplexErc20BalanceBN)
.minus(totalSupplyBN)
.toFixed()

let foreign = {
erc20Balance: Web3Utils.fromWei(foreignErc20Balance)
}

if (displayHalfDuplexToken && tokenSwapAllowed) {
foreign = {
...foreign,
halfDuplexErc20Balance: Web3Utils.fromWei(foreignHalfDuplexErc20Balance)
}
} else if (displayHalfDuplexToken && !tokenSwapAllowed) {
foreign = {
...foreign,
halfDuplexErc20BalanceAfterES: Web3Utils.fromWei(foreignHalfDuplexErc20Balance)
}
}

const diff = foreignErc20BalanceBN.minus(totalSupplyBN).toFixed()
logger.debug('Done')
return {
home: {
totalSupply: Web3Utils.fromWei(totalSupplyBN.toFixed())
},
foreign: {
erc20Balance: Web3Utils.fromWei(foreignErc20Balance)
},
foreign,
balanceDiff: Number(Web3Utils.fromWei(diff)),
lastChecked: Math.floor(Date.now() / 1000)
}
Expand Down
18 changes: 14 additions & 4 deletions monitor/utils/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const {
ZERO_ADDRESS
} = require('../../commons')
const { normalizeEventInformation } = require('./message')
const { filterTransferBeforeES } = require('./tokenUtils')

const {
COMMON_HOME_RPC_URL,
Expand Down Expand Up @@ -42,10 +43,11 @@ async function main(mode) {
const v1Bridge = bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC_V1
let isExternalErc20
let erc20Contract
let erc20Address
let normalizeEvent = normalizeEventInformation
if (bridgeMode !== BRIDGE_MODES.ARBITRARY_MESSAGE) {
const erc20MethodName = bridgeMode === BRIDGE_MODES.NATIVE_TO_ERC || v1Bridge ? 'erc677token' : 'erc20token'
const erc20Address = await foreignBridge.methods[erc20MethodName]().call()
erc20Address = await foreignBridge.methods[erc20MethodName]().call()
const tokenType = await getTokenType(
new web3Foreign.eth.Contract(ERC677_BRIDGE_TOKEN_ABI, erc20Address),
COMMON_FOREIGN_BRIDGE_ADDRESS
Expand Down Expand Up @@ -113,17 +115,25 @@ async function main(mode) {
const uniqueTokenAddresses = [...new Set(bridgeTokensSwappedEvents.map(e => e.returnValues.from))]
await Promise.all(
uniqueTokenAddresses.map(async tokenAddress => {
const previousERC20 = new web3Foreign.eth.Contract(ERC20_ABI, tokenAddress)
const halfDuplexTokenContract = new web3Foreign.eth.Contract(ERC20_ABI, tokenAddress)

const previousTransferEvents = (await getPastEvents(previousERC20, {
const halfDuplexTransferEvents = (await getPastEvents(halfDuplexTokenContract, {
event: 'Transfer',
fromBlock: MONITOR_FOREIGN_START_BLOCK,
toBlock: foreignBlockNumber,
options: {
filter: { to: COMMON_FOREIGN_BRIDGE_ADDRESS }
}
})).map(normalizeEvent)
transferEvents = [...previousTransferEvents, ...transferEvents]

// Remove events after the ES
const validHalfDuplexTransfers = await filterTransferBeforeES(
halfDuplexTransferEvents,
web3Foreign,
foreignBridge
)

transferEvents = [...validHalfDuplexTransfers, ...transferEvents]
})
)

Expand Down
Loading

0 comments on commit afb601b

Please sign in to comment.