mirror of
https://github.com/tornadocash/tornado-cli.git
synced 2024-10-01 07:15:36 -04:00
Handle event sync delay from thegraph
This commit is contained in:
parent
cd7cfd834a
commit
b8bc6de79d
15
cli.js
15
cli.js
@ -870,17 +870,21 @@ async function fetchEvents({ type, currency, amount }) {
|
||||
}
|
||||
|
||||
const cachedEvents = loadCachedEvents({ type, currency, amount });
|
||||
const startBlock = cachedEvents.lastBlock + 1;
|
||||
let startBlock = cachedEvents.lastBlock + 1;
|
||||
|
||||
console.log("Loaded cached",amount,currency.toUpperCase(),type,"events for",startBlock,"block");
|
||||
console.log("Fetching",amount,currency.toUpperCase(),type,"events for",netName,"network");
|
||||
|
||||
async function syncEvents() {
|
||||
async function syncEvents(syncedBlock) {
|
||||
try {
|
||||
let targetBlock = await web3.eth.getBlockNumber();
|
||||
let chunks = 1000;
|
||||
console.log("Querying latest events from RPC");
|
||||
|
||||
if (syncedBlock) {
|
||||
startBlock = syncedBlock + 1;
|
||||
}
|
||||
|
||||
for (let i = startBlock; i < targetBlock; i += chunks) {
|
||||
let fetchedEvents = [];
|
||||
|
||||
@ -1126,13 +1130,14 @@ async function fetchEvents({ type, currency, amount }) {
|
||||
console.log("Fetched", amount, currency.toUpperCase(), type, "events to block:", Number(resultBlock));
|
||||
}
|
||||
}
|
||||
return latestBlockNumber;
|
||||
} else {
|
||||
console.log("Fallback to web3 events");
|
||||
await syncEvents();
|
||||
return startBlock - 1;
|
||||
}
|
||||
}
|
||||
await fetchGraphEvents();
|
||||
await syncEvents();
|
||||
const syncedBlock = await fetchGraphEvents();
|
||||
await syncEvents(syncedBlock);
|
||||
}
|
||||
if (!privateRpc && subgraph && !isTestRPC) {
|
||||
await syncGraphEvents();
|
||||
|
Loading…
Reference in New Issue
Block a user