Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emulated blocks: fix potentially skipping blocks on a crash #221

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions engine/paima-funnel/src/funnels/FunnelCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export class FunnelCacheManager {
public cacheEntries: CacheMapType = {};

public clear(): void {
for (const entry of Object.values<FunnelCacheEntry>(this.cacheEntries)) {
entry.clear();
for (const entry of Object.getOwnPropertySymbols(this.cacheEntries) as Array<
keyof CacheMapType
>) {
this.cacheEntries[entry]?.clear();
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions engine/paima-funnel/src/funnels/emulated/funnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ export class EmulatedBlocksFunnel extends BaseFunnel {
const latestAvailableBlockNumber = this.sharedData.cacheManager.cacheEntries[
RpcCacheEntry.SYMBOL
]?.getState(ENV.CHAIN_ID);
if (
latestAvailableBlockNumber == null ||
latestAvailableBlockNumber.state === RpcRequestState.NotRequested
)
if (latestAvailableBlockNumber?.state !== RpcRequestState.HasResult)
throw new Error(`latestAvailableBlockNumber missing from cache for ${ENV.CHAIN_ID}`);

// check if the chunk we read matches the latest block known by the RPC endpoint
Expand Down Expand Up @@ -334,9 +331,6 @@ export class EmulatedBlocksFunnel extends BaseFunnel {

// we only want to pop off the queue the entries that correspond for the next ChainData
// for the rest, we leave them in the queue to be fetched in the next readData call
if (this.processingQueue.length === 0) {
} else if (this.processingQueue[0].timestamp >= nextBlockEndTimestamp) {
}
const mergedBlocks: ChainData[] = [];
while (
this.processingQueue.length > 0 &&
Expand Down
2 changes: 1 addition & 1 deletion engine/paima-runtime/src/runtime-loops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ async function processSyncBlockData(
exitIfStopped(run);

// note: every state machine update is its own SQL transaction
// this is to ensure things like shutting down and taking snapshots properly sees SM updats
// this is to ensure things like shutting down and taking snapshots properly sees SM updates
const success = await tx<boolean>(gameStateMachine.getReadWriteDbConn(), async dbTx => {
// Before processing -- sanity check of block height:
if (!(await blockPreProcess(dbTx, gameStateMachine, chainData.blockNumber, pollingPeriod))) {
Expand Down