hedera-json-rpc-relay icon indicating copy to clipboard operation
hedera-json-rpc-relay copied to clipboard

Look into using redis cache to cache the hash of a FileId based on the contract bytes hash

Open ebadiere opened this issue 2 years ago • 0 comments

Problem

File create and append transactions are costing HBars. Some of these files have the same content. We need logic to hash the file contents into some sort of content ID, and then store that to the redis cache. Before creating and possibly appending files look up the content ID in the cache and if found we have a duplicate. Use the file id from the cache in the ethereum transaction.

Solution

In the relay, the sdkClient.ts class, the method submitEthereumTransaction calls a method createFile that creates a file for transaction data greater than 5120 bytes (FileCreateTransaction). It will most likely also append data (FileAppendTransaction). This method returns a fileId that is later set in the ethereum call data fileId.

Implement a solution like:

  1. Hash the contents (perhaps using sha 256) and lookup the resulting hash in the redis cache.
  2. If found, use the mapped fileId in the setCallDataFileId.
  3. If not found, call createFile, and then store the hash mapped to the resulting FileId from createFile to the redis cache.

Open question: How long should file contents be stored?

Alternatives

No response

ebadiere avatar Sep 05 '23 01:09 ebadiere