Author: Pierre 2015-08-20 18:36:09
Published on: 2015-08-20T18:36:09+00:00
Rusty Russell, a contributor to the Elements Project has created a state machine for the Lightning Network protocol. The protocol state alternates between high and low priority which resolves conflicts if both parties attempt to make an update at once. PKT_CLOSE is allowed at any time and the protocol should handle re-transmits. The state machine has been tested thoroughly and can be found on the "state" branch of Rusty's GitHub account. The code snippet defines two enums - `enum state` and `enum state_input`. The `enum state` contains various states of a Lightning Network channel, including Opening, Normal Update Loop, and Closing. There are several stages to the protocol including Opening, Normal Update Loop, and Closing. The `enum state_input` contains various inputs to the state machine, including `PKT_OPEN`, `PKT_OPEN_ANCHOR`, `PKT_OPEN_COMMIT_SIG`, `PKT_OPEN_COMPLETE`, `PKT_UPDATE`, `PKT_UPDATE_ADD_HTLC`, `PKT_UPDATE_ACCEPT`, `PKT_UPDATE_SIGNATURE`, `PKT_UPDATE_COMPLETE`, `PKT_UPDATE_COMPLETE_HTLC`, `PKT_UPDATE_TIMEDOUT_HTLC`, `PKT_UPDATE_ROUTEFAIL_HTLC`, `PKT_UPDATE_DECLINE_HTLC`, `PKT_CLOSE`, `PKT_CLOSE_COMPLETE`, `PKT_CLOSE_ACK`, `PKT_ERROR`, `INPUT_NONE`, `BITCOIN_ANCHOR_DEPTHOK`, `BITCOIN_ANCHOR_TIMEOUT`, `BITCOIN_ANCHOR_UNSPENT`, `BITCOIN_ANCHOR_OURCOMMIT_DELAYPASSED`, `BITCOIN_ANCHOR_THEIRSPEND`, `BITCOIN_ANCHOR_OTHERSPEND`, `BITCOIN_SPEND_THEIRS_DONE`, `BITCOIN_SPEND_OURS_DONE`, `BITCOIN_STEAL_DONE`, `BITCOIN_CLOSE_DONE`, `INPUT_CLOSE_COMPLETE_TIMEOUT`, `CMD_SEND_UPDATE`, `CMD_SEND_HTLC_UPDATE`, `CMD_SEND_HTLC_COMPLETE`, `CMD_SEND_HTLC_TIMEDOUT`, `CMD_SEND_HTLC_ROUTEFAIL`, and `CMD_CLOSE`.The code snippet also includes comments explaining the various combinations of states that the state machine could be waiting for, as well as explanations for each input.
Updated on: 2023-05-23T19:47:07.676040+00:00