The challenge of integrating the Lightning Network
in Trading, Tutorial
Lightning Network Integration in Bitfinex was a challenging and exciting task for us. Not only did we enable Lightning Network deposit and withdrawals but we also used Lightning Network to settle payments for purchasing gift cards with Bitrefill.
We learned a lot during the development process, and would like to share some high-level learnings with the community.
Establishing a good development environment is important, and our development started on Simnet Bitcoin. The main benefit of Simnet is that it gives you great flexibility and speed by letting you dig blocks as needed. This is very useful because testing opening and closing channels over and over on testnet is very slow and frustrating, and doing it on mainnet is also expensive and slow at times.
Next up is setting up the Lightning Goals.
Established a cluster of Lightning nodes running in Docker and connected to a 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 different payment provinces and test our integration with ease.
Lightning Network payments are not like any other payment method that Bitfinex previously integrated.
The Lightning Network has no blockchain or addresses and instead has new concepts like payment channels and invoices.
So installing Lightning in 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 massive changes everywhere in our system.
Lightning is ready for prime time
The biggest challenge with Lightning integration was learning and overriding potential attack vectors, best practices and quirks.
Lightning is not like Bitcoin having only 1 operation, Lightning has several operations that follow the BOLT protocol specification. Every Lightning node has its potential quirks and bugs and sometimes relates to incompatibility with other operations. It’s good to know about big bugs and the issues of all major operations.
Do not assume that the default settings are good enough. The configuration of your node is very important, you should be aware of what each configuration item does and adapt to your needs. Some node implementations even have undocumented settings that you should know about.
Even when creating invoices, sending payments, finding invoice settlements, be aware of what each location does. The defects may not suit you.
Understand all payment states. Do not assume that all payments will be successful or fail, payments may also remain pending for an extended period.
As the network and operations are being developed, expect some feats and bugs to appear, some of these are harmless or disruptive, some are more critical and can cause loss of money, sometimes payments can fail because user error or network liquidity. The Lightning Network has many small nuances that wallet developers should know about. Best practices are counted as the network matures and more battle tests are obtained daily.
Lightning Network development is decentralized and moving fast. Different implementations of the specification have different aims, concerns and requirements. This is a good thing as competition between operations should result in each goal offering different features and compromises. Unlike Bitcoin and many other blockchains, new developments happen every week in some corners of the community. To maintain a secure wallet, developers need to be actively monitoring the community.
Here are a few high-level lessons we learned while integrating the Lightning network into Bitfinex.
It’s safe to say that Lightning is now deeply rooted in Bitfinex. We are always working to always build new features and improve our existing features for the benefit of our users and the wider Bitcoin and Lightning Network community.