30 Dec The challenge of integrating the Lightning Network
Integrating Lightning Network at Bitfinex was a challenging and exciting task for us. We didn’t just enable Lightning Network deposit and withdrawals but we are also utilizing Lightning Network to settle payments for gift card purchases with Bitrefill.
We learned a lot during the development process, and we would like to share some high-level learnings with the community.
Setting up a good development environment is important, and our development started on Bitcoin’s Simnet. The main benefit of Simnet is that it gives you great flexibility and speed by letting you mine blocks on demand. This is very useful because testing channel opening and closing over and over again on testnet is very slow and frustrating, and doing it on mainnet is also expensive and slow at times.
Next up is the setting up the Lightning Nodes.
A cluster of Lightning nodes was setup running in Docker and connected to the Bitcoin simnet node.
We simulated many different scenarios using our cluster, like sending and receiving single-hop and multi-hop payments. We can also use this cluster to simulate various payment states and test our integration with ease.
Lightning Network payments are not like any other payment method Bitfinex had previously integrated.
The Lightning Network has no blockchain or addresses and instead has new concepts like payment channels and invoices.
So fitting Lightning into an existing infrastructure could have been quite challenging and time-consuming however, Bitfinex runs on Grenache, an open-source microservice framework developed in house.
Grenache gives us the flexibility and confidence to quickly integrate new features without causing huge changes everywhere in our system.
Lightning is ready for prime time
The biggest challenge with integrating Lightning was learning and covering possible attack vectors, best practices, and quirks.
Lightning is not like Bitcoin which has only 1 implementation, Lightning has several implementations that follow the BOLT protocol specification. Every Lightning node has its quirks and potential bugs and some times incompatibility issues with other implementations. It is good to know about major bugs and issues of all major implementations.
Don’t simply assume the default settings is good enough. Your node config is very important, you should be aware of what every config item does and adjust to your needs. Some node implementations even have undocumented settings that you should know about.
Even when creating invoices, sending payments, detecting invoice settlements, be aware of what each setting does. The defaults may not be suitable for you.
Understand all payment states. Don’t assume all payments will be successful or fail, payments can also remain pending for an extended period.
Since the network and implementations are in active development expect some exploits and bugs to appear, some of these are harmless or disruptive, some are more critical and can cause loss of funds, sometimes payments may fail because of a user error or network liquidity. The Lightning Network has a lot of small nuances that wallet developers should know about. The best practices are being figured out as the network matures and becomes more battle-tested every day.
The development of Lightning Network is decentralized and moves quick. Different implementations of the spec have different goals, concerns, and requirements, This is a good thing as competition between implementations should result in each node offering different features and trade-offs. Unlike Bitcoin and many other blockchains, new developments are happening every week in some corners of the community. To maintain a secure wallet, developers need to be actively monitoring the community.
These are just some high-level lessons we learned while integrating the Lightning network into Bitfinex.
It’s safe to say that Lightning is now deeply embedded in Bitfinex. We constantly work to build out always new features and improve our existing features for the benefit of our users and the wider Bitcoin and Lightning Network community.