Skip to content

Commit

Permalink
parallel funnel: make the presync concurrent
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Apr 16, 2024
1 parent a72abb9 commit 1ee52c5
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions packages/engine/paima-funnel/src/funnels/parallelEvm/funnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,12 +401,12 @@ export class ParallelEvmFunnel extends BaseFunnel implements ChainFunnel {
public override async readPresyncData(
args: ReadPresyncDataFrom
): Promise<{ [network: string]: PresyncChainData[] | typeof FUNNEL_PRESYNC_FINISHED }> {
const baseData = await this.baseFunnel.readPresyncData(args);
const basePromise = this.baseFunnel.readPresyncData(args);

let arg = args.find(arg => arg.network == this.chainName);

if (!arg) {
return baseData;
return await basePromise;
}

let fromBlock = arg.from;
Expand All @@ -415,25 +415,29 @@ export class ParallelEvmFunnel extends BaseFunnel implements ChainFunnel {
const startBlockHeight = this.getState().startBlockHeight;

if (fromBlock >= startBlockHeight) {
return { ...baseData, [this.chainName]: FUNNEL_PRESYNC_FINISHED };
return { ...(await basePromise), [this.chainName]: FUNNEL_PRESYNC_FINISHED };
}

try {
toBlock = Math.min(toBlock, startBlockHeight - 1);
fromBlock = Math.max(fromBlock, 0);
if (fromBlock > toBlock) {
return baseData;
}
toBlock = Math.min(toBlock, startBlockHeight - 1);
fromBlock = Math.max(fromBlock, 0);

if (fromBlock > toBlock) {
return await basePromise;
}

try {
doLog(`EVM CDE funnel presync ${this.config.chainId}: #${fromBlock}-${toBlock}`);

const ungroupedCdeData = await getUngroupedCdeData(
this.web3,
this.sharedData.extensions.filter(extension => extension.network === this.chainName),
fromBlock,
toBlock,
this.chainName
);
const [baseData, ungroupedCdeData] = await Promise.all([
basePromise,
getUngroupedCdeData(
this.web3,
this.sharedData.extensions.filter(extension => extension.network === this.chainName),
fromBlock,
toBlock,
this.chainName
),
]);

return {
...baseData,
Expand Down

0 comments on commit 1ee52c5

Please sign in to comment.