Edit on Github

Payment channels, Lightning FAQ

What are Payment channels?

Payment channels allow two users of Bitcoin to transact commitments to pay back and forth between each other much faster and more fluidly than Bitcoin’s 10 minute block times would normally allow. These commitments are exchanged between the users outside of the Bitcoin blockchain. Once the users are done, they can close the payment channel by publishing the last commitment(s) to the blockchain, which will finalize the amount actually transacted.

An ideal use case for the technology is micropayments: Imagine a user making numerous very small payments (e.g. .0001 BTC) to Big Music Company as she listens to songs over a certain period. Without payment channels, the Bitcoin transaction fees from these small payments would be as much or more than the payments themselves, and each payment would take on average 10 minutes to clear.

Shawn Wilkinson of Storj (a Counterparty project) provides a good overview of payment channels (which goes into detail on both unidirectional and bidirectional channels.

What is the Lightning Network?

The Lightning Network, which is still under development, will allow for secure, instant off-chain payments between two arbitrary participants. The Lightning Network is one of the primary methods of scaling Bitcoin to have credit card network-like transaction throughput, while preserving its decentralized qualities.

Lightning Network technology uses bidirectional payment channels as its central component. Much like the internet routes data packets from one network point to another network point, the Lightning Network routes payments across multiple interconnected payment channels. This eliminates the need to construct a new payment channel for every party that you want to transact with. Instead, you may have a channel set up with a party you have an established relationship with, such as a payment provider like Coinbase, who (possibly through multiple degrees of separation) has a payment channel connection to the final end party.

Because the individual participants’ transactions utilize Bitcoin cryptography and are eventually committed back to the Bitcoin blockchain, transactions on the Lightning Network are essentially as secure as if they were transacted directly on Bitcoin, but without the same cost, speed and scalability limitations.

The Lightning Network site includes more information.

How do payment channels help Counterparty users?

Previously, individual Counterparty transactions were committed directly to the Bitcoin blockchain. This is very secure, but is impacted by Bitcoin’s 10 minute block times and per-transaction fees. With payment channels, Counterparty users gain the ability perform certain actions very rapidly and cheaply, such as incrementally swapping XCP for BTC or paying TOKENABC for increased use of a service. The benefits of this are especially apparent when the amounts transacted are small, and/or performed frequently or on an on-going basis.

What are some potential uses for payment channels/micropayments?

  • Rewarding users for specific actions they take, such as contributing content to a blog, or writing a review
  • Incrementally purchasing a service offering, such as paying for additional storage use with Storj
  • Buying in-game items with Counterparty-based games such as Spells of Genesis or SaruTobi
  • Payments for other digital/virtual goods, such as a “contributor” badge on a forum
  • Referral network payments
  • Small/regular donations to charities, projects or individuals (such as musicians and writers of very neat open source software (hint, hint!))
  • Enabling rental of Counterparty asset names

Could payment channels be useful for any kind of transaction?

Theoretically, any Counterparty transaction could be sent in a payment channel. However, the technology is by far most appropriate for send transactions, where one would transfer a Counterparty asset much like one would transfer Bitcoin.

Payment channels don’t remove the need for on-chain transactions (and indeed, each payment channel is started from and ends with an on-chain transaction). Instead, they enable certain use-cases such as rapid incremental payments, and microtransactions.

What is P2SH?

Most commonly in Bitcoin, transactions are made to a specific user’s public key hash (colloquially known as a Bitcoin address), and are spendable by that user’s corresponding private key.

With “Pay-to-script-hash” (P2SH), transactions are sent to the hash of a “redeem script”, which is a special Bitcoin script (e.g. a Bitcoin smart contract) that can be written to do a variety of things. To “execute” the script and operate on some or all of the sent funds, another party will broadcast an additional transaction that provides the original script content, along with any required signatures.

The P2SH support implemented in Counterparty makes payment channels possible, as payment channels (and Lightning Network, for that matter) require the use of these redeem scripts to work. P2SH is also commonly used for multisignature transactions since the signing process is generally more compact and streamlined than the earlier method (“bare multisig”).

You can tell if a Bitcoin address is for a P2SH destination because it will start with ‘3’ on Bitcoin mainnet. Given this, you may notice that many exchanges, for instance, utilize these ‘3’ addresses for deposits. The redeem script in use with that is most definitely a multisig script of some kind, allowing secure, multi-party handling of deposited funds by the exchange.

What are atomic swaps and OTC markets?

P2SH support, the same technology implemented in Counterparty that makes payment channels possible, also makes on-chain “atomic swaps” possible.

With an atomic swap, two parties perform a special process of exchanging information that completes by the parties broadcasting several transactions that they both have signed. These transactions end up exchanging (i.e. “swapping”) some quantity of one asset from one party in exchange for another. This is done in a way where one party can’t cheat the other.

The use of atomic swaps can be useful to enable the use of things like over the counter (OTC) markets and dark pools. With either structure, a third party (often known as a bookrunner) would maintain a list of bids and offers between buyers and sellers of one asset for another, such as XCP and BTC. That list may be publically published, or not. Interested parties would contact the bookrunner and place buy and sell offers. The bookrunner would match buyers to sellers, who would then perform the trade themselves utilizing an atomic swap. Using this model, risk is greatly minimized, as the bookrunner does not have to hold any assets (and thus cannot run away with them).

The concept of an OTC market may sound antiquated but in reality they are a major boon to markets, especially for large holders who can then enter or exit a market or accumulate an asset without much price “slippage”, as would oftentimes occur on an exchange. In mainstream finance, OTC markets comprise over 40% of stock trading, as well as the vast majority of bond and derivative trading (source 1, source 2).

How do I start using all of this technology with Counterparty?

This technology is all in various stages of development, with some of it being complete (P2SH, for instance) and some in very early states on Counterparty (such as bidirectional payment channels and Lightning Network support).

We will be publishing guides for users and developers as the respective technology becomes available and matures. Until that point, feel free to check out the newest source code and ask questions on #dev on our official Slack chat.