Skip to content

Instantly share code, notes, and snippets.

@johnta0
Created August 11, 2018 09:50
Show Gist options
  • Save johnta0/f9538530fb200d96e579c468cc13a940 to your computer and use it in GitHub Desktop.
Save johnta0/f9538530fb200d96e579c468cc13a940 to your computer and use it in GitHub Desktop.
Lightning Network におけるオフチェーントランザクションの構造

Lightning Network では、はじめにチャネルを開く際 Funding transaction によってマルチシグアドレスにデポジットし、そこから分配するトランザクションを更新・無効化していくことによってマイクロペイメントを行う。

この記事では、Funding transaction の output と、Commitment transaction(状態を更新するためのトランザクション)の構造について書く。

transaction input と output のオーダー

BIP69 で定義されたような Lexicographic な順番になっている。

Segwit

Lightning Network のトランザクションには基本的に SegWit(P2WSH)が用いられる。

Funding Transactin Output

funding transaction の redeemScript は以下である。通常の 2-of-2 のマルチシグだ。

OP_2 <pubkey1> <pubkey2> OP_2 OP_CHECKMULTISIG

Commitment Transaction

条件は以下の通り

  • version: 2 であること。version 2 は BIP68(相対時間でロックできるTx) が有効であることを示す。
  • txin[0]
    • outpoint: funding transacrtion の txidoutput_index
    • script bytes: 0
    • witness: OP_0 <signature_for_pubkey1> <signature_for_pubkey2>

48ビットの commitment transaction number は XOR によって目くらましされる。

Commitment Transaction Outputs

参考

https://github.com/lightningnetwork/lightning-rfc/blob/master/03-transactions.md https://techmedia-think.hatenablog.com/entry/2016/03/28/151533 https://techmedia-think.hatenablog.com/entry/2016/05/09/181924

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment