diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-12-12 09:31:16 +0800 |
---|---|---|
committer | Fred Carlsen <fred@sjelfull.no> | 2018-12-13 01:20:29 +0800 |
commit | c8c68fb75add4456186dae2e31ddb731882f721e (patch) | |
tree | 3edcd575fbfe6f45433ab960aa2aeab28eb3c2af | |
parent | 13648808123ad7c574272fd43acf9370c22ab941 (diff) | |
download | dexon-0x-contracts-c8c68fb75add4456186dae2e31ddb731882f721e.tar dexon-0x-contracts-c8c68fb75add4456186dae2e31ddb731882f721e.tar.gz dexon-0x-contracts-c8c68fb75add4456186dae2e31ddb731882f721e.tar.bz2 dexon-0x-contracts-c8c68fb75add4456186dae2e31ddb731882f721e.tar.lz dexon-0x-contracts-c8c68fb75add4456186dae2e31ddb731882f721e.tar.xz dexon-0x-contracts-c8c68fb75add4456186dae2e31ddb731882f721e.tar.zst dexon-0x-contracts-c8c68fb75add4456186dae2e31ddb731882f721e.zip |
Make pull_missing_blocks script consider all events with block numbers (#1420)
-rw-r--r-- | packages/pipeline/src/scripts/pull_missing_blocks.ts | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/packages/pipeline/src/scripts/pull_missing_blocks.ts b/packages/pipeline/src/scripts/pull_missing_blocks.ts index 18fe1b700..275141a12 100644 --- a/packages/pipeline/src/scripts/pull_missing_blocks.ts +++ b/packages/pipeline/src/scripts/pull_missing_blocks.ts @@ -53,8 +53,21 @@ async function getAllMissingBlocks(web3Source: Web3Source): Promise<void> { async function getMissingBlockNumbers(fromBlock: number): Promise<number[]> { console.log(`Checking for missing blocks starting at ${fromBlock}...`); + // Note(albrow): The easiest way to get all the blocks we need is to + // consider all the events tables together in a single query. If this query + // gets too slow, we should consider re-architecting so that we can work on + // getting the blocks for one type of event at a time. const response = (await connection.query( - 'SELECT DISTINCT(block_number) FROM raw.exchange_fill_events WHERE block_number NOT IN (SELECT number FROM raw.blocks) AND block_number >= $1 ORDER BY block_number ASC LIMIT $2', + `WITH all_events AS ( + SELECT block_number FROM raw.exchange_fill_events + UNION SELECT block_number FROM raw.exchange_cancel_events + UNION SELECT block_number FROM raw.exchange_cancel_up_to_events + UNION SELECT block_number FROM raw.erc20_approval_events + ) + SELECT DISTINCT(block_number) FROM all_events + WHERE block_number NOT IN (SELECT number FROM raw.blocks) + AND block_number >= $1 + ORDER BY block_number ASC LIMIT $2`, [fromBlock, MAX_BLOCKS_PER_QUERY], )) as MissingBlocksResponse[]; const blockNumberStrings = R.pluck('block_number', response); |