-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DIDComm Message Decryption + Disruption by eth_getLogs
/eth_getChainId
calls
#1432
Comments
I can venture some guesses as to what's happening but without a sample to reproduce the issue it'll be harder to provide a clear solution. The calls to the network:
import { getResolver } from 'ethr-did-resolver'
// see https://chainlist.org/ for more RPC options
const SEPOLIA_RPC_URL = `https://ethereum-sepolia-rpc.publicnode.com`;
const SEPOLIA_CHAIN_ID = 11155111;
const network = Network.from(SEPOLIA_CHAIN_ID);
const provider = new JsonRpcProvider(SEPOLIA_RPC_URL, network, { staticNetwork: network });
const ethrResolver = getResolver({
networks: [{
chainId: SEPOLIA_CHAIN_ID,
name: 'sepolia',
registry: '0x03d5003bf0e79C5F5223588F347ebA39AfbC3818',
legacyNonce: false,
provider: provider
}]
}); The long decrypting time.This is very hard to pinpoint without a sample JWE+privateKey to try it locally, BUT there may be some things you can do to speed things up. import { Resolver } from 'did-resolver'
const resolver = new Resolver({
...ethrResolver, // use the ethr resolver configured earlier
// ... other resolvers here
}, { cache: true }); // <<< ENABLE CACHING FOR DID RESOLUTION
const agent = createAgent({
plugins: [
new DIDResolverPlugin({ resolver: resolver })
// ... other plugins
],
}) You can implement your own caching mechanism. See how the inMemoryCache is implemented here. Then, instead of supplying NotesConfiguring an agent like above will result in DID documents that are cached for the lifetime of the
Long term, the did:ethr resolver should have its own caching layer for the results of I hope this helps. Please provide updates if you implement these suggestions as you're surely not the only ones encountering this |
@radleylewis were you able to discover the cause of the slowdown? |
@mirceanis thanks for the follow up. Your advice was on point and we took the approach of caching the resolved DIDDoc, not only in the context of the MetaMask Snap (with respect to our frontend) but also on the server. For reference the delay was completely attributable to the resolution of the DIDDoc (as you had suggested) as evidenced by the below: Our solution for reference (and hopefully that others may use) implemented a derivative of the cache example that you provided (altered for suitablility within the MetaMask Snap): export const snapCache = (): DIDCache => {
const state = StorageService.get();
return async (parsed: ParsedDID, resolve) => {
if (parsed.params && parsed.params['no-cache'] === 'true') return resolve();
const rawDid = parsed.didUrl;
const cached = state.didDocCacheState[did];
let needResolve = false;
if (!cached) needResolve = true;
if (cached) {
const now = new Date();
const timeDiffSinceLastResolved =
now.getTime() - new Date(cached.lastResolvedDate).getTime();
const minuteInMillisec = 60 * 1000;
if (timeDiffSinceLastResolved > 10 * minuteInMillisec) needResolve = true;
}
if (needResolve) {
const result = await resolve();
const onChainEd25519Keys = fetchOnChainEd25519Keys(result);
const onChainX25519Keys = fetchOnChainX25519Keys(result);
// !Note: Make sure to have at least 1 ed25519, x22519 key & service endpoint on chain
// before caching
// This is cater for our use case and might not flexible enough for generic use
if (
result.didResolutionMetadata.error !== 'notFound' &&
onChainX25519Keys.length > 0 &&
onChainEd25519Keys.length > 0 &&
result.didDocument?.service &&
result.didDocument.service.length > 0
) {
state.didDocCacheState[did] = {
lastResolvedDate: new Date(),
didResolution: result,
};
StorageService.set(state);
await StorageService.save();
}
return result;
} else return cached.didResolution;
};
}; In the context of the server we have a similar approach but one which uses redis for the memory cache as opposed to the |
Problem
In our use case we are decrypting didcomm messages within the context of our custom MetaMask Snap. This process is quite time consuming (up to approx. 100 seconds). Our specific use case does not invoke calls to the network, however, Veramo (via the provider) does invoke the
eth_getLogs
andeth_getChainId
calls usingethers
. In the case of their failure (i.e. in the case the RPC provider comes back with an error, for example, a rate limit), the long running decryption process (i.e. the decryption) is interrupted. Therefore, there are two components to this issue we are facing:jwe
encoded) takes around or over 100 seconds;Solution
As it relates to the decryption time any feedback or insight you can provide on the matter is greatly appreciated. As it pertains to the provider calls on
eth_getChainId
andeth_getLogs
errors bubbling up and cancelling the other processes - even when the aforementioned calls do not appear to be required - it would appear that these could be deactivated.Other Questions
Any information you can provide on this is greatly appreciated. If we can align on the solution, we would be happy to present a PR, but wanted to sync up here first.
Screenshot
Example of offending calls within the background.html in the MetaMask Snap.
The text was updated successfully, but these errors were encountered: