Difference between revisions of "Payment Channels"

Line 37: Line 37:
  
 
Where:
 
Where:
* S<sub>v</sub> is the Viewer's signature
+
* S<sub>vn</sub> is the Viewer's nth iteration of the channel signature
 
* P<sub>v</sub> is the Viewer's pubkey
 
* P<sub>v</sub> is the Viewer's pubkey
 
* H<sub>v</sub> is the Viewer's PKH
 
* H<sub>v</sub> is the Viewer's PKH
  
* S<sub>p</sub> is the service provider's signature
+
* S<sub>pn</sub> is the service provider's nth iteration of the channel signature
 
* P<sub>p</sub> is the service provider's pubkey
 
* P<sub>p</sub> is the service provider's pubkey
* H<sub>P</sub> is the service provider's PKH
+
* H<sub>p</sub> is the service provider's PKH
 
* H<sub>c0</sub> is the hash of the merkle root of the content being selected
 
* H<sub>c0</sub> is the hash of the merkle root of the content being selected
* H<sub>cn</sub> is the hash of each content frame with H<sub>c1<\sub> being the first frame data
+
* H<sub>cn</sub> is the hash of each content frame with H<sub>c1<\sub> being the hash of the first frame
* P<sub>f</sub> is the PKH the user pays to in order to prematurely end or pause the stream
+
* C<sub>n</sub> is the content frame with C<sub>1<\sub> being the first frame data
 +
* H<sub>fm</sub> is the hash of a message the user can trigger to prematurely end or pause the stream
 +
* F<sub>m</sub> is a message that the provider uses to end the stream
  
The sequence no. for the input script being spent is set to 1 and an ntimelock setting of (say) 48 hours in the future is set
+
The sequence no. for the input being spent is still 1
  
The transaction pays out two scripts as as follows:
+
The transaction iterates between the two scripts as as follows:
 +
 
 +
==Iteration 1==
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 61: Line 65:
 
| 1
 
| 1
 
| Iteration 1: Content Request
 
| Iteration 1: Content Request
| H<sub>P<\sub> CHECKSIGVERIFY H<sub>c0<\sub> SHA256 EQUALVERIFY P<sub>v<\sub> CHECKSIGVERIFY
+
| H<sub>c0</sub> DROP DUP HASH160 H<sub>p</sub> EQUALVERIFY CHECKSIGVERIFY EQUALVERIFY DUP HASH160 H<sub>v</sub> EQUALVERIFY CHECKSIG
 
| Price of first frame
 
| Price of first frame
 
|-
 
|-
Line 70: Line 74:
 
|}
 
|}
  
The transaction pays out the price of the first frame to the service provider and the remainder is returned to the viewer as change.
+
The Viewer also supplies the following input script:
 +
 
 +
*''S<sub>v0</sub> P<sub>v</sub>''
 +
 
 +
which would allow the service provider to countersign the tx and settle on the network, guaranteeing payment for the first frame.
 +
 
 +
The transaction pays out the price of the first frame to the service provider and the remainder is returned to the viewer as change. If the viewer cancels their session without watching, the transaction can still be processed on the network
 +
 
 +
===Step 4===
 +
The provider responds with a new version of the transaction that modifies the output as shown:
  
The provider responds with a new version of the transaction as shown:
 
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 82: Line 94:
 
| 1
 
| 1
 
| Iteration 2: First frame
 
| Iteration 2: First frame
| H<sub>P</sub> CHECKSIGVERIFY H<sub>c0</sub> SHA256 EQUALVERIFY P<sub>v</sub> CHECKSIGVERIFY
+
| ''SHA256 H<sub>c1</sub> EQUALVERIFY'' DUP HASH160 H<sub>p</sub> EQUALVERIFY CHECKSIGVERIFY EQUALVERIFY DUP HASH160 H<sub>v</sub> EQUALVERIFY CHECKSIG
| Price of first frame
+
| Price of second frame
 +
|-
 +
| 2
 +
| Change
 +
| Viewer's change script
 +
| Change amount
 +
|}
 +
In this iteration, they sign to indicate they have received the first frame and provide the streaming service with payment for the second frame. This can be optimized for each service provider's fee model.
 +
 
 +
They also provide a new signature ''S<sub>p0</sub>'' for this output, allowing the user to countersign should they need to close the channel.
 +
 
 +
===Step 5===
 +
The viewer iterates the transaction as shown:
 +
 
 +
{| class="wikitable"
 +
|-
 +
|! Script No.
 +
|! Purpose
 +
|! Script
 +
|! Amount
 +
|-
 +
| 1
 +
| Iteration 2: First frame
 +
| SHA256 ''H<sub>c2</sub>'' EQUALVERIFY DUP HASH160 H<sub>p</sub> EQUALVERIFY CHECKSIGVERIFY EQUALVERIFY DUP HASH160 H<sub>v</sub> EQUALVERIFY CHECKSIG
 +
| Price of second frame
 +
|-
 +
| 2
 +
| Change
 +
| Viewer's change script
 +
| Change amount
 +
|}
 +
As in the previous iteration, they sign to indicate they have received the frame and provide the streaming service with payment for the next frame. This can be optimized for each service provider's fee model.
 +
 
 +
They also provide a new signature for this output, ''S<sub>v1</sub>'', allowing the service provider to countersign should they need to close the channel. In this example, the keypairs being used don't need to change for each iteration, but they could.
 +
 
 +
===Step N===
 +
The user can request that the provider close the channel. Streams can also be paused, or take place at any framerate or even use larger transactions to move chunks at a time.
 +
In this case the user is deciding to close it.
 +
 
 +
{| class="wikitable"
 +
|-
 +
|! Script No.
 +
|! Purpose
 +
|! Script
 +
|! Amount
 +
|-
 +
| 1
 +
| Iteration 2: First frame
 +
| SHA256 ''H<sub>fm</sub>'' EQUALVERIFY DUP HASH160 H<sub>p</sub> EQUALVERIFY CHECKSIGVERIFY EQUALVERIFY DUP HASH160 H<sub>v</sub> EQUALVERIFY CHECKSIG
 +
| Price of second frame
 
|-
 
|-
 
| 2
 
| 2
Line 90: Line 151:
 
| Change amount
 
| Change amount
 
|}
 
|}
 +
 +
The user puts the finish message hash at the front of the output. The streaming provider sees this and knows the customer wants to close the channel.
 +
The user provide a new signature for this output, ''S<sub>vn</sub>''. This allows the streaming service provider to finalise the channel.
  
  
 +
===Step N+1===
 +
The user can request that the provider close the channel. Streams can also be paused, or take place at any framerate or even use larger transactions to move chunks at a time.
 +
In this case the user is deciding to close it.
  
 +
The provider signs the transaction and solves the puzzle with the following script:
  
====INPUT SCRIPT====
+
''S<sub>vn</sub> P<sub>v</sub> S<sub>pn</sub> P<sub>p</sub> F<sub>m</sub>''
1: S<sub>v</sub> P<sub>v</sub> S<sub>p</sub> P<sub>p</sub>
 
The interpreter add an [[OP_CODESEPARATOR]] after P<sub>p<\sub> to terminate the input.
 
  
<finalization_message_hash>
+
In this way rather than closing the transaction with a potentially large blob of content data at the front, just a short code need be used.

Revision as of 11:50, 16 October 2019

Payment channels are peer to peer channels that can be used to exchange information, money and more.

Properties

Payment channels have the following properties:

  • Payment channels can be opened and closed arbitrarily
  • You do not need do an on-chain transaction to open a payment channel (but you can have one)
  • Payment channels can be private or public
  • You can have many peers in a channel
  • You can add and remove peers from a channel
  • Payment channels are data conduits
  • On-chain payments close channels

Connecting and using payment channels

  1. User peer connects to provider peer via known endpoint
  2. Provider gives peer new endpoint (can be CGA) and Tx template
  3. User peer completes TX by adding funding inputs
  4. Provider supplies data and information to access next item (e.g. movie frames)
  5. Peers keep track of channel state using Sequence

Example - Streaming Movie

The following goes through the sequence of opening, using and closing a payment channel for the purposes of serving streamed content.

STEP 1

User browses catalog for titles to watch. Content can be on-chain or off-chain, but should be provably linked to a hash of the overall data. This hash can be the merkle root of all of the chunks that will be served to the user. The user sends this hash to the service provider to select the content.

Step 2

User selects the content. At this point, there can be a few ways to manage the channel:

  • In public via mining network
  • In private with pre-funded UTXO per channel
  • In private with separate channels for content purchase and service delivery per user

Step 3

In this example, peers will use a timelocked UTXO in a public channel managed by miners to serve the content. For the sake of this example we will assume a single UTXO is being used. This UTXO goes into a double spend monitoring pool.

The viewer sends a transaction with the following output script to the provider to initiate the channel:

Where:

  • Svn is the Viewer's nth iteration of the channel signature
  • Pv is the Viewer's pubkey
  • Hv is the Viewer's PKH
  • Spn is the service provider's nth iteration of the channel signature
  • Pp is the service provider's pubkey
  • Hp is the service provider's PKH
  • Hc0 is the hash of the merkle root of the content being selected
  • Hcn is the hash of each content frame with Hc1<\sub> being the hash of the first frame
  • Cn is the content frame with C1<\sub> being the first frame data
  • Hfm is the hash of a message the user can trigger to prematurely end or pause the stream
  • Fm is a message that the provider uses to end the stream

The sequence no. for the input being spent is still 1

The transaction iterates between the two scripts as as follows:

Iteration 1

! Script No. ! Purpose ! Script ! Amount
1 Iteration 1: Content Request Hc0 DROP DUP HASH160 Hp EQUALVERIFY CHECKSIGVERIFY EQUALVERIFY DUP HASH160 Hv EQUALVERIFY CHECKSIG Price of first frame
2 Change Viewer's change script Change amount

The Viewer also supplies the following input script:

  • Sv0 Pv

which would allow the service provider to countersign the tx and settle on the network, guaranteeing payment for the first frame.

The transaction pays out the price of the first frame to the service provider and the remainder is returned to the viewer as change. If the viewer cancels their session without watching, the transaction can still be processed on the network

Step 4

The provider responds with a new version of the transaction that modifies the output as shown:

! Script No. ! Purpose ! Script ! Amount
1 Iteration 2: First frame SHA256 Hc1 EQUALVERIFY DUP HASH160 Hp EQUALVERIFY CHECKSIGVERIFY EQUALVERIFY DUP HASH160 Hv EQUALVERIFY CHECKSIG Price of second frame
2 Change Viewer's change script Change amount

In this iteration, they sign to indicate they have received the first frame and provide the streaming service with payment for the second frame. This can be optimized for each service provider's fee model.

They also provide a new signature Sp0 for this output, allowing the user to countersign should they need to close the channel.

Step 5

The viewer iterates the transaction as shown:

! Script No. ! Purpose ! Script ! Amount
1 Iteration 2: First frame SHA256 Hc2 EQUALVERIFY DUP HASH160 Hp EQUALVERIFY CHECKSIGVERIFY EQUALVERIFY DUP HASH160 Hv EQUALVERIFY CHECKSIG Price of second frame
2 Change Viewer's change script Change amount

As in the previous iteration, they sign to indicate they have received the frame and provide the streaming service with payment for the next frame. This can be optimized for each service provider's fee model.

They also provide a new signature for this output, Sv1, allowing the service provider to countersign should they need to close the channel. In this example, the keypairs being used don't need to change for each iteration, but they could.

Step N

The user can request that the provider close the channel. Streams can also be paused, or take place at any framerate or even use larger transactions to move chunks at a time. In this case the user is deciding to close it.

! Script No. ! Purpose ! Script ! Amount
1 Iteration 2: First frame SHA256 Hfm EQUALVERIFY DUP HASH160 Hp EQUALVERIFY CHECKSIGVERIFY EQUALVERIFY DUP HASH160 Hv EQUALVERIFY CHECKSIG Price of second frame
2 Change Viewer's change script Change amount

The user puts the finish message hash at the front of the output. The streaming provider sees this and knows the customer wants to close the channel. The user provide a new signature for this output, Svn. This allows the streaming service provider to finalise the channel.


Step N+1

The user can request that the provider close the channel. Streams can also be paused, or take place at any framerate or even use larger transactions to move chunks at a time. In this case the user is deciding to close it.

The provider signs the transaction and solves the puzzle with the following script:

Svn Pv Spn Pp Fm

In this way rather than closing the transaction with a potentially large blob of content data at the front, just a short code need be used.