2017-05-01 19:58:08 +03:00
|
|
|
package htlcswitch
|
|
|
|
|
|
|
|
import (
|
2017-05-03 17:02:22 +03:00
|
|
|
"github.com/lightningnetwork/lnd/channeldb"
|
2017-05-01 19:58:08 +03:00
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
2017-05-03 17:02:22 +03:00
|
|
|
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
2017-11-23 10:15:21 +03:00
|
|
|
"github.com/roasbeef/btcd/wire"
|
2017-05-01 19:58:08 +03:00
|
|
|
)
|
|
|
|
|
2017-05-03 17:02:22 +03:00
|
|
|
// InvoiceDatabase is an interface which represents the persistent subsystem
|
|
|
|
// which may search, lookup and settle invoices.
|
|
|
|
type InvoiceDatabase interface {
|
|
|
|
// LookupInvoice attempts to look up an invoice according to it's 32
|
|
|
|
// byte payment hash.
|
2017-11-12 03:09:14 +03:00
|
|
|
LookupInvoice(chainhash.Hash) (channeldb.Invoice, error)
|
2017-05-03 17:02:22 +03:00
|
|
|
|
2017-06-17 00:32:41 +03:00
|
|
|
// SettleInvoice attempts to mark an invoice corresponding to the
|
|
|
|
// passed payment hash as fully settled.
|
2017-05-03 17:02:22 +03:00
|
|
|
SettleInvoice(chainhash.Hash) error
|
|
|
|
}
|
|
|
|
|
2017-06-17 00:32:41 +03:00
|
|
|
// ChannelLink is an interface which represents the subsystem for managing the
|
|
|
|
// incoming htlc requests, applying the changes to the channel, and also
|
2017-05-01 19:58:08 +03:00
|
|
|
// propagating/forwarding it to htlc switch.
|
|
|
|
//
|
|
|
|
// abstraction level
|
|
|
|
// ^
|
|
|
|
// |
|
|
|
|
// | - - - - - - - - - - - - Lightning - - - - - - - - - - - - -
|
|
|
|
// |
|
|
|
|
// | (Switch) (Switch) (Switch)
|
|
|
|
// | Alice <-- channel link --> Bob <-- channel link --> Carol
|
|
|
|
// |
|
|
|
|
// | - - - - - - - - - - - - - TCP - - - - - - - - - - - - - - -
|
|
|
|
// |
|
|
|
|
// | (Peer) (Peer) (Peer)
|
|
|
|
// | Alice <----- tcp conn --> Bob <---- tcp conn -----> Carol
|
|
|
|
// |
|
|
|
|
//
|
|
|
|
type ChannelLink interface {
|
2017-11-11 01:48:23 +03:00
|
|
|
// TODO(roasbeef): modify interface to embed mail boxes?
|
|
|
|
|
2017-05-01 19:58:08 +03:00
|
|
|
// HandleSwitchPacket handles the switch packets. This packets might be
|
|
|
|
// forwarded to us from another channel link in case the htlc update
|
|
|
|
// came from another peer or if the update was created by user
|
|
|
|
// initially.
|
2017-11-11 01:48:23 +03:00
|
|
|
//
|
|
|
|
// NOTE: This function MUST be non-blocking (or block as little as
|
|
|
|
// possible).
|
2017-05-01 19:58:08 +03:00
|
|
|
HandleSwitchPacket(*htlcPacket)
|
|
|
|
|
|
|
|
// HandleChannelUpdate handles the htlc requests as settle/add/fail
|
|
|
|
// which sent to us from remote peer we have a channel with.
|
2017-11-11 01:48:23 +03:00
|
|
|
//
|
|
|
|
// NOTE: This function MUST be non-blocking (or block as little as
|
|
|
|
// possible).
|
2017-05-01 19:58:08 +03:00
|
|
|
HandleChannelUpdate(lnwire.Message)
|
|
|
|
|
2017-06-17 00:32:41 +03:00
|
|
|
// ChanID returns the channel ID for the channel link. The channel ID
|
|
|
|
// is a more compact representation of a channel's full outpoint.
|
2017-05-01 19:58:08 +03:00
|
|
|
ChanID() lnwire.ChannelID
|
|
|
|
|
2017-06-17 00:32:41 +03:00
|
|
|
// ShortChanID returns the short channel ID for the channel link. The
|
|
|
|
// short channel ID encodes the exact location in the main chain that
|
|
|
|
// the original funding output can be found.
|
|
|
|
ShortChanID() lnwire.ShortChannelID
|
2017-06-17 01:01:00 +03:00
|
|
|
|
|
|
|
// UpdateForwardingPolicy updates the forwarding policy for the target
|
|
|
|
// ChannelLink. Once updated, the link will use the new forwarding
|
|
|
|
// policy to govern if it an incoming HTLC should be forwarded or not.
|
|
|
|
UpdateForwardingPolicy(ForwardingPolicy)
|
|
|
|
|
2017-08-22 09:36:43 +03:00
|
|
|
// Bandwidth returns the amount of milli-satoshis which current link
|
|
|
|
// might pass through channel link. The value returned from this method
|
2017-06-17 01:01:00 +03:00
|
|
|
// represents the up to date available flow through the channel. This
|
|
|
|
// takes into account any forwarded but un-cleared HTLC's, and any
|
|
|
|
// HTLC's which have been set to the over flow queue.
|
2017-08-22 09:36:43 +03:00
|
|
|
Bandwidth() lnwire.MilliSatoshi
|
2017-05-01 19:58:08 +03:00
|
|
|
|
|
|
|
// Stats return the statistics of channel link. Number of updates,
|
2017-08-22 09:36:43 +03:00
|
|
|
// total sent/received milli-satoshis.
|
|
|
|
Stats() (uint64, lnwire.MilliSatoshi, lnwire.MilliSatoshi)
|
2017-05-01 19:58:08 +03:00
|
|
|
|
2017-06-17 00:32:41 +03:00
|
|
|
// Peer returns the representation of remote peer with which we have
|
|
|
|
// the channel link opened.
|
2017-05-01 19:58:08 +03:00
|
|
|
Peer() Peer
|
|
|
|
|
2017-12-06 04:48:28 +03:00
|
|
|
// EligibleToForward returns a bool indicating if the channel is able
|
|
|
|
// to actively accept requests to forward HTLC's. A channel may be
|
|
|
|
// active, but not able to forward HTLC's if it hasn't yet finalized
|
|
|
|
// the pre-channel operation protocol with the remote peer. The switch
|
|
|
|
// will use this function in forwarding decisions accordingly.
|
|
|
|
EligibleToForward() bool
|
|
|
|
|
2017-06-17 00:32:41 +03:00
|
|
|
// Start/Stop are used to initiate the start/stop of the channel link
|
|
|
|
// functioning.
|
2017-05-01 19:58:08 +03:00
|
|
|
Start() error
|
|
|
|
Stop()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Peer is an interface which represents the remote lightning node inside our
|
|
|
|
// system.
|
|
|
|
type Peer interface {
|
|
|
|
// SendMessage sends message to remote peer.
|
|
|
|
SendMessage(lnwire.Message) error
|
|
|
|
|
2017-11-23 10:15:21 +03:00
|
|
|
// WipeChannel removes the channel uniquely identified by its channel
|
|
|
|
// point from all indexes associated with the peer.
|
|
|
|
WipeChannel(*wire.OutPoint) error
|
2017-05-03 17:02:22 +03:00
|
|
|
|
2017-06-17 00:38:42 +03:00
|
|
|
// PubKey returns the serialize public key of the source peer.
|
|
|
|
PubKey() [33]byte
|
2017-05-01 19:58:08 +03:00
|
|
|
|
|
|
|
// Disconnect disconnects with peer if we have error which we can't
|
|
|
|
// properly handle.
|
2017-07-12 16:44:17 +03:00
|
|
|
Disconnect(reason error)
|
2017-05-01 19:58:08 +03:00
|
|
|
}
|