Skip to content

Commit

Permalink
add a startup function to check the env for block numbers to scrape p…
Browse files Browse the repository at this point in the history
…rior to starting ETL (for tests)
  • Loading branch information
b-pmcg committed Nov 2, 2022
1 parent f446f0f commit 32386e3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand Down
47 changes: 47 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
},
Expand All @@ -220,13 +224,56 @@ 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');
config = [mainnet, arbitrum];
} 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;

0 comments on commit 32386e3

Please sign in to comment.