Skip to content

Commit

Permalink
add chain name to the binary search log
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Feb 15, 2024
1 parent 7a43fea commit 6a741e7
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions packages/engine/paima-funnel/src/funnels/evm/funnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class EvmFunnel extends BaseFunnel implements ChainFunnel {
const block = await this.sharedData.web3.eth.getBlock(chainData[0].blockNumber - 1);

const ts = Number(block.timestamp);
cachedState.lastBlock = (await findBlockByTimestamp(this.web3, ts)) - 1;
cachedState.lastBlock = (await findBlockByTimestamp(this.web3, ts, this.chainName)) - 1;
}
}

Expand Down Expand Up @@ -434,7 +434,8 @@ export class EvmFunnel extends BaseFunnel implements ChainFunnel {

const mappedStartingBlockHeight = await findBlockByTimestamp(
web3,
Number(startingBlock.timestamp)
Number(startingBlock.timestamp),
chainName
);

evmCacheEntry.updateState(config.chainId, [], [], mappedStartingBlockHeight);
Expand Down Expand Up @@ -508,7 +509,11 @@ export async function wrapToEvmFunnel(
}

// performs binary search to find the corresponding block
async function findBlockByTimestamp(web3: Web3, timestamp: number): Promise<number> {
async function findBlockByTimestamp(
web3: Web3,
timestamp: number,
chainName: string
): Promise<number> {
let low = 0;
let high = Number(await web3.eth.getBlockNumber()) + 1;

Expand All @@ -528,7 +533,9 @@ async function findBlockByTimestamp(web3: Web3, timestamp: number): Promise<numb
}
}

doLog(`EVM CDE funnel: Found block ${low} by binary search with #${requests} requests`);
doLog(
`EVM CDE funnel: Found block #${low} on ${chainName} by binary search with ${requests} requests`
);

return low;
}
Expand Down

0 comments on commit 6a741e7

Please sign in to comment.