mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 11:09:23 +01:00
htlcswitch: add channel link config
Step №1 in making htlcManager (aka channelLink) testable: Start use config which will allow as mock/stub external subsystems.
This commit is contained in:
parent
0de4ea2712
commit
7f572fc155
3 changed files with 55 additions and 0 deletions
|
@ -3,10 +3,25 @@ package htlcswitch
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||||
"github.com/roasbeef/btcutil"
|
"github.com/roasbeef/btcutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
LookupInvoice(chainhash.Hash) (*channeldb.Invoice, error)
|
||||||
|
|
||||||
|
// SettleInvoice attempts to mark an invoice corresponding to the passed
|
||||||
|
// payment hash as fully settled.
|
||||||
|
SettleInvoice(chainhash.Hash) error
|
||||||
|
}
|
||||||
|
|
||||||
// ChannelLink is an interface which represents the subsystem for managing
|
// ChannelLink is an interface which represents the subsystem for managing
|
||||||
// the incoming htlc requests, applying the changes to the channel, and also
|
// the incoming htlc requests, applying the changes to the channel, and also
|
||||||
// propagating/forwarding it to htlc switch.
|
// propagating/forwarding it to htlc switch.
|
||||||
|
@ -66,6 +81,10 @@ type Peer interface {
|
||||||
// ID returns the lightning network peer id.
|
// ID returns the lightning network peer id.
|
||||||
ID() [sha256.Size]byte
|
ID() [sha256.Size]byte
|
||||||
|
|
||||||
|
// WipeChannel removes the passed channel from all indexes associated
|
||||||
|
// with the peer.
|
||||||
|
WipeChannel(*lnwallet.LightningChannel) error
|
||||||
|
|
||||||
// PubKey returns the peer public key.
|
// PubKey returns the peer public key.
|
||||||
PubKey() []byte
|
PubKey() []byte
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,33 @@ import (
|
||||||
"github.com/roasbeef/btcutil"
|
"github.com/roasbeef/btcutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ChannelLinkConfig defines the configuration for the channel link. ALL
|
||||||
|
// elements within the configuration MUST be non-nil for channel link to carry
|
||||||
|
// out its duties.
|
||||||
|
type ChannelLinkConfig struct {
|
||||||
|
// Switch is a subsystem which is used to forward the incoming htlc
|
||||||
|
// packets to other peer which should handle it.
|
||||||
|
Switch *Switch
|
||||||
|
|
||||||
|
// Peer is a lightning network node with which we have the channel
|
||||||
|
// link opened.
|
||||||
|
Peer Peer
|
||||||
|
|
||||||
|
// Registry is a sub-system which responsible for managing the
|
||||||
|
// invoices in thread-safe manner.
|
||||||
|
Registry InvoiceDatabase
|
||||||
|
|
||||||
|
// SettledContracts is used to notify that a channel has peacefully been
|
||||||
|
// closed. Once a channel has been closed the other subsystem no longer
|
||||||
|
// needs to watch for breach closes.
|
||||||
|
SettledContracts chan *wire.OutPoint
|
||||||
|
|
||||||
|
// DebugHTLC should be turned on if you want all HTLCs sent to a node
|
||||||
|
// with the debug htlc R-Hash are immediately settled in the next
|
||||||
|
// available state transition.
|
||||||
|
DebugHTLC bool
|
||||||
|
}
|
||||||
|
|
||||||
// commitmentState is the volatile+persistent state of an active channel's
|
// commitmentState is the volatile+persistent state of an active channel's
|
||||||
// commitment update state-machine. This struct is used by htlcManager's to
|
// commitment update state-machine. This struct is used by htlcManager's to
|
||||||
// save meta-state required for proper functioning.
|
// save meta-state required for proper functioning.
|
||||||
|
@ -63,6 +90,10 @@ type commitmentState struct {
|
||||||
channel *lnwallet.LightningChannel
|
channel *lnwallet.LightningChannel
|
||||||
chanPoint *wire.OutPoint
|
chanPoint *wire.OutPoint
|
||||||
chanID lnwire.ChannelID
|
chanID lnwire.ChannelID
|
||||||
|
|
||||||
|
// cfg is a structure which carries all dependable fields/handlers
|
||||||
|
// which may affect behaviour of the service.
|
||||||
|
cfg *ChannelLinkConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// htlcManager is the primary goroutine which drives a channel's commitment
|
// htlcManager is the primary goroutine which drives a channel's commitment
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/roasbeef/btcutil"
|
"github.com/roasbeef/btcutil"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mockServer struct {
|
type mockServer struct {
|
||||||
|
@ -152,6 +153,10 @@ func (s *mockServer) Disconnect() {
|
||||||
s.t.Fatalf("server %v was disconnected", s.name)
|
s.t.Fatalf("server %v was disconnected", s.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *mockServer) WipeChannel(*lnwallet.LightningChannel) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *mockServer) Stop() {
|
func (s *mockServer) Stop() {
|
||||||
if !atomic.CompareAndSwapInt32(&s.shutdown, 0, 1) {
|
if !atomic.CompareAndSwapInt32(&s.shutdown, 0, 1) {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue