Lightning Full Node on your TV!?

Mandel duck
7 min readApr 15, 2019

TLDR: Full bitcoin and lightning node running on Android os, video example below!

Full Article

I admit it’s a bit of a click baity title but the purpose of this article is to demonstrate how it is possible for a user to run their own Bitcoin and Lightning Full Node on their consumer Android OS device such as their smart phone or smart TV.

I am a firm believer that if you aren't running your own full node then you aren't really using bitcoin, however I appreciate the obvious barrier to entry of running a full bitcoin node let alone a full lightning node. This has become much easier recently with the introduction of standalone full lightning node solutions such as the CASA NODE and NODL which I think are great products however would it not be even better if a user could install a full bitcoin and lightning node as simply as downloading and installing an app on their existing consumer entertainment device?

Actually the easiest way to do this is to use Lightning Labs Neutrino SPV solution with the LND lightning implementation, something like Zap, Pebble Wallet or Lightning Lab’s own mobile wallet will soon support this option in the app stores. The SPV solution is pretty straight forward and more light weight than a full node however the SPV approach also has some concerns regarding its effect on the health of the entire bitcoin network. For anybody interested in these concerns they are explained by Nicolas Dorier in his article here.

Moving on… in the article I will demonstrate how I created an Android app that runs a full bitcoind and LND node side by side, furthermore as this is all runnable on android it follows that given a bit of fancy UI and optimizations a user could simply download a fully sovereign lightning setup onto their Android TV or… hey… technically even their smart fridge? why not? it’s always on.

Next I will go into the weeds on the technical details, for those not interested please be kind enough to scroll to the bottom and check out the donation links, any little donation helps me justify to my wife why i’m spending the weekends tinkering for fun when I could be doing paid work or taking her out to fancy restaurants.

Components

The three main components used are stated below, the developers of these components did all the hard work I was just lucky enough to be able to bundle them all together so kudos to them.

ABCore

The foundational app used in this setup is ABCore developed by the Areen Address team, ABCore is an Android wrapper for bitcoind allowing bitcoind to be run on Android OS.

LND

The lightning implementation I chose to use along side ABCore is LND, the reason being is that LND is written in golang and golang has a very useful module called gomobile which lets you compile a golang app into an iOS or Android library.

gRPC

The LND api communicates using gRPC which is an RPC framework allowing a native Android Java app to communicate with the LND lncli.

Putting it all together

With the components in place I decided to download the sample ABCore app as a starting base.
https://github.com/greenaddress/abcore

After compiling it builds a simple app with a switch that will download the bitcoind binary and run it based on a config file you can adjust in the app settings. For this purpose I set this config to testnet and ran it on an android emulator as I don’t have an android device with more than 16GB of storage and 512MB of ram, however if it runs on an emulator it would work on a real device.

Luckily as ABCore is just a wrapper of bitcoind it means that LND should have no compatibility issues connecting to it, as the RPC server api would be the same as regular bitcoind. The next step was to build LND for android using gomobile and import it as a library into our project.

This was a lengthy process as the standard LND master branch cannot be easily built using gomobile due to its structure. After a lot of research I was able to create my own custom branch based off of the mobile support branch developed by halseth at Lightning Labs, the resulting branch is here and should not be used for production purposes. (Apparently Lightning Labs has a plan to release an update to the LND repository to make this process easier in the future!)

After building for Android gomobile produces an .aar file we can import into our android studio project.

Once we have LND imported as a module we need to be able to interface with it, this is where gRPC comes in which can be installed as a gradle dependency. Using the LND rpc.proto file will let gRPC generate an LND api java class we can use to make calls to our LND instance. This process is also somewhat cumbersome to setup at first but more info can be found in the relevant gRPC documentation for Android.

Finally we just need to set up the config files for LND and ABCore to let LND connect to our bitcoind backend. With ABCore it was pretty simple as it can be done directly inside the sample app provided by green address

The main things to note were to enable zmqs and the server config and make sure the rpc host is set to run on localhost, as this may not be done by default with ABCore. Setting the lnd.conf was a bit more involved as there was no function to do so with the lndmobile.aar we produced. It turns out you need to save a pre-made configuration file into the android app directory for lnd to read it. This was done by including an lnd.conf file in the apps bundle then copying it to the lnd data directory on app load.

Finally I added some extra UI and code to interact with LND allowing us to start it, open channels, add peers etc.

Time to run!

Crash!

So it turns out LND will crash if opened too soon after starting bitcoind, this was resolved by simply waiting a while to start LND, seems bitcoind needs to fully open its db and wallet etc. I waited for ABCore to fully sync to testnet and then started LND again and hey bingo! LND was waiting for the user to create or unlock their wallet. Using gRPC I was able to create an new wallet and generate an address which I used to deposit some testnet bitcoins. After the coins were confirmed LNDs great auto pilot feature set up some channels for me and before I knew it I was able to buy an article on the Y‘all’s testnet site as shown in the video above!.

The source code for the project can be found here, it is messy and not recommended for production use.

Next Steps

This was really just a weekend challenge inspired by a twitter thread to see if it were possible, turns out it is. Once I get more time I plan to polish up the source code, make a simple UI and try to compile for android TV if I can get my hands on one. I will also incorporate this into an open source mobile android app people can download.

Implications

I think that running a full node need not be complex at all and the fallacy that only tech geeks can run one needs to be broken. We all have computers and smart phones that run apps and programs just as (if not more) complex than a bitcoin full node so there is no reason why running a full node can’t be made simpler in the future. Hopefully this article demonstrates that in the not to distant future it will be possible for non technical people to easily and cheaply run a fully validating bitcoin and lightning node, helping the decentralisation of the network, but more importantly allowing people to reduce their need to trust whilst increasing their ability to verify!

Update

Managed to also run on an Android smart phone but it did take a day to sync even on testnet.

https://youtu.be/95aQLzJqLtQ

Donations

If you want to help support me develop this project and others further or just want to buy me a beer please consider donating some sats below!

https://mandelduck.io/store

--

--