Intro
So I applied for Summer of Bitcoin (SoB) again this summer (read my 2022 SoB blog here), with the same organization Talaia Labs.
My project this year was relatively easy and away from LN. The goal is to make the watchtower daemon (teosd) compatible with different databases other than SQLite, especially PostgreSQL.
Project Work
I used sqlx as the replacement to the rusqlite driver that supported only SQLite. This is kinda straight forward. With that change alone, we get supported for both SQLite and PostgreSQL. We should get MySQL support as well, but for that we need to change how the queries are written for each database driver (because MySQL syntax is a bit different than PostgreSQL one).
sqlx is an async driver, while rusqlite is a blocking sync one, so all the database methods needed to adapt to be asynchronous. This causes a ripple effect over big part of the code base to be asynchronous as well.
An async database driver is better than a sync one for cases like an async webserver/api, which is the case with the watchtower. The request used to come and be served inside an async context but at some point it needed to query the database, with a blocking sync database driver, thus blocking thread. This wasn't too bad though since the tower does already run multi-threaded and the database queries were all short and fast, but we could get some improvement there nonetheless.
The toughest problem I faced wasn't actually database-related at all. Remember the async ripple effect, it needed to propagate all the way to methods and traits from another library (namely LDK). Luckily, since these traits' methods didn't need to return anything to the caller, we could use the actor model, which is a way to bridge sync events to be executed inside an asynchronous context.
Read more technical details about the project in my proposal
Some other related work I was doing during SoB was memory usage optimization. In this PR, we trimmed down most of the in-memory data held by the tower. This data/cache was growing with the number of appointments the tower holds, thus could become unsustainable with a high load tower. We noticed this after Sergi's tower became a memory hog and consumed a constant 2GiB of ram, mine grew big later as well and crashed since my server is a low-resource one.
Post SoB
Why cut the fun short?! I will keep working on The Eye of Satoshi until, well, I don't know.
Final Words
This was my last year at SoB since I have graduated from university already. It's safe to say that thanks to SoB, I can no longer work in a non-bitcoin job. Thanks SoB for shutting down a big portion of the market on my face. Hope to land a bitcoin job soon 🤞.
But really, thanks for this amazing & life changing experience I got to partake in.