Skip to content

Commit 835dd54

Browse files
committed
update prune stack
1 parent 484e3b2 commit 835dd54

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

bit.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,10 @@ export class Bit {
617617
// handle next item in the pruning stack
618618
let pruningStack = PruneStack();
619619
let tokenIdsPruned = pruningStack.newBlock(index);
620-
for (let tokenId of tokenIdsPruned) {
621-
self._tokenIdsModified.add(tokenId);
620+
if (tokenIdsPruned) {
621+
for (let tokenId of tokenIdsPruned) {
622+
self._tokenIdsModified.add(tokenId);
623+
}
622624
}
623625

624626
console.time('[PERF] RPC END ' + index);

prunestack.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ class _PruningStack {
2424
}
2525

2626
// This should be at start of block crawl().
27-
public newBlock(blockIndex: number): IterableIterator<TokenId> {
28-
let blocks = Array.from(this._stack.keys());
29-
let nextBlock = blocks[0];
30-
let pruneMap = this._stack.get(nextBlock)!;
27+
public newBlock(blockIndex: number): IterableIterator<TokenId>|null {
28+
let nextBlock = Array.from(this._stack.keys())[0];
29+
let pruneMap = this._stack.get(nextBlock);
30+
if (!pruneMap) {
31+
console.log(`[WARN] No pruneMap for ${nextBlock}.`);
32+
console.log(`[WARN] PruneStack Keys: ${Array.from(this._stack.keys())} before adding ${blockIndex}`);
33+
this._stack.set(blockIndex, new Map());
34+
return null;
35+
}
3136
console.log(`[INFO] Prune stack at ${blockIndex}, about to pop ${nextBlock}.`);
32-
this._stack.set(blockIndex, new Map());
3337
this._considerPruningMap(pruneMap, blockIndex);
38+
this._stack.set(blockIndex, new Map());
3439
return pruneMap.keys();
3540
}
3641

0 commit comments

Comments
 (0)