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,10 +3,25 @@ package htlcswitch
|
||||
import (
|
||||
"crypto/sha256"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
"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
|
||||
// the incoming htlc requests, applying the changes to the channel, and also
|
||||
// propagating/forwarding it to htlc switch.
|
||||
@ -66,6 +81,10 @@ type Peer interface {
|
||||
// ID returns the lightning network peer id.
|
||||
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() []byte
|
||||
|
||||
|
@ -17,6 +17,33 @@ import (
|
||||
"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
|
||||
// commitment update state-machine. This struct is used by htlcManager's to
|
||||
// save meta-state required for proper functioning.
|
||||
@ -63,6 +90,10 @@ type commitmentState struct {
|
||||
channel *lnwallet.LightningChannel
|
||||
chanPoint *wire.OutPoint
|
||||
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
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/roasbeef/btcutil"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
)
|
||||
|
||||
type mockServer struct {
|
||||
@ -152,6 +153,10 @@ func (s *mockServer) Disconnect() {
|
||||
s.t.Fatalf("server %v was disconnected", s.name)
|
||||
}
|
||||
|
||||
func (s *mockServer) WipeChannel(*lnwallet.LightningChannel) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *mockServer) Stop() {
|
||||
if !atomic.CompareAndSwapInt32(&s.shutdown, 0, 1) {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user