mirror of
https://github.com/tornadocash/tornado-root-updater.git
synced 2024-12-04 23:15:05 +01:00
upload deposits and withdrawal separately; disable gas price bump
This commit is contained in:
parent
6c671ff21c
commit
2a7ad84284
@ -12,5 +12,5 @@ INSERT_BATCH_SIZE=60
|
|||||||
CRON_EXPRESSION="0 */3 * * * *"
|
CRON_EXPRESSION="0 */3 * * * *"
|
||||||
CONFIRMATION_BLOCKS=3
|
CONFIRMATION_BLOCKS=3
|
||||||
|
|
||||||
# one of "low", "standard", "fast", "instant" or a number in Gwei
|
# a number in Gwei
|
||||||
GAS_PRICE=fast
|
GAS_PRICE=20
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "root-updater",
|
"name": "root-updater",
|
||||||
"version": "1.0.6",
|
"version": "1.0.7",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -16,7 +16,6 @@
|
|||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"eth-ens-namehash": "^2.0.8",
|
"eth-ens-namehash": "^2.0.8",
|
||||||
"fixed-merkle-tree": "^0.3.4",
|
"fixed-merkle-tree": "^0.3.4",
|
||||||
"gas-price-oracle": "^0.2.2",
|
|
||||||
"ioredis": "^4.17.3",
|
"ioredis": "^4.17.3",
|
||||||
"snarkjs": "git+https://github.com/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5",
|
"snarkjs": "git+https://github.com/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5",
|
||||||
"torn-token": "^1.0.0",
|
"torn-token": "^1.0.0",
|
||||||
|
42
src/index.js
42
src/index.js
@ -1,10 +1,10 @@
|
|||||||
require('dotenv').config()
|
require('dotenv').config()
|
||||||
const cron = require('cron')
|
const cron = require('cron')
|
||||||
const { web3, redis, getTornadoTrees, txManager, gasOracle } = require('./singletons')
|
const { web3, redis, getTornadoTrees, txManager } = require('./singletons')
|
||||||
const config = require('torn-token')
|
const config = require('torn-token')
|
||||||
const { getTornadoEvents, getRegisteredEvents } = require('./events')
|
const { getTornadoEvents, getRegisteredEvents } = require('./events')
|
||||||
const GAS_PRICE_VALUES = ['low', 'standard', 'fast', 'instant']
|
|
||||||
const { toWei, toHex } = require('web3-utils')
|
const { toWei, toHex } = require('web3-utils')
|
||||||
|
const { action } = require('./utils')
|
||||||
|
|
||||||
const STARTING_BLOCK = process.env.STARTING_BLOCK || 0
|
const STARTING_BLOCK = process.env.STARTING_BLOCK || 0
|
||||||
const prefix = {
|
const prefix = {
|
||||||
@ -13,6 +13,8 @@ const prefix = {
|
|||||||
5: 'goerli.',
|
5: 'goerli.',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let previousUpload = action.DEPOSIT
|
||||||
|
|
||||||
async function main(isRetry = false) {
|
async function main(isRetry = false) {
|
||||||
const tornadoTrees = await getTornadoTrees()
|
const tornadoTrees = await getTornadoTrees()
|
||||||
const newEvents = {}
|
const newEvents = {}
|
||||||
@ -22,7 +24,7 @@ async function main(isRetry = false) {
|
|||||||
const explorer = `https://${prefix[netId]}etherscan.io`
|
const explorer = `https://${prefix[netId]}etherscan.io`
|
||||||
const instances = Object.values(config.instances[`netId${netId}`].eth.instanceAddress)
|
const instances = Object.values(config.instances[`netId${netId}`].eth.instanceAddress)
|
||||||
console.log(`Getting events for blocks ${startBlock} to ${currentBlock}`)
|
console.log(`Getting events for blocks ${startBlock} to ${currentBlock}`)
|
||||||
for (const type of ['deposit', 'withdrawal']) {
|
for (const type of Object.values(action)) {
|
||||||
const newRegisteredEvents = await getRegisteredEvents({ type })
|
const newRegisteredEvents = await getRegisteredEvents({ type })
|
||||||
const tornadoEvents = await getTornadoEvents({ instances, startBlock, endBlock: currentBlock, type })
|
const tornadoEvents = await getTornadoEvents({ instances, startBlock, endBlock: currentBlock, type })
|
||||||
|
|
||||||
@ -41,27 +43,26 @@ async function main(isRetry = false) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (newEvents['deposit'].length || newEvents['withdrawal'].length) {
|
console.log(
|
||||||
const chunks = {}
|
`There are ${newEvents[action.DEPOSIT].length} unprocessed deposits and ${
|
||||||
for (const type of ['deposit', 'withdrawal']) {
|
newEvents[action.WITHDRAWAL].length
|
||||||
chunks[type] = newEvents[type].splice(0, process.env.INSERT_BATCH_SIZE)
|
} withdrawals`,
|
||||||
}
|
)
|
||||||
console.log(
|
|
||||||
`Submitting tree update with ${chunks['deposit'].length} deposits and ${chunks['withdrawal'].length} withdrawals`,
|
|
||||||
)
|
|
||||||
let gasPrice
|
|
||||||
if (GAS_PRICE_VALUES.includes(process.env.GAS_PRICE)) {
|
|
||||||
const gasPrices = await gasOracle.gasPrices()
|
|
||||||
gasPrice = gasPrices[process.env.GAS_PRICE]
|
|
||||||
} else {
|
|
||||||
gasPrice = Number(process.env.GAS_PRICE)
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = tornadoTrees.methods.updateRoots(chunks['deposit'], chunks['withdrawal']).encodeABI()
|
while (newEvents[action.DEPOSIT].length || newEvents[action.WITHDRAWAL].length) {
|
||||||
|
const chunks = {}
|
||||||
|
const type = previousUpload === action.DEPOSIT ? action.WITHDRAWAL : action.DEPOSIT
|
||||||
|
chunks[type] = newEvents[type].splice(0, process.env.INSERT_BATCH_SIZE)
|
||||||
|
|
||||||
|
console.log(`Submitting tree update with ${chunks[type].length} ${type}s`)
|
||||||
|
|
||||||
|
const args =
|
||||||
|
previousUpload === action.DEPOSIT ? [[], chunks[action.WITHDRAWAL]] : [chunks[action.DEPOSIT], []]
|
||||||
|
const data = tornadoTrees.methods.updateRoots(...args).encodeABI()
|
||||||
const tx = txManager.createTx({
|
const tx = txManager.createTx({
|
||||||
to: tornadoTrees._address,
|
to: tornadoTrees._address,
|
||||||
data,
|
data,
|
||||||
gasPrice: toHex(toWei(gasPrice.toString(), 'Gwei')),
|
gasPrice: toHex(toWei(process.env.GAS_PRICE, 'Gwei')),
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -81,6 +82,7 @@ async function main(isRetry = false) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
previousUpload = type
|
||||||
}
|
}
|
||||||
|
|
||||||
await redis.set('lastBlock', currentBlock)
|
await redis.set('lastBlock', currentBlock)
|
||||||
|
@ -5,8 +5,6 @@ const tornadoTreesAbi = require('../abi/tornadoTrees.json')
|
|||||||
const Redis = require('ioredis')
|
const Redis = require('ioredis')
|
||||||
const ENSResolver = require('./resolver')
|
const ENSResolver = require('./resolver')
|
||||||
const resolver = new ENSResolver()
|
const resolver = new ENSResolver()
|
||||||
const { GasPriceOracle } = require('gas-price-oracle')
|
|
||||||
const gasOracle = new GasPriceOracle({ defaultRpc: process.env.RPC_URL })
|
|
||||||
const redis = new Redis(process.env.REDIS_URL)
|
const redis = new Redis(process.env.REDIS_URL)
|
||||||
const config = require('torn-token')
|
const config = require('torn-token')
|
||||||
let tornadoTrees
|
let tornadoTrees
|
||||||
@ -20,6 +18,7 @@ const txManager = new TxManager({
|
|||||||
rpcUrl: process.env.RPC_URL,
|
rpcUrl: process.env.RPC_URL,
|
||||||
config: {
|
config: {
|
||||||
CONFIRMATIONS: process.env.CONFIRMATION_BLOCKS,
|
CONFIRMATIONS: process.env.CONFIRMATION_BLOCKS,
|
||||||
|
MAX_GAS_PRICE: process.env.GAS_PRICE,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -36,5 +35,4 @@ module.exports = {
|
|||||||
redis,
|
redis,
|
||||||
getTornadoTrees,
|
getTornadoTrees,
|
||||||
txManager,
|
txManager,
|
||||||
gasOracle,
|
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,10 @@ const toFixedHex = (number, length = 32) =>
|
|||||||
const poseidonHash = (items) => toFixedHex(poseidon(items))
|
const poseidonHash = (items) => toFixedHex(poseidon(items))
|
||||||
const poseidonHash2 = (a, b) => poseidonHash([a, b])
|
const poseidonHash2 = (a, b) => poseidonHash([a, b])
|
||||||
|
|
||||||
|
const action = Object.freeze({ DEPOSIT: 'deposit', WITHDRAWAL: 'withdrawal' })
|
||||||
module.exports = {
|
module.exports = {
|
||||||
toFixedHex,
|
toFixedHex,
|
||||||
poseidonHash,
|
poseidonHash,
|
||||||
poseidonHash2,
|
poseidonHash2,
|
||||||
|
action,
|
||||||
}
|
}
|
||||||
|
@ -2133,14 +2133,6 @@ gas-price-oracle@^0.2.0:
|
|||||||
axios "^0.19.2"
|
axios "^0.19.2"
|
||||||
bignumber.js "^9.0.0"
|
bignumber.js "^9.0.0"
|
||||||
|
|
||||||
gas-price-oracle@^0.2.2:
|
|
||||||
version "0.2.2"
|
|
||||||
resolved "https://registry.yarnpkg.com/gas-price-oracle/-/gas-price-oracle-0.2.2.tgz#32c57a9aa6bc69152be96812880232efebfecbc6"
|
|
||||||
integrity sha512-I4+rLbc7C1vgYXV+cYY0MKeqdZVna2hXpNfD2fcIvf/wIgvtIYmG9gsmhiaYGSgOE2RSPUs2xf/W4K2nJOoNuQ==
|
|
||||||
dependencies:
|
|
||||||
axios "^0.19.2"
|
|
||||||
bignumber.js "^9.0.0"
|
|
||||||
|
|
||||||
get-caller-file@^1.0.1:
|
get-caller-file@^1.0.1:
|
||||||
version "1.0.3"
|
version "1.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a"
|
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a"
|
||||||
|
Loading…
Reference in New Issue
Block a user