From b5baa886e6820336a9550bbaa7b6f476da4782ae Mon Sep 17 00:00:00 2001 From: ryanycw Date: Wed, 25 Oct 2023 21:56:09 +0800 Subject: [PATCH 1/2] build: export block during deploy --- packages/contracts/scripts/deploy.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/contracts/scripts/deploy.ts b/packages/contracts/scripts/deploy.ts index b50b361ec..1552cc380 100644 --- a/packages/contracts/scripts/deploy.ts +++ b/packages/contracts/scripts/deploy.ts @@ -33,6 +33,10 @@ export async function main() { : `/** This contract was deployed using a mnemonic. The PRIVATE_KEY variable needs to be set manually **/` + + // get forked block number + const blockNum = await ethers.provider.getBlockNumber() + config.GENESIS_BLOCK = (blockNum - 999).toString() await fs.promises.writeFile(configPath, envfile.stringify(config)) }) From 1c6aa22fa6ef9956dbb87976a936b782d6b31dfd Mon Sep 17 00:00:00 2001 From: ryanycw Date: Wed, 25 Oct 2023 21:56:29 +0800 Subject: [PATCH 2/2] build: add genesis block from configs --- packages/relay/src/config.ts | 10 ++++++++-- packages/relay/src/index.ts | 5 ++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/relay/src/config.ts b/packages/relay/src/config.ts index a9eead0d8..5ef100cc5 100644 --- a/packages/relay/src/config.ts +++ b/packages/relay/src/config.ts @@ -17,11 +17,17 @@ Object.assign(process.env, { PRIVATE_KEY: process.env.PRIVATE_KEY ?? '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80', + GENESIS_BLOCK: process.env.GENESIS_BLOCK ?? '0', ...process.env, }) -export const { UNIREP_ADDRESS, APP_ADDRESS, ETH_PROVIDER_URL, PRIVATE_KEY } = - process.env as any +export const { + UNIREP_ADDRESS, + APP_ADDRESS, + ETH_PROVIDER_URL, + PRIVATE_KEY, + GENESIS_BLOCK, +} = process.env as any export const APP_ABI = ABI diff --git a/packages/relay/src/index.ts b/packages/relay/src/index.ts index fe90614d5..bf5deb3b2 100644 --- a/packages/relay/src/index.ts +++ b/packages/relay/src/index.ts @@ -17,6 +17,7 @@ import { DB_PATH, APP_ADDRESS, APP_ABI, + GENESIS_BLOCK, } from './config' import TransactionManager from './singletons/TransactionManager' @@ -27,8 +28,6 @@ main().catch((err) => { async function main() { const db = await SQLiteConnector.create(schema, DB_PATH ?? ':memory:') - // TODO: this should be switched by stage and prod - const blockNum = await provider.send('eth_blockNumber', []) const synchronizer = new UnirepSocialSynchronizer( { @@ -37,7 +36,7 @@ async function main() { prover: prover, provider: provider, unirepAddress: UNIREP_ADDRESS, - genesisBlock: parseInt(blockNum) - 999, + genesisBlock: parseInt(GENESIS_BLOCK), }, new ethers.Contract(APP_ADDRESS, APP_ABI, provider) )