Skip to content

Commit

Permalink
Merge pull request #24 from k1rill-fedoseev/master
Browse files Browse the repository at this point in the history
  • Loading branch information
akolotov committed Nov 27, 2019
2 parents f972fb6 + 00b1390 commit 3d8623e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 23 deletions.
12 changes: 10 additions & 2 deletions src/deploy/deploy-home/contracts/BasicBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,19 @@ contract BasicBridge {
}

function getX() view public returns (uint) {
return states[epoch].x;
return getX(epoch);
}

function getX(uint16 _epoch) view public returns (uint) {
return states[_epoch].x;
}

function getY() view public returns (uint) {
return states[epoch].y;
return getY(epoch);
}

function getY(uint16 _epoch) view public returns (uint) {
return states[_epoch].y;
}

function getCloseEpoch() view public returns (bool) {
Expand Down
13 changes: 8 additions & 5 deletions src/ethereum-testnet/side-oracle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ async function initialize() {
sideProvider = new ethers.providers.JsonRpcProvider(SIDE_RPC_URL)
homeProvider = new ethers.providers.JsonRpcProvider(HOME_RPC_URL)

homeWallet = new ethers.Wallet(HOME_PRIVATE_KEY, homeProvider)
bridge = new ethers.Contract(HOME_BRIDGE_ADDRESS, bridgeAbi, homeWallet)
sharedDb = new ethers.Contract(SIDE_SHARED_DB_ADDRESS, sharedDbAbi, sideProvider)

nonce = await homeWallet.getTransactionCount()
await sideProvider.getNetwork()
await homeProvider.getNetwork()
break
} catch (e) {
console.log('Cannot create providers')
await delay(1000)
}
}

homeWallet = new ethers.Wallet(HOME_PRIVATE_KEY, homeProvider)
bridge = new ethers.Contract(HOME_BRIDGE_ADDRESS, bridgeAbi, homeWallet)
sharedDb = new ethers.Contract(SIDE_SHARED_DB_ADDRESS, sharedDbAbi, sideProvider)

nonce = await homeWallet.getTransactionCount()
}

async function loop() {
Expand Down
43 changes: 35 additions & 8 deletions src/oracle/ethWatcher/ethWatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const bridgeAbi = [
'event EpochStart(uint16 indexed epoch, uint256 x, uint256 y)',
'event EpochClose(uint16 indexed epoch)',
'event ForceSign()',
'function getX(uint16 epoch) view returns (uint256)',
'function getY(uint16 epoch) view returns (uint256)',
'function getThreshold(uint16 epoch) view returns (uint16)',
'function getParties(uint16 epoch) view returns (uint16)',
'function getRangeSize(uint16 epoch) view returns (uint16)',
Expand Down Expand Up @@ -92,11 +94,15 @@ async function resetFutureMessages(queue) {

async function sendKeygen(event) {
const { newEpoch } = event.values
const [threshold, parties] = await Promise.all([
bridge.getThreshold(newEpoch),
bridge.getParties(newEpoch)
])
keygenQueue.send({
epoch: newEpoch,
blockNumber,
threshold: await bridge.getThreshold(newEpoch),
parties: await bridge.getParties(newEpoch)
threshold,
parties
})
logger.debug('Sent keygen start event')
}
Expand All @@ -112,13 +118,26 @@ function sendKeygenCancellation(event) {

async function sendSignFundsTransfer(event) {
const { newEpoch, oldEpoch } = event.values
const [
x, y, threshold, parties
] = await Promise.all([
bridge.getX(newEpoch).then((value) => new BN(value).toString(16)),
bridge.getY(newEpoch).then((value) => new BN(value).toString(16)),
bridge.getThreshold(oldEpoch),
bridge.getParties(oldEpoch)
])
const recipient = publicKeyToAddress({
x,
y
})
signQueue.send({
epoch: oldEpoch,
blockNumber,
newEpoch,
nonce: foreignNonce[oldEpoch],
threshold: await bridge.getThreshold(oldEpoch),
parties: await bridge.getParties(oldEpoch)
recipient,
threshold,
parties
})
logger.debug('Sent sign funds transfer event')
foreignNonce[oldEpoch] += 1
Expand Down Expand Up @@ -161,12 +180,16 @@ async function sendSign(event, transactionHash) {
}

async function sendStartSign() {
const [threshold, parties] = await Promise.all([
bridge.getThreshold(epoch),
bridge.getParties(epoch)
])
signQueue.send({
epoch,
blockNumber,
nonce: foreignNonce[epoch],
threshold: await bridge.getThreshold(epoch),
parties: await bridge.getParties(epoch)
threshold,
parties
})
foreignNonce[epoch] += 1
redisTx.incr(`foreignNonce${epoch}`)
Expand All @@ -189,12 +212,16 @@ async function processEpochStart(event) {

async function sendEpochClose() {
logger.debug(`Consumed epoch ${epoch} close event`)
const [threshold, parties] = await Promise.all([
bridge.getThreshold(epoch),
bridge.getParties(epoch)
])
signQueue.send({
closeEpoch: epoch,
blockNumber,
nonce: foreignNonce[epoch],
threshold: await bridge.getThreshold(epoch),
parties: await bridge.getParties(epoch)
threshold,
parties
})
foreignNonce[epoch] += 1
redisTx.incr(`foreignNonce${epoch}`)
Expand Down
11 changes: 3 additions & 8 deletions src/oracle/tss-sign/signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ function getAccountBalance(account, asset) {
}

async function buildTx(from, account, data) {
const { closeEpoch, newEpoch, nonce } = data
const {
closeEpoch, newEpoch, nonce, recipient: to
} = data

const txOptions = {
from,
Expand All @@ -237,13 +239,6 @@ async function buildTx(from, account, data) {

txOptions.flags = 0x01
} else if (newEpoch) {
const newKeysFile = `/keys/keys${newEpoch}.store`
const to = getAccountFromFile(newKeysFile).address

if (to === '') {
return { tx: null }
}

logger.info(`Building corresponding transaction for transferring all funds, nonce ${nonce}, recipient ${to}`)
const fee = await getFee()

Expand Down

0 comments on commit 3d8623e

Please sign in to comment.