Lightning Network is a Layer 2 solution on top Bitcoin (Layer 1).
Under normal conditions we should run our own Bitcoin Full Node and point the Lightning Network Node to it. This way we make sure that we are independent of any third parties to notify us about events related to our channel(s) state.
However, many people do not want/can/care to run a Bitcoin Full Node, what they would like is a quick and simple way to test some Lightning Network applications (LApps).
In this article we will look in detail at how the balance of a Lighting Network channel gets updated without any of the participants risking their funds.
Lightning Network is an adversarial network, participants do not trust the other side. In fact they expect that the “others” will try to cheat them.
A participant signs only what it knows to be safe. At any moment it must have the option to take out the money and leave the agreement (close the channel).
For this article we assume that the payment channel has already been open and it has a balance…
Bitcoin has contracts, it always did. A contract is just a small script (program) that gets executed when an output is being spent.
The spender must provide an input for the script (contract), then the script is executed, if it returns TRUE, then the UTXO can be spent, otherwise it cannot.
A contract is usually (but not always) agreed between two parties. The party that spends the funds (Alice) and the party that receives the funds (Bob).
A Revocable Sequence Maturity Contract (RSMC) has two main characteristics: