A channel consists of two transactions on the blockchain.
{
channelId: String,
pub1: Pubkey,
pub2: Pubkey,
amount1: Integer,
amount2: Integer
}
When an opening transaction is published to the blockchain, it must be signed by both pub1
and pub2
to be valid.
amount1
is how much money pub1
has deposited into the channel. amount2
is how much money pub2
has deposited into the channel. These amounts are removed from the accounts of pub1
and pub2
, and kept in the channel.
{
channelId: String,
nonce: Integer,
amount1: Integer,
amount2: Integer,
delay: Integer
}
The channel transaction updates amount1
, amount2
, and the nonce
. It is only considered valid if the total of amount1
and amount2
stays the same. This allows both parties to make payments to one another.
If Bob wants to request payment from Alice, he adjusts the amounts to transfer the desired funds and signs the transaction. To make the payment, she signs the transaction as well. None of this involves publishing anything to the blockchain, and can happen instantly.
To actually claim the funds, either party publishes the latest channel transaction to the blockchain. After delay
blocks, amount1
and amount2
are transfered to pub1
and pub2
. If a channel transaction with a higher nonce
is published to the blockchain before then, it overrides the older transaction.
This means that if Alice disappears or becomes uncooperative, Bob can still get his money out by waiting delay
blocks.
If Bob tries to cheat by publishing an old channel transaction where he has a higher amount than he does currently, Alice can simply publish the latest transaction with a higher nonce
.