From 32386e344299a62b9d2f68e0787f38fd2dc5758a Mon Sep 17 00:00:00 2001 From: b-pmcg Date: Wed, 2 Nov 2022 17:34:57 -0600 Subject: [PATCH] add a startup function to check the env for block numbers to scrape prior to starting ETL (for tests) --- .env | 4 ++-- config.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/.env b/.env index ef79147..8ca8c87 100644 --- a/.env +++ b/.env @@ -6,7 +6,7 @@ VL_DB_HOST=host.docker.internal VL_DB_PORT=5432 VL_CHAIN_HOST=http://host.docker.internal:8545 VL_CHAIN_HOST_L2=http://host.docker.internal:8546 -VL_CONFIG_NAME=multi_goerli +VL_CONFIG_NAME=docker_config VL_LOGGING_LEVEL=3 @@ -18,7 +18,7 @@ VL_LOGGING_LEVEL=3 # VL_DB_PORT=5432 # VL_CHAIN_HOST=http://localhost:8545 # VL_CHAIN_HOST_L2=http://localhost:8546 -# VL_CONFIG_NAME=multi_goerli +# VL_CONFIG_NAME=docker_config # VL_LOGGING_LEVEL=3 STARTING_BLOCK_GOERLI=7810463 diff --git a/config.js b/config.js index da5a63a..c48d9f8 100644 --- a/config.js +++ b/config.js @@ -12,6 +12,9 @@ const voteProxyFactoryTransformer = require('./transformers/VoteProxyFactoryTran const esmTransformer = require('./transformers/EsmTransformer'); const esmV2Transformer = require('./transformers/EsmV2Transformer'); const voteDelegateFactoryTransformer = require('./transformers/VoteDelegateFactoryTransformer'); +const { + BlockGenerator, +} = require('@makerdao-dux/spock-etl/dist/blockGenerator/blockGenerator'); //mainnet const MKR_ADDRESS = '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2'; @@ -204,6 +207,7 @@ const arbitrumTestnet = { startingBlock: STARTING_BLOCK_ARB_TESTNET, extractors: [...makeRawLogExtractors([ARB_TESTNET_POLLING_ADDRESS])], transformers: [arbitrumPollingTransformer(ARB_TESTNET_POLLING_ADDRESS)], + // TODO: I think don't need to run the migrations a second time, remove this: migrations: { mkr: './migrations', }, @@ -220,6 +224,46 @@ const arbitrumTestnet = { console.log(`Starting with these services: ${Object.keys(services)}`), }; +const dockerConfig = [ + { + ...goerli, + onStart: async (services) => { + console.log( + `Starting Goerli config with these services: ${Object.keys(services)}` + ); + + // Blocknumbers can be provided to add certain events to the test database on an adhoc basis + if (process.env.SEED_BLOCKS) { + const blocks = process.env.SEED_BLOCKS.split(','); + + console.log(`Initial seed blocks to scrape: ${blocks}`); + + // Set the batch size to 1 so we only extract the single block we want + const modServices = { + ...services, + config: { + ...services.config, + blockGenerator: { + batch: 1, + }, + }, + }; + + const b = new BlockGenerator(modServices); + await b.init(); + await Promise.all( + blocks.map((blockNumber) => + b.run(parseInt(blockNumber), parseInt(blockNumber)) + ) + ); + + await b.deinit(); + } + }, + }, + arbitrumTestnet, +]; + let config; if (process.env.VL_CONFIG_NAME === 'multi') { console.log('Using Mainnet multi-chain config'); @@ -227,6 +271,9 @@ if (process.env.VL_CONFIG_NAME === 'multi') { } else if (process.env.VL_CONFIG_NAME === 'multi_goerli') { console.log('Using Goerli multi-chain config'); config = [goerli, arbitrumTestnet]; +} else if (process.env.VL_CONFIG_NAME === 'docker_config') { + console.log('Using Docker multi-chain config'); + config = dockerConfig; } module.exports.default = config;