Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Cache getCode() with blockNumber (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamiak authored Oct 31, 2023
1 parent c7ecbb0 commit 573e8ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/discovery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @l2beat/discovery

## 0.21.2

### Patch Changes

- Cache getCode() with blockNumber because the code can change

## 0.21.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/discovery/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@l2beat/discovery",
"description": "L2Beat discovery - engine & tooling utilized for keeping an eye on L2s",
"version": "0.21.1",
"version": "0.21.2",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
Expand Down
12 changes: 7 additions & 5 deletions packages/discovery/src/discovery/provider/ProviderWithCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ export class ProviderWithCache extends DiscoveryProvider {
address: EthereumAddress,
blockNumber: number,
): Promise<Bytes> {
const key = this.buildKey(
'getCode',
// Ignoring blockNumber here, assuming that code will not change
[address],
)
// Contract code can change at any moment, so we cache *with blockNumber*
// see: https://medium.com/coinmonks/dark-side-of-create2-opcode-6b6838a42d71
// Another problem is running discovery on a very old block number
// when some contract has not been deployed yet:
// getCode() would return previously cached value instead of empty code.

const key = this.buildKey('getCode', [blockNumber, address])

return this.cacheOrFetch(
key,
Expand Down

0 comments on commit 573e8ff

Please sign in to comment.