fallback event indexing & extend caching support
This commit is contained in:
parent
a83fae0772
commit
1b922fa445
8 changed files with 84 additions and 27 deletions
54
scripts/checkEventsSync.js
Normal file
54
scripts/checkEventsSync.js
Normal file
|
@ -0,0 +1,54 @@
|
|||
import networkConfig from '../networkConfig'
|
||||
import ABI from '../abis/Instance.abi.json'
|
||||
import { loadCachedEvents, getPastEvents } from './helpers'
|
||||
|
||||
const EVENTS_PATH = './static/events/'
|
||||
const enabledChains = ['1', '56', '100', '137' ]
|
||||
|
||||
async function main() {
|
||||
for (let network in enabledChains) {
|
||||
const netId = enabledChains[network]
|
||||
const config = networkConfig[`netId${netId}`]
|
||||
const { constants, tokens, nativeCurrency, deployedBlock } = config
|
||||
const CONTRACTS = tokens[nativeCurrency].instanceAddress
|
||||
|
||||
console.log(`\n ::: ${netId} [${nativeCurrency.toUpperCase()}] :::`)
|
||||
|
||||
for (const [instance, _contract] of Object.entries(CONTRACTS)) {
|
||||
console.log(`\n instanceDenomation - ${instance}`)
|
||||
|
||||
const withdrawalCachedEvents = await loadCachedEvents({
|
||||
name: `withdrawals_${nativeCurrency}_${instance}.json`,
|
||||
directory: EVENTS_PATH,
|
||||
deployedBlock
|
||||
})
|
||||
|
||||
console.log('- Withdrawals')
|
||||
console.log('cachedEvents count - ', withdrawalCachedEvents.events.length)
|
||||
console.log('lastBlock - ', withdrawalCachedEvents.lastBlock)
|
||||
|
||||
const depositCachedEvents = await loadCachedEvents({
|
||||
name: `withdrawals_${nativeCurrency}_${instance}.json`,
|
||||
directory: EVENTS_PATH,
|
||||
deployedBlock
|
||||
})
|
||||
|
||||
console.log('- Deposits')
|
||||
console.log('cachedEvents count - ', depositCachedEvents.events.length)
|
||||
console.log('lastBlock - ', depositCachedEvents.lastBlock)
|
||||
|
||||
const notesCachedEvents = await loadCachedEvents({
|
||||
name: `encrypted_notes_${netId}.json`,
|
||||
directory: EVENTS_PATH,
|
||||
deployedBlock: constants.ENCRYPTED_NOTES_BLOCK
|
||||
})
|
||||
|
||||
console.log('- Notes')
|
||||
console.log('cachedEvents count - ', notesCachedEvents.events.length)
|
||||
console.log('lastBlock - ', notesCachedEvents.lastBlock)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
|
@ -55,7 +55,7 @@ export async function getPastEvents({ type, fromBlock, netId, events, contractAt
|
|||
let [{ url: rpcUrl }] = Object.values(networkConfig[`netId${netId}`].rpcUrls)
|
||||
|
||||
if (netId === '5') {
|
||||
rpcUrl = `https://goerli.infura.io/v3/${process.env.INFURA_KEY}`
|
||||
rpcUrl = 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161'
|
||||
}
|
||||
|
||||
const provider = new Web3.providers.HttpProvider(rpcUrl)
|
||||
|
@ -63,9 +63,13 @@ export async function getPastEvents({ type, fromBlock, netId, events, contractAt
|
|||
const contract = new web3.eth.Contract(...contractAttrs)
|
||||
|
||||
const currentBlockNumber = await web3.eth.getBlockNumber()
|
||||
const blockDifference = Math.ceil(currentBlockNumber - fromBlock)
|
||||
// PoS networks index blocks too fast, so a buffer is needed
|
||||
const blockNumberBuffer = currentBlockNumber - 3
|
||||
const blockDifference = Math.ceil(blockNumberBuffer - fromBlock)
|
||||
|
||||
const blockRange = Number(netId) === 56 ? 4950 : blockDifference / 20
|
||||
// eth_logs and eth_filter are restricted > 10,000 block queries
|
||||
const blockDenom = blockDifference > 10000 ? 4950 : 20
|
||||
const blockRange = blockDifference / blockDenom
|
||||
|
||||
let chunksCount = blockDifference === 0 ? 1 : Math.ceil(blockDifference / blockRange)
|
||||
const chunkSize = Math.ceil(blockDifference / chunksCount)
|
||||
|
@ -97,7 +101,6 @@ export async function getPastEvents({ type, fromBlock, netId, events, contractAt
|
|||
toBlock += chunkSize
|
||||
} catch (err) {
|
||||
console.log('getPastEvents events', `chunk number - ${i}, has error: ${err.message}`)
|
||||
chunksCount = chunksCount + 1
|
||||
}
|
||||
}
|
||||
return downloadedEvents
|
||||
|
|
|
@ -8,7 +8,7 @@ import ABI from '../abis/TornadoProxy.abi.json'
|
|||
import { getPastEvents, loadCachedEvents } from './helpers'
|
||||
|
||||
const EVENTS_PATH = './static/events/'
|
||||
const enabledChains = ['1', '5', '56']
|
||||
const enabledChains = ['1', '5', '56', '100', '137']
|
||||
|
||||
async function saveEncryptedNote(netId) {
|
||||
const {
|
||||
|
|
|
@ -9,7 +9,7 @@ import { loadCachedEvents, getPastEvents } from './helpers'
|
|||
|
||||
const EVENTS_PATH = './static/events/'
|
||||
const EVENTS = ['Deposit', 'Withdrawal']
|
||||
const enabledChains = ['1', '56', '5']
|
||||
const enabledChains = ['1', '56', '5', '100', '137' ]
|
||||
|
||||
async function main(type, netId) {
|
||||
const { tokens, nativeCurrency, deployedBlock } = networkConfig[`netId${netId}`]
|
||||
|
|
|
@ -14,7 +14,7 @@ const TREES_PATH = './static/trees/'
|
|||
const EVENTS_PATH = './static/events/'
|
||||
|
||||
const EVENTS = ['deposit']
|
||||
const enabledChains = ['1']
|
||||
const enabledChains = ['1', '56', '100', '137' ]
|
||||
let mimcHash
|
||||
|
||||
const trees = {
|
||||
|
@ -28,8 +28,8 @@ function getName({ path, type, instance, format = '.json', currName = 'eth' }) {
|
|||
|
||||
function createTreeZip(netId) {
|
||||
try {
|
||||
const config = networkConfig[`netId${netId}`]
|
||||
const { instanceAddress: CONTRACTS } = config.tokens.eth
|
||||
const { tokens, nativeCurrency, currencyName } = networkConfig[`netId${netId}`]
|
||||
const CONTRACTS = tokens[nativeCurrency].instanceAddress
|
||||
|
||||
for (const type of EVENTS) {
|
||||
for (const [instance] of Object.entries(CONTRACTS)) {
|
||||
|
@ -38,7 +38,7 @@ function createTreeZip(netId) {
|
|||
instance,
|
||||
format: '',
|
||||
path: TREES_PATH,
|
||||
currName: config.currencyName.toLowerCase()
|
||||
currName: currencyName.toLowerCase()
|
||||
})
|
||||
|
||||
const treesFolder = fs.readdirSync(TREES_FOLDER)
|
||||
|
@ -58,25 +58,24 @@ function createTreeZip(netId) {
|
|||
|
||||
async function createTree(netId) {
|
||||
try {
|
||||
const { currencyName, tokens, deployedBlock } = networkConfig[`netId${netId}`]
|
||||
|
||||
const currName = currencyName.toLowerCase()
|
||||
const { instanceAddress: CONTRACTS } = tokens.eth
|
||||
const config = networkConfig[`netId${netId}`]
|
||||
const { nativeCurrency, currencyName, deployedBlock } = config
|
||||
const CONTRACTS = config.tokens[nativeCurrency].instanceAddress
|
||||
|
||||
for (const type of EVENTS) {
|
||||
for (const [instance] of Object.entries(CONTRACTS)) {
|
||||
const filePath = getName({
|
||||
type,
|
||||
instance,
|
||||
currName,
|
||||
format: '',
|
||||
path: TREES_PATH
|
||||
path: TREES_PATH,
|
||||
currName: currencyName.toLowerCase()
|
||||
})
|
||||
|
||||
console.log('createTree', { type, instance })
|
||||
|
||||
const { events } = await loadCachedEvents({
|
||||
name: `${type}s_${currName}_${instance}.json`,
|
||||
name: `${type}s_${nativeCurrency}_${instance}.json`,
|
||||
directory: EVENTS_PATH,
|
||||
deployedBlock
|
||||
})
|
||||
|
|
|
@ -58,7 +58,7 @@ async function testCommon(netId, type, filename) {
|
|||
}
|
||||
|
||||
async function main() {
|
||||
const NETWORKS = [1, 5, 56]
|
||||
const NETWORKS = [1, 5, 56, 100, 137 ]
|
||||
|
||||
for await (const netId of NETWORKS) {
|
||||
updateEncrypted(netId)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue