Lightning-Network

創建通道閃電網路時檢索地址

  • July 1, 2020

我在regtest中有兩個節點。第一個是:

$ l1-cli getinfo
{
  "id": "02c3f99e70c8da59e428dd119d36c0a1317e5cd85218a760355b5f9b4f822f6109",
  "alias": "ALICE",
  "color": "ddff06",
  "num_peers": 0,
  "num_pending_channels": 0,
  "num_active_channels": 0,
  "num_inactive_channels": 0,
  "address": [],
  "binding": [
     {
        "type": "ipv4",
        "address": "127.0.0.1",
        "port": 6060
     }
  ],
  "version": "v0.8.2-269-g6014644",
  "blockheight": 1,
  "network": "regtest",
  "msatoshi_fees_collected": 0,
  "fees_collected_msat": "0msat",
  "lightning-dir": "/tmp/l1-regtest/regtest"
}
$ l1-cli  dev-listaddrs
{
  "addresses": [
     {
        "keyidx": 0,
        "pubkey": "032173996ba61da17cf20a15bbd72bc6f1e6dcace0ffa55e0a8c4de6cb1fde0cd4",
        "p2sh": "2N5tGiR5EkCv8gMYAs9myqQ7R6Wkgkcc1L5",
        "p2sh_redeemscript": "0014a0064ff5b87368717f4d7f8f7d84f8aa41de10e9",
        "bech32": "bcrt1q5qryladcwd58zl6d078hmp8c4fqauy8fj4vsrv",
        "bech32_redeemscript": "a0064ff5b87368717f4d7f8f7d84f8aa41de10e9"
     }
  ]
}

第二個是:

$ l2-cli getinfo
{
  "id": "0214106517c1a81bf2dd8a3f37f6438e264ee17e270ed5c08110f584863f9bfa99",
  "alias": "BOB",
  "color": "021410",
  "num_peers": 0,
  "num_pending_channels": 0,
  "num_active_channels": 0,
  "num_inactive_channels": 0,
  "address": [],
  "binding": [
     {
        "type": "ipv4",
        "address": "127.0.0.1",
        "port": 9090
     }
  ],
  "version": "v0.8.2-269-g6014644",
  "blockheight": 1,
  "network": "regtest",
  "msatoshi_fees_collected": 0,
  "fees_collected_msat": "0msat",
  "lightning-dir": "/tmp/l2-regtest/regtest"
}
$ l2-cli  dev-listaddrs
{
  "addresses": [
     {
        "keyidx": 0,
        "pubkey": "03ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe62628",
        "p2sh": "2MsoPq7yYttm63u8yzRGgnYs44TTEe7z6ZS",
        "p2sh_redeemscript": "001463550e0be42780fef27416d022943739cfd06423",
        "bech32": "bcrt1qvd2suzlyy7q0aun5zmgz99ph888aqeprvsg6sw",
        "bech32_redeemscript": "63550e0be42780fef27416d022943739cfd06423"
     }
  ]
}

Alice 有 50 個比特幣bcrt1q5qryladcwd58zl6d078hmp8c4fqauy8fj4vsrv Alice 連接到 BOB

$ l1-cli connect 0214106517c1a81bf2dd8a3f37f6438e264ee17e270ed5c08110f584863f9bfa99 127.0.0.1:9090
{
  "id": "0214106517c1a81bf2dd8a3f37f6438e264ee17e270ed5c08110f584863f9bfa99",
  "features": "02aaa2"
}

Alice 用 0.05 個比特幣 = 50000000000msat 創建一個通道

l1-cli fundchannel 0214106517c1a81bf2dd8a3f37f6438e264ee17e270ed5c08110f584863f9bfa99 5000000000msat                                │
{                                                                                                                                     │
  "tx": "02000000000101e5fd718b998672b2b38747f010676fc1300b8cb063649e8a922637941bbce6060000000000feffffff02404b4c0000000000220020b7e3│
dec987315eaf340075d2a06fb92961f7e6578285d7c2e418da449c17fd9d26a6b9290100000016001406d177ca4906c71db5d4240e31468ad6d93f3989024730440220│
4b35306bb23701b24102b3933289cd1e7a0b67c875d965c337cd7357946f1b9e022031f98d8f318d2b72d8f3621c2005378a78a103a6169536b940e31f51e05c8d2f01│
21032173996ba61da17cf20a15bbd72bc6f1e6dcace0ffa55e0a8c4de6cb1fde0cd400000000",                                                        │
  "txid": "dbb8a5f98d465c6cf438b8166a438a09c8118f2b62960ef99403be00e1ced8a6",                                                        │
  "channel_id": "a6d8cee100be0394f90e96622b8f11c8098a436a16b838f46c5c468df9a5b8db"                                                   │
} 

現在我檢查資金交易

bitcoin-cli getrawtransaction dbb8a5f98d465c6cf438b8166a438a09c8118f2b62960ef99403be00e1ced8a6 2

"vout": [
   {
     "value": 0.05000000,
     "n": 0,
     "scriptPubKey": {
       "asm": "0 b7e3dec987315eaf340075d2a06fb92961f7e6578285d7c2e418da449c17fd9d",
       "hex": "0020b7e3dec987315eaf340075d2a06fb92961f7e6578285d7c2e418da449c17fd9d",
       "reqSigs": 1,
       "type": "witness_v0_scripthash",
       "addresses": [
         "bcrt1qkl3aajv8x9027dqqwhf2qmae99sl0ejhs2za0shyrrdyf8qhlkwsgphj96"
       ]
     }
   },
   {
     "value": 49.94999846,
     "n": 1,
     "scriptPubKey": {
       "asm": "0 06d177ca4906c71db5d4240e31468ad6d93f3989",
       "hex": "001406d177ca4906c71db5d4240e31468ad6d93f3989",
       "reqSigs": 1,
       "type": "witness_v0_keyhash",
       "addresses": [
         "bcrt1qqmgh0jjfqmr3mdw5ys8rz3526mvn7wvf5pklnl"
       ]
     }
   }
 ],

該地址bcrt1qkl3aajv8x9027dqqwhf2qmae99sl0ejhs2za0shyrrdyf8qhlkwsgphj96是 Segwit 多重簽名。現在如果我在 l1 中檢查 addr 我可以看到

$ l1-cli  dev-listaddrs
{
  "addresses": [
     {
        "keyidx": 0,
        "pubkey": "032173996ba61da17cf20a15bbd72bc6f1e6dcace0ffa55e0a8c4de6cb1fde0cd4",
        "p2sh": "2N5tGiR5EkCv8gMYAs9myqQ7R6Wkgkcc1L5",
        "p2sh_redeemscript": "0014a0064ff5b87368717f4d7f8f7d84f8aa41de10e9",
        "bech32": "bcrt1q5qryladcwd58zl6d078hmp8c4fqauy8fj4vsrv",
        "bech32_redeemscript": "a0064ff5b87368717f4d7f8f7d84f8aa41de10e9"
     },
     {
        "keyidx": 1,
        "pubkey": "03841e0be7af4049e44818cfab5248128806e22103b6177a0915e18fdb683875c8",
        "p2sh": "2N6aAJa7kbCVFx8cNMjRskR2beACY6AaPBA",
        "p2sh_redeemscript": "00146e289f089c56abb767fecd3e189489eb619ffa74",
        "bech32": "bcrt1qdc5f7zyu264mwel7e5lp39yfadsel7n5hnp04r",
        "bech32_redeemscript": "6e289f089c56abb767fecd3e189489eb619ffa74"
     },
     {
        "keyidx": 2,
        "pubkey": "020f91c2b34bc3a8cf3b56279fb7cae5a24ed3fb571cdfca2c35064e1d17d57b18",
        "p2sh": "2N5WmmNYJCr8eK2nJvf8N8QwV9zj9Lxree2",
        "p2sh_redeemscript": "0014751389f7ad7f0426e8fed655c0e40de0c06c3781",
        "bech32": "bcrt1qw5fcnaad0uzzd6876e2upeqdurqxcdup20v8lj",
        "bech32_redeemscript": "751389f7ad7f0426e8fed655c0e40de0c06c3781"
     },
     {
        "keyidx": 3,
        "pubkey": "03c2ecd5456ebf61168ef9536da277772c308798a5635f83e9ed60233bdf620958",
        "p2sh": "2N1rzfyGXpbPPjr7FhZsvaaaFiifvrxiEyd",
        "p2sh_redeemscript": "001478624d2bcd45fe2adf8c479a171634209adac754",
        "bech32": "bcrt1q0p3y627dghlz4huvg7dpw935yzdd4365xje7v5",
        "bech32_redeemscript": "78624d2bcd45fe2adf8c479a171634209adac754"
     },
     {
        "keyidx": 4,
        "pubkey": "033a1f02a7c19cba180defc087fdc0b48636a3d61adc4eb9d5ca1e8e6f21b12284",
        "p2sh": "2MvZeMyFSN4UWtYnTEBcTdtCjBi8kNVKKum",
        "p2sh_redeemscript": "001406d177ca4906c71db5d4240e31468ad6d93f3989",
        "bech32": "bcrt1qqmgh0jjfqmr3mdw5ys8rz3526mvn7wvf5pklnl",
        "bech32_redeemscript": "06d177ca4906c71db5d4240e31468ad6d93f3989"
     },
     {
        "keyidx": 5,
        "pubkey": "03c0032537904220bd32be2f8431597f4a49b23300face9212a49b469470b99ec3",
        "p2sh": "2NCARQgcBZzmYK6CfvTW1XMGXv2pddZnrxh",
        "p2sh_redeemscript": "0014a22f05c2da4a52fbef434d67b1fda4c228990145",
        "bech32": "bcrt1q5ghstsk6fff0hm6rf4nmrldycg5fjq29xt5gpx",
        "bech32_redeemscript": "a22f05c2da4a52fbef434d67b1fda4c228990145"
     }
  ]
}

在 l2 我可以看到

$ l2-cli  dev-listaddrs
{
  "addresses": [
     {
        "keyidx": 0,
        "pubkey": "03ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe62628",
        "p2sh": "2MsoPq7yYttm63u8yzRGgnYs44TTEe7z6ZS",
        "p2sh_redeemscript": "001463550e0be42780fef27416d022943739cfd06423",
        "bech32": "bcrt1qvd2suzlyy7q0aun5zmgz99ph888aqeprvsg6sw",
        "bech32_redeemscript": "63550e0be42780fef27416d022943739cfd06423"
     },
     {
        "keyidx": 1,
        "pubkey": "02e28aaf512284c08336782769b9af1eb816970f99b6fadb2faa5c0d65ddc24d7e",
        "p2sh": "2MvpYKgQ7hY4q86WSn5FQALFjezAtxuyvBM",
        "p2sh_redeemscript": "00143c67dd58505ad35c30dc19db622659dfc543566e",
        "bech32": "bcrt1q83na6kzsttf4cvxur8dkyfjemlz5x4nwxq9kpz",
        "bech32_redeemscript": "3c67dd58505ad35c30dc19db622659dfc543566e"
     }
  ]
}

為什麼我在 l1 有多個地址?我怎樣才能得到bcrt1qkl3aajv8x9027dqqwhf2qmae99sl0ejhs2za0shyrrdyf8qhlkwsgphj96

我嘗試使用 l1 的公鑰和 l2 的公鑰,但沒有幸運

$  bitcoin-cli createmultisig 2 '["032173996ba61da17cf20a15bbd72bc6f1e6dcace0ffa55e0a8c4de6cb1fde0cd4","03ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe62628"]' "bech32"
bitcoin-cli createmultisig 2 '["03841e0be7af4049e44818cfab5248128806e22103b6177a0915e18fdb683875c8","03ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe62628"]' "bech32"
bitcoin-cli createmultisig 2 '["020f91c2b34bc3a8cf3b56279fb7cae5a24ed3fb571cdfca2c35064e1d17d57b18","03ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe62628"]' "bech32"
bitcoin-cli createmultisig 2 '["03c2ecd5456ebf61168ef9536da277772c308798a5635f83e9ed60233bdf620958","03ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe62628"]' "bech32"
bitcoin-cli createmultisig 2 '["033a1f02a7c19cba180defc087fdc0b48636a3d61adc4eb9d5ca1e8e6f21b12284","03ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe62628"]' "bech32"
bitcoin-cli createmultisig 2 '["03c0032537904220bd32be2f8431597f4a49b23300face9212a49b469470b99ec3","03ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe62628"]' "bech32"
{
 "address": "bcrt1qdynj6dv4zq03ldfregnl3wwppt4gu0wm8xhn7gma48mg3s8vxswsau88sc",
 "redeemScript": "5221032173996ba61da17cf20a15bbd72bc6f1e6dcace0ffa55e0a8c4de6cb1fde0cd42103ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe6262852ae"
}
{
 "address": "bcrt1q5kvw3x3gafcg83w6klfrdtdta6dmptc35fyxty58kzr7wzd3n83q46t7x6",
 "redeemScript": "522103841e0be7af4049e44818cfab5248128806e22103b6177a0915e18fdb683875c82103ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe6262852ae"
}
{
 "address": "bcrt1q5fg097ujz8cl0hum4xt9x6mygzqhlvgkggkwqdlv7rvj8n0npk6qnzslpz",
 "redeemScript": "5221020f91c2b34bc3a8cf3b56279fb7cae5a24ed3fb571cdfca2c35064e1d17d57b182103ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe6262852ae"
}
{
 "address": "bcrt1qhzj0jgl56uatnxdzhwczrf08ku9a6c7x7fjldsnrkam75evlzywsn4ww6w",
 "redeemScript": "522103c2ecd5456ebf61168ef9536da277772c308798a5635f83e9ed60233bdf6209582103ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe6262852ae"
}
{
 "address": "bcrt1qsjm7zc0rhpzjmrldht7rxhp0y5ldu7c53da0fyr2jq3l9u03lz3q47r3r7",
 "redeemScript": "5221033a1f02a7c19cba180defc087fdc0b48636a3d61adc4eb9d5ca1e8e6f21b122842103ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe6262852ae"
}
{
 "address": "bcrt1qgsp7ltzlq9qcqmqr2eqd5h8zm87ch9zfdfj256nzsuk4ys2nc4asr0sqxk",
 "redeemScript": "522103c0032537904220bd32be2f8431597f4a49b23300face9212a49b469470b99ec32103ac7ca112d8459dd119e83be0242f7f9f8e3c0b44286cb262d84aa3d99fe6262852ae"
}

為什麼我在 l1 有多個地址?

也許你探勘了一些區塊來啟動頻道?

我怎樣才能得到bcrt1qkl3aajv8x9027dqqwhf2qmae99sl0ejhs2za0shyrrdyf8qhlkwsgphj96

正如我在您關於使用 C-lightning 派生密鑰的問題中詳述的那樣,lightningd針對不同目的使用不同的派生方法。

您正在使用的(僅限開發人員)RPC 命令列出用作“鏈上錢包”的 BIP32 樹中的地址(newaddr例如,用於生成帶有或用於通道聲明交易的地址)。

為了檢查與通道相關的事務,您可以使用該listtransactions命令。引用幫助:

返回錢包中跟踪的交易。這包括與渠道相關的存款、取款和交易。一筆交易可能有多種類型,例如,如果一筆交易關閉通道並將資金返還給錢包,則該筆交易可能既是平倉又是存款。


編輯:跟進評論中的問題。@MonkeyUser 問:

是的,但在那種情況下,我想了解如何bcrt1qkl3aajv8x9027dqqwhf2qmae99sl0ejhs2za0shyrrdyf8qhlkwsgphj96生成。使用了哪些公鑰?謝謝

在資助過程中,同行向我們發送消息 [resp. 我們向對等方發送一條消息] 告訴“嘿,我想用這個配置打開一個頻道”。資金公鑰是此配置的一部分。

然後我們回應[resp。對等方響應] 並顯示一條消息,告訴您“好的,這是我的配置。請務必尊重它,否則我將關閉您的頻道!”。第二個資金公鑰是此消息**(*)**的一部分。

無論我們是資金方還是出資方,lightningd都會使用“ funding_basepoint”公鑰作為我們的資金公鑰來建構資金交易的 P2WSH 多重簽名。

基點來自通道的確定性資訊,如下所示:

channel_seed = hkdf_sha256(hkdf_sha256(hsm_secret, salt=NULL, info="peer seed"), salt=peer_id | dbid, info="per-peer seed")
[funding, revocation, payment, htlc, delayed, shaseed] = expanded_hkdf_sha256(channel_seed, salt=NULL, info="c-lightning")

**(*)**事實上,我們用這個消息交換了一大堆公鑰,更具體地說是“基點”。這些用於派生不同操作(撤銷、htlcs、支付、延遲支付等)所需的所有密鑰。

引用自:https://bitcoin.stackexchange.com/questions/96749