Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3493239
D6551.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6551.diff
View Options
diff --git a/lib/utils/ens-cache.js b/lib/utils/ens-cache.js
--- a/lib/utils/ens-cache.js
+++ b/lib/utils/ens-cache.js
@@ -3,6 +3,7 @@
import namehash from 'eth-ens-namehash';
const cacheTimeout = 24 * 60 * 60 * 1000; // one day
+const failedQueryCacheTimeout = 5 * 60 * 1000; // five minutes
export type EthersProvider = {
+lookupAddress: (address: string) => Promise<?string>,
@@ -70,7 +71,13 @@
const fetchENSNamePromise = (async () => {
// ethers.js handles checking forward resolution (point 1 above) for us
- const ensName = await this.provider.lookupAddress(normalizedETHAddress);
+ let ensName;
+ try {
+ ensName = await this.provider.lookupAddress(normalizedETHAddress);
+ } catch (e) {
+ console.log(e);
+ return null;
+ }
if (!ensName) {
return undefined;
}
@@ -91,9 +98,11 @@
return (async () => {
const normalizedENSName = await fetchENSNamePromise;
+ const timeout =
+ normalizedENSName === null ? failedQueryCacheTimeout : cacheTimeout;
this.nameQueryCache.set(normalizedETHAddress, {
normalizedETHAddress,
- expirationTime: Date.now() + cacheTimeout,
+ expirationTime: Date.now() + timeout,
normalizedENSName,
});
return normalizedENSName;
@@ -143,7 +152,13 @@
}
const fetchETHAddressPromise = (async () => {
- const ethAddress = await this.provider.resolveName(normalizedENSName);
+ let ethAddress;
+ try {
+ ethAddress = await this.provider.resolveName(normalizedENSName);
+ } catch (e) {
+ console.log(e);
+ return null;
+ }
if (!ethAddress) {
return undefined;
}
@@ -158,9 +173,11 @@
return (async () => {
const normalizedETHAddress = await fetchETHAddressPromise;
+ const timeout =
+ normalizedETHAddress === null ? failedQueryCacheTimeout : cacheTimeout;
this.addressQueryCache.set(normalizedENSName, {
normalizedENSName,
- expirationTime: Date.now() + cacheTimeout,
+ expirationTime: Date.now() + timeout,
normalizedETHAddress,
});
return normalizedETHAddress;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 2:34 AM (20 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2679862
Default Alt Text
D6551.diff (2 KB)
Attached To
Mode
D6551: [lib] Catch exceptions thrown by ethers.js in ENSCache
Attached
Detach File
Event Timeline
Log In to Comment