Skip to content

Commit

Permalink
remove fallback pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 authored and ScottyPoi committed Jan 22, 2025
1 parent afe3fa6 commit cf59eff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
14 changes: 2 additions & 12 deletions packages/portalnetwork/src/client/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ export class ETH {
lookupResponse = await lookup.startLookup()
this.logger.extend('getBlockByHash')(lookupResponse)
if (!lookupResponse || !('content' in lookupResponse)) {
// Header not found by hash, try to find by number if known
const blockNumber = this.history!.blockHashToNumber(blockHash)
if (blockNumber !== undefined) {
const block = await this.getBlockByNumber(blockNumber, includeTransactions)
return block
}
return undefined
} else {
header = lookupResponse.content
Expand Down Expand Up @@ -177,13 +171,9 @@ export class ETH {
// Body not found by hash. Reassemble block without body
return reassembleBlock(header)
}
} else {
// Header not found by number. If block hash is known, search for header by hash
const blockHash = this.history!.blockNumberToHash(BigInt(blockNumber))
if (blockHash !== undefined) {
return this.getBlockByHash(blockHash, includeTransactions)
}
}
// Block not found by number
return undefined
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ describe('getBlockByHash', async () => {
await history.indexBlockHash(21591997n, blockHash)
const block = await ultralight.ETH.getBlockByHash(hexToBytes(blockHash), false)
assert.equal(block, undefined)
}, 3000)
})
it('should not find a block by number', async () => {
const blockNumber = 21591997n
const blockHash = '0x1e98ea9bdf6e44eaed730041682e7db748812d5baef84a38435c8ad5f6c5d1e2'
const history = ultralight.networks.get(NetworkId.HistoryNetwork) as HistoryNetwork
await history.indexBlockHash(blockNumber, blockHash)
const block = await ultralight.ETH.getBlockByNumber(blockNumber, false)
assert.equal(block, undefined)
})
})

0 comments on commit cf59eff

Please sign in to comment.