From 19054c0c0a15b6d7c6b900fe4758c5cf1d1159f8 Mon Sep 17 00:00:00 2001 From: poma Date: Wed, 31 Mar 2021 11:35:43 +0300 Subject: [PATCH] fix tree watcher loop --- package.json | 2 +- src/treeWatcher.js | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 39082eb..fe712f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "relay", - "version": "4.0.10", + "version": "4.0.11", "description": "Relayer for Tornado.cash privacy solution. https://tornado.cash", "scripts": { "server": "node src/server.js", diff --git a/src/treeWatcher.js b/src/treeWatcher.js index d503cb4..f48d8b7 100644 --- a/src/treeWatcher.js +++ b/src/treeWatcher.js @@ -59,7 +59,7 @@ async function processNewEvent(err, event) { await updateRedis() } else { console.log(`Invalid element index ${index}, rebuilding tree`) - await rebuild() + rebuild() } } @@ -77,7 +77,7 @@ async function updateRedis() { const rootOnContract = await contract.methods.getLastAccountRoot().call() if (!tree.root().eq(toBN(rootOnContract))) { console.log(`Invalid tree root: ${tree.root()} != ${toBN(rootOnContract)}, rebuilding tree`) - await rebuild() + rebuild() return } const rootInRedis = await redis.get('tree:root') @@ -92,10 +92,11 @@ async function updateRedis() { } } -async function rebuild() { - await eventSubscription.unsubscribe() - await blockSubscription.unsubscribe() - setTimeout(init, 3000) +function rebuild() { + process.exit(1) + // await eventSubscription.unsubscribe() + // await blockSubscription.unsubscribe() + // setTimeout(init, 3000) } async function init() { @@ -106,10 +107,10 @@ async function init() { const block = await web3.eth.getBlockNumber() const events = await fetchEvents(0, block) tree = new MerkleTree(minerMerkleTreeHeight, events, { hashFunction: poseidonHash2 }) + await updateRedis() console.log(`Rebuilt tree with ${events.length} elements, root: ${tree.root()}`) eventSubscription = contract.events.NewAccount({ fromBlock: block + 1 }, processNewEvent) blockSubscription = web3.eth.subscribe('newBlockHeaders', processNewBlock) - await updateRedis() } catch (e) { console.error('error on init treeWatcher', e.message) }