Payment Channel (aka., State Channel)

Summary

A two-way pathway (aka., payment channel) is established between transacting parties to perform transactions off-chain while recording opening and final settlement transactions on the blockchain.

Context

A set of low-value payments (aka., micropayments) are to be made frequently, e.g., a small payment paid every time a WiFi service is used.

Problem

If a public blockchain is used, micro-payments are too expensive to make as the transaction fee might be higher than the monetary value within the transaction. Moreover, it takes time to achieve finality on a blockchain. Furthermore, as public blockchains have limited performance, transactions can take several minutes or even an hour to be committed on the blockchain. Therefore, how can frequent payments be processed without waiting for a long time and incurring high transaction fees?

Forces

  • Latency – It might take a long time to confirm a transaction on the blockchain, although users usually expect instantaneous settlement of payments.
  • Scalability – Blockchain has limited scalability because every bit of data is replicated across all nodes and kept permanently.
  • Cost – If a public blockchain is used, the transaction fee might be higher than the monetary value of the payment.

Solution

As seen in the following figure an off-chain, two-way pathway (aka., payment channel) can be established between two parties to handle frequently occurring transactions.

State channel pattern

State channel pattern

The following figure depicts the sequence of activities involved in a payment channel. First, establish a channel for payment (aka., payment channel) between two participants by getting one or both participants (e.g., buyer and seller) to lock up an agreed amount of money as security in a smart contract. Then the two parties can perform a sequence of micropayments between them while recording the transactions and corresponding balances off-chain. Similar to blockchain transactions, these transactions also need to be digitally signed by the transacting parties. Also, each intermediate transaction should carry a sequence number to correctly calculate the settlement balance and ensure no transaction is missed. Thus, the payment channel tracks micropayments, intermediate states/balances, and their authenticity off-chain. When the settlement is to be made or the payment channel is no longer needed, parties can submit the closing balances to the smart contract to update the on-chain states/balances. Finally, the smart contract returns the tokens as per the closing balance of each party.

Sequence diagram of payment channel.

 

In case of a dispute, digitally signed transactions recorded off-chain could be presented by one of the parties to the smart contract as evidence to resolve the dispute. The buyer and seller may also interchange the roles such that tokens flow both ways. Such off-chain channels could be generalised to exchange states for more general purposes other than monetary value.

Instead of waiting till the end of the lifetime of the payment channel, parties can also update on-chain balances/states from time to time. The frequency of transaction settlement depends on the use case, and the agreement between the parties. For example, in utility payments, Internet service providers or electricity companies can establish payment channels with their consumers for an agreed billing period like a month. As the consumer uses certain units of data or energy, the intermediate state is stored in the channel. At the end of the month, payment of that month’s could be settled on-chain.

Multiple pair-wise payment channels could be combined to form a network of channels. This enables a party to transact with all other parties in the network without establishing a pair-wise channel to each of them. Using multi-hop transaction routing within this network individual transactions can take place entirely off-chain. Only the final transaction that settles the payment for a given channel or set of channels is submitted to the blockchain.

The technology used to implement a state channel is specific to the blockchain platform. For example, Lightning network on the Bitcoin blockchain is a proposed implementation of Hashed Timelock Contracts (HTLCs) with bi-directional payment channels which allow secure payments across multiple peer-to-peer channels. A HTLC is a type of payment that use the features of Script, like hashlocks and timelocks, to require that the receiver of a payment acknowledges receiving the payment prior to a deadline by generating cryptographic proof.

Benefits

  • Latency – As the blockchain is not involved in every transaction, the off-chain transactions can be settled instantaneously. The delay could be in a fraction of a second than minutes of hours for a blockchain where we need to wait for the blockchain network to process the transaction, generate a new block with the transaction, reach consensus, and the desired number of confirmation blocks.
  • Throughput – The number of off-chain transactions that can be processed is not limited by the blockchain’s throughput, which depends on multiple factors such as block size, inter-block time, and transaction fee. Thus a much higher throughput can be achieved for off-chain transactions.
  • Privacy – Other than the settlement transaction(s), off-chain transactions do not show up in the public ledger. Thus, the detail of these intermediate off-chain transactions is not publicly visible.
  • Cost – If a public blockchain is used, only the final settlement transaction costs a transaction fee to be included in the blockchain. Off-chain transactions do not cost any money. Or in the context of a payment channel network, transactions may still pay a fee that is relatively low compared to its monitory value. For example, such networks typically charged a small percentage of the transacted amount.

Drawbacks

  • Data Integrity – The data integrity of the intermediate state of payment channels cannot be ensured because intermediate transactions are not stored on-chain and vulnerable to transaction malleability. However, disputes can be usually resolved by presenting all the intermediate transactions to the smart contract as evidence.
  • Liquidity – To establish a payment channel, money from one or both sides of the channel participants needs to be locked up in a smart contract for the lifetime of the payment channel. The liquidity of the channel participants is thereby reduced.
  • Trustworthiness – Off-chain micropayment transactions might not be as trustworthy as on-chain transactions because the micropayment transactions are not stored in an immutable data store. The intermediate state of payment channels might be lost after the payment channels are closed or it does not have sufficient availability.
  • Modifiability – A new wallet or extension to the existing wallet is needed to support the micropayment protocol.

Related patterns

  • Token registry pattern could be used by the smart contract to update the balance of the transacting parties at the time of payment channel initiation and settlement.
  • Hashed timelock contracts used in the atomic swap pattern can be used with payment channels.

Known uses

  • The Lightning network uses an off-chain protocol to enable micropayments of Bitcoin and several other cryptocurrencies. Micropayments are enabled by establishing a bidirectional payment channel by committing a funding transaction to the blockchain. This can be followed by a number of micropayment transactions that update the distribution of the funds within the channel without broadcasting transactions to the blockchain network. The payment channel can be closed by broadcasting the final version of the funding transaction to settle the payment.
  • The Raiden network on the Ethereum blockchain is a similar solution to the Lightning network. The basic idea is to avoid the consensus bottleneck by leveraging a network of off-chain payment channels that allow to secure transfer of monetary values. Smart contracts are used to deposit value into the payment channels.
  • Orinoco is another payment channel solution built on the Ethereum blockchain. In addition to payment channels, Orinoco also provides a payment hub for payment channel management. However, the payment hub introduces an extra party that needs to be trusted by both the sender and the recipient of the payment channel.
  • State channel on Ethereum and Gnosis Go offer a more generalized form of state channels that support exchanging states for general-purpose applications.