Skip to content

Commit

Permalink
improve logging and make presync concurrent
Browse files Browse the repository at this point in the history
  • Loading branch information
ecioppettini committed Nov 9, 2023
1 parent e2e612e commit 079776d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
51 changes: 30 additions & 21 deletions packages/engine/paima-funnel/src/funnels/carp/funnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,36 +106,45 @@ export class CarpFunnel extends BaseFunnel implements ChainFunnel {
): Promise<{ [network: number]: PresyncChainData[] | 'finished' }> {
const arg = args.find(arg => arg.network == Network.CARDANO);

let data = await this.baseFunnel.readPresyncData(args);
let basePromise = this.baseFunnel.readPresyncData(args);

if (arg && arg.from >= 0 && arg.from < this.startSlot) {
const poolEvents = await Promise.all(
this.sharedData.extensions
.filter(extension => extension.cdeType === ChainDataExtensionType.CardanoPool)
.map(extension => {
const data = getCdePoolData(
this.carpUrl,
extension as ChainDataExtensionCardanoDelegation,
arg.from,
Math.min(arg.to, this.startSlot - 1),
slot => {
return slot;
}
);
return data;
})
);
const [poolEvents, data] = await Promise.all([
Promise.all(
this.sharedData.extensions
.filter(extension => extension.cdeType === ChainDataExtensionType.CardanoPool)
.map(extension => {
const data = getCdePoolData(
this.carpUrl,
extension as ChainDataExtensionCardanoDelegation,
arg.from,
Math.min(arg.to, this.startSlot - 1),
slot => {
return slot;
}
);
return data;
})
),
basePromise,
]);

let grouped = groupCdeData(Network.CARDANO, arg.from, arg.to, poolEvents);

if (grouped.length > 0) {
data[Network.CARDANO] = grouped;
}
} else if (arg) {
data[Network.CARDANO] = 'finished';
}

return data;
return data;
} else {
const data = await basePromise;

if (arg) {
data[Network.CARDANO] = 'finished';
}

return data;
}
}

public static async recoverState(
Expand Down
11 changes: 9 additions & 2 deletions packages/engine/paima-runtime/src/runtime-loops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,14 @@ async function runPresync(
}

await loopIfStopBlockReached(presyncBlockHeight[Network.EVM], stopBlockHeight);
doLog(`[paima-runtime] Presync finished at ${JSON.stringify(presyncBlockHeight)}`);

const latestPresyncBlockheight = await gameStateMachine.getPresyncBlockHeight();
doLog(`[paima-runtime] Presync finished at ${latestPresyncBlockheight}`);

const latestPresyncSlotHeight = await gameStateMachine.getPresyncCardanoSlotHeight();
if (latestPresyncSlotHeight > 0) {
doLog(`[paima-runtime] Cardano presync finished at ${latestPresyncSlotHeight}`);
}
}

async function getPresyncStartBlockheight(
Expand Down Expand Up @@ -154,7 +161,7 @@ async function runPresyncRound(
}

const filteredPresyncDataList = Object.values(latestPresyncDataList)
.flatMap(network => (network !== 'finished' ? network : []))
.flatMap(data => (data !== 'finished' ? data : []))
.filter(unit => unit.extensionDatums.length > 0);
for (const presyncData of filteredPresyncDataList) {
await gameStateMachine.presyncProcess(chainFunnel.getDbTx(), presyncData);
Expand Down

0 comments on commit 079776d

Please sign in to comment.