bolt2

Lightning peer protocol, per BOLT #2 (docs.ppad.tech/bolt2).
git clone git://git.ppad.tech/bolt2.git
Log | Files | Refs | README | LICENSE

Messages.hs (20817B)


      1 {-# OPTIONS_HADDOCK prune #-}
      2 {-# LANGUAGE BangPatterns #-}
      3 {-# LANGUAGE DeriveGeneric #-}
      4 {-# LANGUAGE DerivingStrategies #-}
      5 
      6 -- |
      7 -- Module: Lightning.Protocol.BOLT2.Messages
      8 -- Copyright: (c) 2025 Jared Tobin
      9 -- License: MIT
     10 -- Maintainer: Jared Tobin <jared@ppad.tech>
     11 --
     12 -- Message types for BOLT #2 peer protocol.
     13 --
     14 -- This module defines per-message record types and a top-level Message
     15 -- sum type for all BOLT #2 messages.
     16 
     17 module Lightning.Protocol.BOLT2.Messages (
     18   -- * Message type codes
     19     MsgType(..)
     20   , msgTypeWord
     21 
     22   -- * Top-level message type
     23   , Message(..)
     24 
     25   -- * Channel establishment v1
     26   , OpenChannel(..)
     27   , AcceptChannel(..)
     28   , FundingCreated(..)
     29   , FundingSigned(..)
     30   , ChannelReady(..)
     31 
     32   -- * Channel establishment v2
     33   , OpenChannel2(..)
     34   , AcceptChannel2(..)
     35   , TxAddInput(..)
     36   , TxAddOutput(..)
     37   , TxRemoveInput(..)
     38   , TxRemoveOutput(..)
     39   , TxComplete(..)
     40   , TxSignatures(..)
     41   , TxInitRbf(..)
     42   , TxAckRbf(..)
     43   , TxAbort(..)
     44 
     45   -- * Channel close
     46   , Stfu(..)
     47   , Shutdown(..)
     48   , ClosingSigned(..)
     49   , ClosingComplete(..)
     50   , ClosingSig(..)
     51 
     52   -- * Normal operation
     53   , UpdateAddHtlc(..)
     54   , UpdateFulfillHtlc(..)
     55   , UpdateFailHtlc(..)
     56   , UpdateFailMalformedHtlc(..)
     57   , CommitmentSigned(..)
     58   , RevokeAndAck(..)
     59   , UpdateFee(..)
     60 
     61   -- * Reestablishment
     62   , ChannelReestablish(..)
     63 
     64   -- * Witness data
     65   , Witness(..)
     66   ) where
     67 
     68 import Control.DeepSeq (NFData)
     69 import qualified Data.ByteString as BS
     70 import Data.Word (Word8, Word16, Word32, Word64)
     71 import GHC.Generics (Generic)
     72 import Lightning.Protocol.BOLT1 (TlvStream)
     73 import Lightning.Protocol.BOLT2.Types
     74 
     75 -- Message type codes ----------------------------------------------------------
     76 
     77 -- | BOLT #2 message type codes.
     78 data MsgType
     79   = MsgStfu                    -- ^ 2
     80   | MsgOpenChannel             -- ^ 32
     81   | MsgAcceptChannel           -- ^ 33
     82   | MsgFundingCreated          -- ^ 34
     83   | MsgFundingSigned           -- ^ 35
     84   | MsgChannelReady            -- ^ 36
     85   | MsgShutdown                -- ^ 38
     86   | MsgClosingSigned           -- ^ 39
     87   | MsgClosingComplete         -- ^ 40
     88   | MsgClosingSig              -- ^ 41
     89   | MsgOpenChannel2            -- ^ 64
     90   | MsgAcceptChannel2          -- ^ 65
     91   | MsgTxAddInput              -- ^ 66
     92   | MsgTxAddOutput             -- ^ 67
     93   | MsgTxRemoveInput           -- ^ 68
     94   | MsgTxRemoveOutput          -- ^ 69
     95   | MsgTxComplete              -- ^ 70
     96   | MsgTxSignatures            -- ^ 71
     97   | MsgTxInitRbf               -- ^ 72
     98   | MsgTxAckRbf                -- ^ 73
     99   | MsgTxAbort                 -- ^ 74
    100   | MsgUpdateAddHtlc           -- ^ 128
    101   | MsgUpdateFulfillHtlc       -- ^ 130
    102   | MsgUpdateFailHtlc          -- ^ 131
    103   | MsgCommitmentSigned        -- ^ 132
    104   | MsgRevokeAndAck            -- ^ 133
    105   | MsgUpdateFee               -- ^ 134
    106   | MsgUpdateFailMalformedHtlc -- ^ 135
    107   | MsgChannelReestablish      -- ^ 136
    108   deriving stock (Eq, Ord, Show, Generic)
    109 
    110 instance NFData MsgType
    111 
    112 -- | Get the numeric type code for a message type.
    113 msgTypeWord :: MsgType -> Word16
    114 msgTypeWord MsgStfu                    = 2
    115 msgTypeWord MsgOpenChannel             = 32
    116 msgTypeWord MsgAcceptChannel           = 33
    117 msgTypeWord MsgFundingCreated          = 34
    118 msgTypeWord MsgFundingSigned           = 35
    119 msgTypeWord MsgChannelReady            = 36
    120 msgTypeWord MsgShutdown                = 38
    121 msgTypeWord MsgClosingSigned           = 39
    122 msgTypeWord MsgClosingComplete         = 40
    123 msgTypeWord MsgClosingSig              = 41
    124 msgTypeWord MsgOpenChannel2            = 64
    125 msgTypeWord MsgAcceptChannel2          = 65
    126 msgTypeWord MsgTxAddInput              = 66
    127 msgTypeWord MsgTxAddOutput             = 67
    128 msgTypeWord MsgTxRemoveInput           = 68
    129 msgTypeWord MsgTxRemoveOutput          = 69
    130 msgTypeWord MsgTxComplete              = 70
    131 msgTypeWord MsgTxSignatures            = 71
    132 msgTypeWord MsgTxInitRbf               = 72
    133 msgTypeWord MsgTxAckRbf                = 73
    134 msgTypeWord MsgTxAbort                 = 74
    135 msgTypeWord MsgUpdateAddHtlc           = 128
    136 msgTypeWord MsgUpdateFulfillHtlc       = 130
    137 msgTypeWord MsgUpdateFailHtlc          = 131
    138 msgTypeWord MsgCommitmentSigned        = 132
    139 msgTypeWord MsgRevokeAndAck            = 133
    140 msgTypeWord MsgUpdateFee               = 134
    141 msgTypeWord MsgUpdateFailMalformedHtlc = 135
    142 msgTypeWord MsgChannelReestablish      = 136
    143 {-# INLINE msgTypeWord #-}
    144 
    145 -- Channel establishment v1 ----------------------------------------------------
    146 
    147 -- | The open_channel message (type 32).
    148 --
    149 -- Contains information about a node and indicates its desire to set up
    150 -- a new channel.
    151 data OpenChannel = OpenChannel
    152   { openChannelChainHash             :: !ChainHash
    153   , openChannelTempChannelId         :: !ChannelId
    154   , openChannelFundingSatoshis       :: {-# UNPACK #-} !Satoshis
    155   , openChannelPushMsat              :: {-# UNPACK #-} !MilliSatoshis
    156   , openChannelDustLimitSatoshis     :: {-# UNPACK #-} !Satoshis
    157   , openChannelMaxHtlcValueInFlight  :: {-# UNPACK #-} !MilliSatoshis
    158   , openChannelChannelReserveSat     :: {-# UNPACK #-} !Satoshis
    159   , openChannelHtlcMinimumMsat       :: {-# UNPACK #-} !MilliSatoshis
    160   , openChannelFeeratePerKw          :: {-# UNPACK #-} !Word32
    161   , openChannelToSelfDelay           :: {-# UNPACK #-} !Word16
    162   , openChannelMaxAcceptedHtlcs      :: {-# UNPACK #-} !Word16
    163   , openChannelFundingPubkey         :: !Point
    164   , openChannelRevocationBasepoint   :: !Point
    165   , openChannelPaymentBasepoint      :: !Point
    166   , openChannelDelayedPaymentBase    :: !Point
    167   , openChannelHtlcBasepoint         :: !Point
    168   , openChannelFirstPerCommitPoint   :: !Point
    169   , openChannelChannelFlags          :: {-# UNPACK #-} !Word8
    170   , openChannelTlvs                  :: !TlvStream
    171   } deriving stock (Eq, Show, Generic)
    172 
    173 instance NFData OpenChannel
    174 
    175 -- | The accept_channel message (type 33).
    176 --
    177 -- Contains information about a node and indicates its acceptance of
    178 -- the new channel.
    179 data AcceptChannel = AcceptChannel
    180   { acceptChannelTempChannelId       :: !ChannelId
    181   , acceptChannelDustLimitSatoshis   :: {-# UNPACK #-} !Satoshis
    182   , acceptChannelMaxHtlcValueInFlight :: {-# UNPACK #-} !MilliSatoshis
    183   , acceptChannelChannelReserveSat   :: {-# UNPACK #-} !Satoshis
    184   , acceptChannelHtlcMinimumMsat     :: {-# UNPACK #-} !MilliSatoshis
    185   , acceptChannelMinimumDepth        :: {-# UNPACK #-} !Word32
    186   , acceptChannelToSelfDelay         :: {-# UNPACK #-} !Word16
    187   , acceptChannelMaxAcceptedHtlcs    :: {-# UNPACK #-} !Word16
    188   , acceptChannelFundingPubkey       :: !Point
    189   , acceptChannelRevocationBasepoint :: !Point
    190   , acceptChannelPaymentBasepoint    :: !Point
    191   , acceptChannelDelayedPaymentBase  :: !Point
    192   , acceptChannelHtlcBasepoint       :: !Point
    193   , acceptChannelFirstPerCommitPoint :: !Point
    194   , acceptChannelTlvs                :: !TlvStream
    195   } deriving stock (Eq, Show, Generic)
    196 
    197 instance NFData AcceptChannel
    198 
    199 -- | The funding_created message (type 34).
    200 --
    201 -- Describes the outpoint which the funder has created for the initial
    202 -- commitment transactions.
    203 data FundingCreated = FundingCreated
    204   { fundingCreatedTempChannelId   :: !ChannelId
    205   , fundingCreatedFundingTxid     :: !TxId
    206   , fundingCreatedFundingOutIdx   :: {-# UNPACK #-} !Word16
    207   , fundingCreatedSignature       :: !Signature
    208   } deriving stock (Eq, Show, Generic)
    209 
    210 instance NFData FundingCreated
    211 
    212 -- | The funding_signed message (type 35).
    213 --
    214 -- Gives the funder the signature for the first commitment transaction.
    215 data FundingSigned = FundingSigned
    216   { fundingSignedChannelId  :: !ChannelId
    217   , fundingSignedSignature  :: !Signature
    218   } deriving stock (Eq, Show, Generic)
    219 
    220 instance NFData FundingSigned
    221 
    222 -- | The channel_ready message (type 36).
    223 --
    224 -- Indicates that the funding transaction has sufficient confirms for
    225 -- channel use.
    226 data ChannelReady = ChannelReady
    227   { channelReadyChannelId            :: !ChannelId
    228   , channelReadySecondPerCommitPoint :: !Point
    229   , channelReadyTlvs                 :: !TlvStream
    230   } deriving stock (Eq, Show, Generic)
    231 
    232 instance NFData ChannelReady
    233 
    234 -- Channel establishment v2 ----------------------------------------------------
    235 
    236 -- | The open_channel2 message (type 64).
    237 --
    238 -- Initiates the v2 channel establishment workflow.
    239 data OpenChannel2 = OpenChannel2
    240   { openChannel2ChainHash            :: !ChainHash
    241   , openChannel2TempChannelId        :: !ChannelId
    242   , openChannel2FundingFeeratePerkw  :: {-# UNPACK #-} !Word32
    243   , openChannel2CommitFeeratePerkw   :: {-# UNPACK #-} !Word32
    244   , openChannel2FundingSatoshis      :: {-# UNPACK #-} !Satoshis
    245   , openChannel2DustLimitSatoshis    :: {-# UNPACK #-} !Satoshis
    246   , openChannel2MaxHtlcValueInFlight :: {-# UNPACK #-} !MilliSatoshis
    247   , openChannel2HtlcMinimumMsat      :: {-# UNPACK #-} !MilliSatoshis
    248   , openChannel2ToSelfDelay          :: {-# UNPACK #-} !Word16
    249   , openChannel2MaxAcceptedHtlcs     :: {-# UNPACK #-} !Word16
    250   , openChannel2Locktime             :: {-# UNPACK #-} !Word32
    251   , openChannel2FundingPubkey        :: !Point
    252   , openChannel2RevocationBasepoint  :: !Point
    253   , openChannel2PaymentBasepoint     :: !Point
    254   , openChannel2DelayedPaymentBase   :: !Point
    255   , openChannel2HtlcBasepoint        :: !Point
    256   , openChannel2FirstPerCommitPoint  :: !Point
    257   , openChannel2SecondPerCommitPoint :: !Point
    258   , openChannel2ChannelFlags         :: {-# UNPACK #-} !Word8
    259   , openChannel2Tlvs                 :: !TlvStream
    260   } deriving stock (Eq, Show, Generic)
    261 
    262 instance NFData OpenChannel2
    263 
    264 -- | The accept_channel2 message (type 65).
    265 --
    266 -- Indicates acceptance of the v2 channel.
    267 data AcceptChannel2 = AcceptChannel2
    268   { acceptChannel2TempChannelId        :: !ChannelId
    269   , acceptChannel2FundingSatoshis      :: {-# UNPACK #-} !Satoshis
    270   , acceptChannel2DustLimitSatoshis    :: {-# UNPACK #-} !Satoshis
    271   , acceptChannel2MaxHtlcValueInFlight :: {-# UNPACK #-} !MilliSatoshis
    272   , acceptChannel2HtlcMinimumMsat      :: {-# UNPACK #-} !MilliSatoshis
    273   , acceptChannel2MinimumDepth         :: {-# UNPACK #-} !Word32
    274   , acceptChannel2ToSelfDelay          :: {-# UNPACK #-} !Word16
    275   , acceptChannel2MaxAcceptedHtlcs     :: {-# UNPACK #-} !Word16
    276   , acceptChannel2FundingPubkey        :: !Point
    277   , acceptChannel2RevocationBasepoint  :: !Point
    278   , acceptChannel2PaymentBasepoint     :: !Point
    279   , acceptChannel2DelayedPaymentBase   :: !Point
    280   , acceptChannel2HtlcBasepoint        :: !Point
    281   , acceptChannel2FirstPerCommitPoint  :: !Point
    282   , acceptChannel2SecondPerCommitPoint :: !Point
    283   , acceptChannel2Tlvs                 :: !TlvStream
    284   } deriving stock (Eq, Show, Generic)
    285 
    286 instance NFData AcceptChannel2
    287 
    288 -- Interactive transaction construction ----------------------------------------
    289 
    290 -- | The tx_add_input message (type 66).
    291 --
    292 -- Adds a transaction input to the collaborative transaction.
    293 data TxAddInput = TxAddInput
    294   { txAddInputChannelId :: !ChannelId
    295   , txAddInputSerialId  :: {-# UNPACK #-} !Word64
    296   , txAddInputPrevTx    :: !BS.ByteString
    297   , txAddInputPrevVout  :: {-# UNPACK #-} !Word32
    298   , txAddInputSequence  :: {-# UNPACK #-} !Word32
    299   } deriving stock (Eq, Show, Generic)
    300 
    301 instance NFData TxAddInput
    302 
    303 -- | The tx_add_output message (type 67).
    304 --
    305 -- Adds a transaction output to the collaborative transaction.
    306 data TxAddOutput = TxAddOutput
    307   { txAddOutputChannelId :: !ChannelId
    308   , txAddOutputSerialId  :: {-# UNPACK #-} !Word64
    309   , txAddOutputSats      :: {-# UNPACK #-} !Satoshis
    310   , txAddOutputScript    :: !ScriptPubKey
    311   } deriving stock (Eq, Show, Generic)
    312 
    313 instance NFData TxAddOutput
    314 
    315 -- | The tx_remove_input message (type 68).
    316 --
    317 -- Removes a previously added input from the collaborative transaction.
    318 data TxRemoveInput = TxRemoveInput
    319   { txRemoveInputChannelId :: !ChannelId
    320   , txRemoveInputSerialId  :: {-# UNPACK #-} !Word64
    321   } deriving stock (Eq, Show, Generic)
    322 
    323 instance NFData TxRemoveInput
    324 
    325 -- | The tx_remove_output message (type 69).
    326 --
    327 -- Removes a previously added output from the collaborative transaction.
    328 data TxRemoveOutput = TxRemoveOutput
    329   { txRemoveOutputChannelId :: !ChannelId
    330   , txRemoveOutputSerialId  :: {-# UNPACK #-} !Word64
    331   } deriving stock (Eq, Show, Generic)
    332 
    333 instance NFData TxRemoveOutput
    334 
    335 -- | The tx_complete message (type 70).
    336 --
    337 -- Signals the conclusion of a peer's transaction contributions.
    338 data TxComplete = TxComplete
    339   { txCompleteChannelId :: !ChannelId
    340   } deriving stock (Eq, Show, Generic)
    341 
    342 instance NFData TxComplete
    343 
    344 -- | Witness data for tx_signatures.
    345 data Witness = Witness
    346   { witnessData :: !BS.ByteString
    347   } deriving stock (Eq, Show, Generic)
    348 
    349 instance NFData Witness
    350 
    351 -- | The tx_signatures message (type 71).
    352 --
    353 -- Contains signatures for the collaborative transaction.
    354 data TxSignatures = TxSignatures
    355   { txSignaturesChannelId :: !ChannelId
    356   , txSignaturesTxid      :: !TxId
    357   , txSignaturesWitnesses :: ![Witness]
    358   } deriving stock (Eq, Show, Generic)
    359 
    360 instance NFData TxSignatures
    361 
    362 -- | The tx_init_rbf message (type 72).
    363 --
    364 -- Initiates a replacement of the transaction after it's been completed.
    365 data TxInitRbf = TxInitRbf
    366   { txInitRbfChannelId :: !ChannelId
    367   , txInitRbfLocktime  :: {-# UNPACK #-} !Word32
    368   , txInitRbfFeerate   :: {-# UNPACK #-} !Word32
    369   , txInitRbfTlvs      :: !TlvStream
    370   } deriving stock (Eq, Show, Generic)
    371 
    372 instance NFData TxInitRbf
    373 
    374 -- | The tx_ack_rbf message (type 73).
    375 --
    376 -- Acknowledges an RBF attempt.
    377 data TxAckRbf = TxAckRbf
    378   { txAckRbfChannelId :: !ChannelId
    379   , txAckRbfTlvs      :: !TlvStream
    380   } deriving stock (Eq, Show, Generic)
    381 
    382 instance NFData TxAckRbf
    383 
    384 -- | The tx_abort message (type 74).
    385 --
    386 -- Aborts the collaborative transaction negotiation.
    387 data TxAbort = TxAbort
    388   { txAbortChannelId :: !ChannelId
    389   , txAbortData      :: !BS.ByteString
    390   } deriving stock (Eq, Show, Generic)
    391 
    392 instance NFData TxAbort
    393 
    394 -- Channel close ---------------------------------------------------------------
    395 
    396 -- | The stfu message (type 2).
    397 --
    398 -- Indicates "SomeThing Fundamental is Underway" - used for channel
    399 -- quiescence.
    400 data Stfu = Stfu
    401   { stfuChannelId :: !ChannelId
    402   , stfuInitiator :: {-# UNPACK #-} !Word8
    403   } deriving stock (Eq, Show, Generic)
    404 
    405 instance NFData Stfu
    406 
    407 -- | The shutdown message (type 38).
    408 --
    409 -- Initiates closing of the channel.
    410 data Shutdown = Shutdown
    411   { shutdownChannelId    :: !ChannelId
    412   , shutdownScriptPubkey :: !ScriptPubKey
    413   } deriving stock (Eq, Show, Generic)
    414 
    415 instance NFData Shutdown
    416 
    417 -- | The closing_signed message (type 39).
    418 --
    419 -- Used in legacy closing negotiation.
    420 data ClosingSigned = ClosingSigned
    421   { closingSignedChannelId   :: !ChannelId
    422   , closingSignedFeeSatoshis :: {-# UNPACK #-} !Satoshis
    423   , closingSignedSignature   :: !Signature
    424   , closingSignedTlvs        :: !TlvStream
    425   } deriving stock (Eq, Show, Generic)
    426 
    427 instance NFData ClosingSigned
    428 
    429 -- | The closing_complete message (type 40).
    430 --
    431 -- Proposes a closing transaction in the new closing protocol.
    432 data ClosingComplete = ClosingComplete
    433   { closingCompleteChannelId       :: !ChannelId
    434   , closingCompleteCloserScript    :: !ScriptPubKey
    435   , closingCompleteCloseeScript    :: !ScriptPubKey
    436   , closingCompleteFeeSatoshis     :: {-# UNPACK #-} !Satoshis
    437   , closingCompleteLocktime        :: {-# UNPACK #-} !Word32
    438   , closingCompleteTlvs            :: !TlvStream
    439   } deriving stock (Eq, Show, Generic)
    440 
    441 instance NFData ClosingComplete
    442 
    443 -- | The closing_sig message (type 41).
    444 --
    445 -- Signs a closing transaction in the new closing protocol.
    446 data ClosingSig = ClosingSig
    447   { closingSigChannelId       :: !ChannelId
    448   , closingSigCloserScript    :: !ScriptPubKey
    449   , closingSigCloseeScript    :: !ScriptPubKey
    450   , closingSigFeeSatoshis     :: {-# UNPACK #-} !Satoshis
    451   , closingSigLocktime        :: {-# UNPACK #-} !Word32
    452   , closingSigTlvs            :: !TlvStream
    453   } deriving stock (Eq, Show, Generic)
    454 
    455 instance NFData ClosingSig
    456 
    457 -- Normal operation ------------------------------------------------------------
    458 
    459 -- | The update_add_htlc message (type 128).
    460 --
    461 -- Offers an HTLC to the other node, redeemable in return for a payment
    462 -- preimage.
    463 data UpdateAddHtlc = UpdateAddHtlc
    464   { updateAddHtlcChannelId       :: !ChannelId
    465   , updateAddHtlcId              :: {-# UNPACK #-} !Word64
    466   , updateAddHtlcAmountMsat      :: {-# UNPACK #-} !MilliSatoshis
    467   , updateAddHtlcPaymentHash     :: !PaymentHash
    468   , updateAddHtlcCltvExpiry      :: {-# UNPACK #-} !Word32
    469   , updateAddHtlcOnionPacket     :: !OnionPacket
    470   , updateAddHtlcTlvs            :: !TlvStream
    471   } deriving stock (Eq, Show, Generic)
    472 
    473 instance NFData UpdateAddHtlc
    474 
    475 -- | The update_fulfill_htlc message (type 130).
    476 --
    477 -- Supplies the preimage to fulfill an HTLC.
    478 data UpdateFulfillHtlc = UpdateFulfillHtlc
    479   { updateFulfillHtlcChannelId       :: !ChannelId
    480   , updateFulfillHtlcId              :: {-# UNPACK #-} !Word64
    481   , updateFulfillHtlcPaymentPreimage :: !PaymentPreimage
    482   , updateFulfillHtlcTlvs            :: !TlvStream
    483   } deriving stock (Eq, Show, Generic)
    484 
    485 instance NFData UpdateFulfillHtlc
    486 
    487 -- | The update_fail_htlc message (type 131).
    488 --
    489 -- Indicates an HTLC has failed.
    490 data UpdateFailHtlc = UpdateFailHtlc
    491   { updateFailHtlcChannelId :: !ChannelId
    492   , updateFailHtlcId        :: {-# UNPACK #-} !Word64
    493   , updateFailHtlcReason    :: !BS.ByteString
    494   , updateFailHtlcTlvs      :: !TlvStream
    495   } deriving stock (Eq, Show, Generic)
    496 
    497 instance NFData UpdateFailHtlc
    498 
    499 -- | The update_fail_malformed_htlc message (type 135).
    500 --
    501 -- Indicates an HTLC could not be parsed.
    502 data UpdateFailMalformedHtlc = UpdateFailMalformedHtlc
    503   { updateFailMalformedHtlcChannelId   :: !ChannelId
    504   , updateFailMalformedHtlcId          :: {-# UNPACK #-} !Word64
    505   , updateFailMalformedHtlcSha256Onion :: !PaymentHash
    506   , updateFailMalformedHtlcFailureCode :: {-# UNPACK #-} !Word16
    507   } deriving stock (Eq, Show, Generic)
    508 
    509 instance NFData UpdateFailMalformedHtlc
    510 
    511 -- | The commitment_signed message (type 132).
    512 --
    513 -- Applies pending changes and provides signatures for the commitment
    514 -- transaction.
    515 data CommitmentSigned = CommitmentSigned
    516   { commitmentSignedChannelId      :: !ChannelId
    517   , commitmentSignedSignature      :: !Signature
    518   , commitmentSignedHtlcSignatures :: ![Signature]
    519   } deriving stock (Eq, Show, Generic)
    520 
    521 instance NFData CommitmentSigned
    522 
    523 -- | The revoke_and_ack message (type 133).
    524 --
    525 -- Revokes the previous commitment transaction and acknowledges receipt
    526 -- of the commitment_signed.
    527 data RevokeAndAck = RevokeAndAck
    528   { revokeAndAckChannelId             :: !ChannelId
    529   , revokeAndAckPerCommitmentSecret   :: !Secret
    530   , revokeAndAckNextPerCommitPoint    :: !Point
    531   } deriving stock (Eq, Show, Generic)
    532 
    533 instance NFData RevokeAndAck
    534 
    535 -- | The update_fee message (type 134).
    536 --
    537 -- Updates the fee rate for commitment transactions.
    538 data UpdateFee = UpdateFee
    539   { updateFeeChannelId    :: !ChannelId
    540   , updateFeeFeeratePerKw :: {-# UNPACK #-} !Word32
    541   } deriving stock (Eq, Show, Generic)
    542 
    543 instance NFData UpdateFee
    544 
    545 -- Reestablishment -------------------------------------------------------------
    546 
    547 -- | The channel_reestablish message (type 136).
    548 --
    549 -- Used to re-establish a channel after reconnection.
    550 data ChannelReestablish = ChannelReestablish
    551   { channelReestablishChannelId            :: !ChannelId
    552   , channelReestablishNextCommitNum        :: {-# UNPACK #-} !Word64
    553   , channelReestablishNextRevocationNum    :: {-# UNPACK #-} !Word64
    554   , channelReestablishYourLastCommitSecret :: !Secret
    555   , channelReestablishMyCurrentCommitPoint :: !Point
    556   , channelReestablishTlvs                 :: !TlvStream
    557   } deriving stock (Eq, Show, Generic)
    558 
    559 instance NFData ChannelReestablish
    560 
    561 -- Top-level message type ------------------------------------------------------
    562 
    563 -- | All BOLT #2 messages.
    564 data Message
    565   -- Channel establishment v1
    566   = MsgOpenChannelVal !OpenChannel
    567   | MsgAcceptChannelVal !AcceptChannel
    568   | MsgFundingCreatedVal !FundingCreated
    569   | MsgFundingSignedVal !FundingSigned
    570   | MsgChannelReadyVal !ChannelReady
    571   -- Channel establishment v2
    572   | MsgOpenChannel2Val !OpenChannel2
    573   | MsgAcceptChannel2Val !AcceptChannel2
    574   | MsgTxAddInputVal !TxAddInput
    575   | MsgTxAddOutputVal !TxAddOutput
    576   | MsgTxRemoveInputVal !TxRemoveInput
    577   | MsgTxRemoveOutputVal !TxRemoveOutput
    578   | MsgTxCompleteVal !TxComplete
    579   | MsgTxSignaturesVal !TxSignatures
    580   | MsgTxInitRbfVal !TxInitRbf
    581   | MsgTxAckRbfVal !TxAckRbf
    582   | MsgTxAbortVal !TxAbort
    583   -- Channel close
    584   | MsgStfuVal !Stfu
    585   | MsgShutdownVal !Shutdown
    586   | MsgClosingSignedVal !ClosingSigned
    587   | MsgClosingCompleteVal !ClosingComplete
    588   | MsgClosingSigVal !ClosingSig
    589   -- Normal operation
    590   | MsgUpdateAddHtlcVal !UpdateAddHtlc
    591   | MsgUpdateFulfillHtlcVal !UpdateFulfillHtlc
    592   | MsgUpdateFailHtlcVal !UpdateFailHtlc
    593   | MsgUpdateFailMalformedHtlcVal !UpdateFailMalformedHtlc
    594   | MsgCommitmentSignedVal !CommitmentSigned
    595   | MsgRevokeAndAckVal !RevokeAndAck
    596   | MsgUpdateFeeVal !UpdateFee
    597   -- Reestablishment
    598   | MsgChannelReestablishVal !ChannelReestablish
    599   deriving stock (Eq, Show, Generic)
    600 
    601 instance NFData Message