Skip to content

Commit

Permalink
fix uncaught in block stream
Browse files Browse the repository at this point in the history
  • Loading branch information
kajoseph committed Jul 19, 2024
1 parent b1047fb commit fcddb96
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/bitcore-node/src/providers/chain-state/evm/api/csp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -911,15 +911,22 @@ export class BaseEVMStateProvider extends InternalStateProvider implements IChai

let block;
let nextBlock;
for (const blockNum of blockRange) {
// stage next block in new var so `nextBlock` doesn't get overwritten if needed for `block`
const thisNextBlock = parseInt(block?.number) === blockNum + 1 ? block : await web3.eth.getBlock(blockNum + 1);
block = parseInt(nextBlock?.number) === blockNum ? nextBlock : await web3.eth.getBlock(blockNum);
nextBlock = thisNextBlock;
const convertedBlock = EVMBlockStorage.convertRawBlock(chain, network, block);
convertedBlock.nextBlockHash = nextBlock?.hash;
convertedBlock.confirmations = tipHeight - block.number + 1;
this.push(convertedBlock);
try {
for (const blockNum of blockRange) {
// stage next block in new var so `nextBlock` doesn't get overwritten if needed for `block`
const thisNextBlock = parseInt(block?.number) === blockNum + 1 ? block : await web3.eth.getBlock(blockNum + 1);
block = parseInt(nextBlock?.number) === blockNum ? nextBlock : await web3.eth.getBlock(blockNum);
if (!block) {
continue;
}
nextBlock = thisNextBlock;
const convertedBlock = EVMBlockStorage.convertRawBlock(chain, network, block);
convertedBlock.nextBlockHash = nextBlock?.hash;
convertedBlock.confirmations = tipHeight - block.number + 1;
this.push(convertedBlock);
}
} catch (e) {
logger.error('Error streaming blocks: %o', e);
}
this.push(null);
}
Expand Down

0 comments on commit fcddb96

Please sign in to comment.