Skip to content

Recipe: Initialising a simple state channel

Liam Horne edited this page Jul 20, 2017 · 5 revisions

Warning: still under construction

How to safely initialise a simple fully abstracted state channel with a single payment sub-channel contained inside of it (ignores some incentive compatibility requirements that would aid performance).

You will need:

An adjudicator factory, a nonce comparer, a bulletin board to handle counterfactual addressing, a call library to handle insertion of addresses into counterfactual calls, and a set of participants A,B,.. who will participate in the channel.

Steps:

  1. Create proxy contracts for A,B,...
  2. Create the Unanimous Consent contract, passing in the proxies from step 1 as the participants.
  3. Counterfactually instantiate the lock adjudicator (from here on all calls/instantiations should require the lock adjudicator to still have empty state/nonce of "0").
  4. Counterfactually instantiate the payment channel adjudicator.
  5. Counterfactually call the payment channel adjudicator and update its state to [nonce, A's initial intended deposit, 0, ...]
  6. Counterfactually make a lookup of the payment channel adjudicator's state, ensure that it's frozen, read the array, and pay out each respective value's worth in the array to A,B,...
  7. A can now safely deposit their initial amount on-chain.
  8. Repeat steps 5 and 7 for B,... with the successive slots in the payment channel adjudicator state array.
  9. The payment subchannel is now configured! To send money between participants, sign commitments to calls that increment the payment channel adjudicator nonce and adjust the array values to reflect the intended transfer.