Merge pull request #24 from k1rill-fedoseev/master
This commit is contained in:
commit
3d8623e05d
|
@ -123,11 +123,19 @@ contract BasicBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getX() view public returns (uint) {
|
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) {
|
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) {
|
function getCloseEpoch() view public returns (bool) {
|
||||||
|
|
|
@ -63,17 +63,20 @@ async function initialize() {
|
||||||
sideProvider = new ethers.providers.JsonRpcProvider(SIDE_RPC_URL)
|
sideProvider = new ethers.providers.JsonRpcProvider(SIDE_RPC_URL)
|
||||||
homeProvider = new ethers.providers.JsonRpcProvider(HOME_RPC_URL)
|
homeProvider = new ethers.providers.JsonRpcProvider(HOME_RPC_URL)
|
||||||
|
|
||||||
homeWallet = new ethers.Wallet(HOME_PRIVATE_KEY, homeProvider)
|
await sideProvider.getNetwork()
|
||||||
bridge = new ethers.Contract(HOME_BRIDGE_ADDRESS, bridgeAbi, homeWallet)
|
await homeProvider.getNetwork()
|
||||||
sharedDb = new ethers.Contract(SIDE_SHARED_DB_ADDRESS, sharedDbAbi, sideProvider)
|
|
||||||
|
|
||||||
nonce = await homeWallet.getTransactionCount()
|
|
||||||
break
|
break
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Cannot create providers')
|
console.log('Cannot create providers')
|
||||||
await delay(1000)
|
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() {
|
async function loop() {
|
||||||
|
|
|
@ -23,6 +23,8 @@ const bridgeAbi = [
|
||||||
'event EpochStart(uint16 indexed epoch, uint256 x, uint256 y)',
|
'event EpochStart(uint16 indexed epoch, uint256 x, uint256 y)',
|
||||||
'event EpochClose(uint16 indexed epoch)',
|
'event EpochClose(uint16 indexed epoch)',
|
||||||
'event ForceSign()',
|
'event ForceSign()',
|
||||||
|
'function getX(uint16 epoch) view returns (uint256)',
|
||||||
|
'function getY(uint16 epoch) view returns (uint256)',
|
||||||
'function getThreshold(uint16 epoch) view returns (uint16)',
|
'function getThreshold(uint16 epoch) view returns (uint16)',
|
||||||
'function getParties(uint16 epoch) view returns (uint16)',
|
'function getParties(uint16 epoch) view returns (uint16)',
|
||||||
'function getRangeSize(uint16 epoch) view returns (uint16)',
|
'function getRangeSize(uint16 epoch) view returns (uint16)',
|
||||||
|
@ -92,11 +94,15 @@ async function resetFutureMessages(queue) {
|
||||||
|
|
||||||
async function sendKeygen(event) {
|
async function sendKeygen(event) {
|
||||||
const { newEpoch } = event.values
|
const { newEpoch } = event.values
|
||||||
|
const [threshold, parties] = await Promise.all([
|
||||||
|
bridge.getThreshold(newEpoch),
|
||||||
|
bridge.getParties(newEpoch)
|
||||||
|
])
|
||||||
keygenQueue.send({
|
keygenQueue.send({
|
||||||
epoch: newEpoch,
|
epoch: newEpoch,
|
||||||
blockNumber,
|
blockNumber,
|
||||||
threshold: await bridge.getThreshold(newEpoch),
|
threshold,
|
||||||
parties: await bridge.getParties(newEpoch)
|
parties
|
||||||
})
|
})
|
||||||
logger.debug('Sent keygen start event')
|
logger.debug('Sent keygen start event')
|
||||||
}
|
}
|
||||||
|
@ -112,13 +118,26 @@ function sendKeygenCancellation(event) {
|
||||||
|
|
||||||
async function sendSignFundsTransfer(event) {
|
async function sendSignFundsTransfer(event) {
|
||||||
const { newEpoch, oldEpoch } = event.values
|
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({
|
signQueue.send({
|
||||||
epoch: oldEpoch,
|
epoch: oldEpoch,
|
||||||
blockNumber,
|
blockNumber,
|
||||||
newEpoch,
|
newEpoch,
|
||||||
nonce: foreignNonce[oldEpoch],
|
nonce: foreignNonce[oldEpoch],
|
||||||
threshold: await bridge.getThreshold(oldEpoch),
|
recipient,
|
||||||
parties: await bridge.getParties(oldEpoch)
|
threshold,
|
||||||
|
parties
|
||||||
})
|
})
|
||||||
logger.debug('Sent sign funds transfer event')
|
logger.debug('Sent sign funds transfer event')
|
||||||
foreignNonce[oldEpoch] += 1
|
foreignNonce[oldEpoch] += 1
|
||||||
|
@ -161,12 +180,16 @@ async function sendSign(event, transactionHash) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function sendStartSign() {
|
async function sendStartSign() {
|
||||||
|
const [threshold, parties] = await Promise.all([
|
||||||
|
bridge.getThreshold(epoch),
|
||||||
|
bridge.getParties(epoch)
|
||||||
|
])
|
||||||
signQueue.send({
|
signQueue.send({
|
||||||
epoch,
|
epoch,
|
||||||
blockNumber,
|
blockNumber,
|
||||||
nonce: foreignNonce[epoch],
|
nonce: foreignNonce[epoch],
|
||||||
threshold: await bridge.getThreshold(epoch),
|
threshold,
|
||||||
parties: await bridge.getParties(epoch)
|
parties
|
||||||
})
|
})
|
||||||
foreignNonce[epoch] += 1
|
foreignNonce[epoch] += 1
|
||||||
redisTx.incr(`foreignNonce${epoch}`)
|
redisTx.incr(`foreignNonce${epoch}`)
|
||||||
|
@ -189,12 +212,16 @@ async function processEpochStart(event) {
|
||||||
|
|
||||||
async function sendEpochClose() {
|
async function sendEpochClose() {
|
||||||
logger.debug(`Consumed epoch ${epoch} close event`)
|
logger.debug(`Consumed epoch ${epoch} close event`)
|
||||||
|
const [threshold, parties] = await Promise.all([
|
||||||
|
bridge.getThreshold(epoch),
|
||||||
|
bridge.getParties(epoch)
|
||||||
|
])
|
||||||
signQueue.send({
|
signQueue.send({
|
||||||
closeEpoch: epoch,
|
closeEpoch: epoch,
|
||||||
blockNumber,
|
blockNumber,
|
||||||
nonce: foreignNonce[epoch],
|
nonce: foreignNonce[epoch],
|
||||||
threshold: await bridge.getThreshold(epoch),
|
threshold,
|
||||||
parties: await bridge.getParties(epoch)
|
parties
|
||||||
})
|
})
|
||||||
foreignNonce[epoch] += 1
|
foreignNonce[epoch] += 1
|
||||||
redisTx.incr(`foreignNonce${epoch}`)
|
redisTx.incr(`foreignNonce${epoch}`)
|
||||||
|
|
|
@ -222,7 +222,9 @@ function getAccountBalance(account, asset) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildTx(from, account, data) {
|
async function buildTx(from, account, data) {
|
||||||
const { closeEpoch, newEpoch, nonce } = data
|
const {
|
||||||
|
closeEpoch, newEpoch, nonce, recipient: to
|
||||||
|
} = data
|
||||||
|
|
||||||
const txOptions = {
|
const txOptions = {
|
||||||
from,
|
from,
|
||||||
|
@ -237,13 +239,6 @@ async function buildTx(from, account, data) {
|
||||||
|
|
||||||
txOptions.flags = 0x01
|
txOptions.flags = 0x01
|
||||||
} else if (newEpoch) {
|
} 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}`)
|
logger.info(`Building corresponding transaction for transferring all funds, nonce ${nonce}, recipient ${to}`)
|
||||||
const fee = await getFee()
|
const fee = await getFee()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue