DEV Community

Satvik Singh
Satvik Singh

Posted on

What I learned interning at Fileverse

Alright so I finally wrapped up my internship at Fileverse a few weeks back, and I've been meaning to sit down and actually write about what I learned instead of just letting it rot in my brain. It was my first time working with Web3 so I was definietly nervous in the beginning. So this is me trying to unpack the stuff that actually stuck.

Private IPFS is wayyy cooler and secure

One of the bigger things I worked on was adding private uploads to our IPFS storage layer (we use Pinata under the hood). Public IPFS is simple in a way anyone with the CID can fetch the content and that causes security concerns in many ways. Sure, we can encrypt the file before uploading it but....thats not secure in the long run(what if our keys get leaked years after the inital upload... we cant forcefully remove copies of our encrypted file from 3rd party) .

In the newer version, Pinata provides private uploads and it works like as follows:

  • Hiding from Public IPFS DHT(Distributed Hash Table): after computing the content hash, it doesnt broadcast the CID to the DHT.
  • Unaccessible from public IPFS gateways: private files cant be accessed through public IPFS gateways like: https://ipfs.io/ipfs/ . So, even if your CID is leaked...fear not. Its not game over.

Alright, but how do we even access our own files on the private IPFS...

There are mainly two ways:

  1. Signed Urls: generate a short lived link using our API key(best for the client side to fetch the files directly)
  2. Direct Backend Retrieval: fetch the raw file payload with our API credentials.

Restricting who can even upload was its own rabbit hole

Well the private Upload is cool and all but not everyone can enjoy it. I won't get into the specifics of how we identify a legitimate caller (that part's internal and not really blog material). I initially tried to shove the check into an existing middleware that already handled a related but different case, and my reviewer (rightly) told me to just split it into its own thing.

So, the lesson is that dont just reuse random scraps if they look useful as debugging will be hell in future.

Storage doesn't clean itself up

Completely separate piece of work, we had a slow storage leak where every time a document got saved, it created a new pinned copy. These kept accumulating and filling up the storage quota.

The fix wasnt conceptually hard, just keep the last N versions and delete the older ones but we cant just send a request to IPFS to unpin the file as soon as the user clicks delete... we just mark it to be unpinned and remove it from the UI and then a scheduled cron job can read the files marked for deletion and request Pinata to unpin it and only mark the file as deleted after a successful unpin from pinata.

otherwise if we mark it as deleted before, then a failed deletetion job will cause our numbers to drift apart and a ghost file will remain pinned and consume unnecessary resources.

A very weird memory leak

This one was very fun to tinker with. A service that does some cryptographic verification work was steadily eating more memory than usual and the memory usage wasnt going back down to normal idle levels after request has been responded to. There wasnt an obvious issue.

Turned out the issue was buried in how a particular elliptic curve object was being initialized, inside the worker thread loop, first it was getting checked if the object has been initialized...if not then initialize the object...the initialization was a slow task. now suppose 2 request come in very close to each other...the first one sees that the object has not been initialized so it calls the initialize method and waits...then the second request comes in and sees that the object has still not been initialized so it calls the initialize again separately... we were having multiple objects living in the memory as opposed to a single one.

I also implemented a resource logger at every level to help me find where the the issue arises keeping the logger itself lightweight so it doesnt hog the resources itself and flags them.

Conclusion

Anyway, that's everything summarised to fit your attention span lol. I will definitely delve deeper into some of the concepts which I needed to study during this period. If any of this is useful to someone else stumbling into a similar stack, cool. If not, at least future-me has this written down somewhere.

Top comments (0)