Skip to content

Commit

Permalink
Give precedence to block hash over number in time travel queries
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Nov 2, 2023
1 parent 5c0f4a9 commit a550dc0
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/util/src/graph/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ export class GraphDatabase {
block: CanonicalBlockHeight,
alias: string
): Promise<SelectQueryBuilder<Entity>> {
// Block hash takes precedence over number if provided
if (block.hash) {
if (!block.canonicalBlockHashes) {
const { canonicalBlockNumber, blockHashes } = await this._baseDatabase.getFrothyRegion(queryRunner, block.hash);
Expand All @@ -1249,9 +1250,7 @@ export class GraphDatabase {
qb.where(`${alias}.block_hash IN (:...blockHashes)`, { blockHashes: block.canonicalBlockHashes })
.orWhere(`${alias}.block_number <= :canonicalBlockNumber`, { canonicalBlockNumber: block.number });
}));
}

if (block.number) {
} else if (block.number) {
queryBuilder = queryBuilder.andWhere(`${alias}.block_number <= :blockNumber`, { blockNumber: block.number });
}

Expand Down

0 comments on commit a550dc0

Please sign in to comment.