diff --git a/src/deploy/deploy-home/contracts/BasicBridge.sol b/src/deploy/deploy-home/contracts/BasicBridge.sol index 86a2e08..3589447 100644 --- a/src/deploy/deploy-home/contracts/BasicBridge.sol +++ b/src/deploy/deploy-home/contracts/BasicBridge.sol @@ -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) { diff --git a/src/ethereum-testnet/side-oracle/index.js b/src/ethereum-testnet/side-oracle/index.js index d90ecfc..64d075b 100644 --- a/src/ethereum-testnet/side-oracle/index.js +++ b/src/ethereum-testnet/side-oracle/index.js @@ -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() { diff --git a/src/oracle/ethWatcher/ethWatcher.js b/src/oracle/ethWatcher/ethWatcher.js index e26d430..82e7632 100644 --- a/src/oracle/ethWatcher/ethWatcher.js +++ b/src/oracle/ethWatcher/ethWatcher.js @@ -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)', @@ -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') } @@ -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 @@ -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}`) @@ -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}`) diff --git a/src/oracle/tss-sign/signer.js b/src/oracle/tss-sign/signer.js index b7e0d14..514b7ba 100644 --- a/src/oracle/tss-sign/signer.js +++ b/src/oracle/tss-sign/signer.js @@ -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, @@ -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()