mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-01 11:00:51 +02:00
multi: pass BuildBreachRetribution callback to tower client
In this commit, a new BuildBreachRetribution callback is added to the tower client's Config struct. The main LND server provides the client with an implementation of the callback.
This commit is contained in:
38
server.go
38
server.go
@ -1523,12 +1523,37 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// buildBreachRetribution is a call-back that can be used to
|
||||||
|
// query the BreachRetribution info and channel type given a
|
||||||
|
// channel ID and commitment height.
|
||||||
|
buildBreachRetribution := func(chanID lnwire.ChannelID,
|
||||||
|
commitHeight uint64) (*lnwallet.BreachRetribution,
|
||||||
|
channeldb.ChannelType, error) {
|
||||||
|
|
||||||
|
channel, err := s.chanStateDB.FetchChannelByID(
|
||||||
|
nil, chanID,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
br, err := lnwallet.NewBreachRetribution(
|
||||||
|
channel, commitHeight, 0, nil,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return br, channel.ChanType, nil
|
||||||
|
}
|
||||||
|
|
||||||
fetchClosedChannel := s.chanStateDB.FetchClosedChannelForID
|
fetchClosedChannel := s.chanStateDB.FetchClosedChannelForID
|
||||||
|
|
||||||
s.towerClient, err = wtclient.New(&wtclient.Config{
|
s.towerClient, err = wtclient.New(&wtclient.Config{
|
||||||
FetchClosedChannel: fetchClosedChannel,
|
FetchClosedChannel: fetchClosedChannel,
|
||||||
SessionCloseRange: sessionCloseRange,
|
BuildBreachRetribution: buildBreachRetribution,
|
||||||
ChainNotifier: s.cc.ChainNotifier,
|
SessionCloseRange: sessionCloseRange,
|
||||||
|
ChainNotifier: s.cc.ChainNotifier,
|
||||||
SubscribeChannelEvents: func() (subscribe.Subscription,
|
SubscribeChannelEvents: func() (subscribe.Subscription,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
@ -1558,9 +1583,10 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
blob.Type(blob.FlagAnchorChannel)
|
blob.Type(blob.FlagAnchorChannel)
|
||||||
|
|
||||||
s.anchorTowerClient, err = wtclient.New(&wtclient.Config{
|
s.anchorTowerClient, err = wtclient.New(&wtclient.Config{
|
||||||
FetchClosedChannel: fetchClosedChannel,
|
FetchClosedChannel: fetchClosedChannel,
|
||||||
SessionCloseRange: sessionCloseRange,
|
BuildBreachRetribution: buildBreachRetribution,
|
||||||
ChainNotifier: s.cc.ChainNotifier,
|
SessionCloseRange: sessionCloseRange,
|
||||||
|
ChainNotifier: s.cc.ChainNotifier,
|
||||||
SubscribeChannelEvents: func() (subscribe.Subscription,
|
SubscribeChannelEvents: func() (subscribe.Subscription,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
|
@ -178,6 +178,11 @@ type Config struct {
|
|||||||
// ChainNotifier can be used to subscribe to block notifications.
|
// ChainNotifier can be used to subscribe to block notifications.
|
||||||
ChainNotifier chainntnfs.ChainNotifier
|
ChainNotifier chainntnfs.ChainNotifier
|
||||||
|
|
||||||
|
// BuildBreachRetribution is a function closure that allows the client
|
||||||
|
// fetch the breach retribution info for a certain channel at a certain
|
||||||
|
// revoked commitment height.
|
||||||
|
BuildBreachRetribution BreachRetributionBuilder
|
||||||
|
|
||||||
// NewAddress generates a new on-chain sweep pkscript.
|
// NewAddress generates a new on-chain sweep pkscript.
|
||||||
NewAddress func() ([]byte, error)
|
NewAddress func() ([]byte, error)
|
||||||
|
|
||||||
@ -240,6 +245,12 @@ type Config struct {
|
|||||||
SessionCloseRange uint32
|
SessionCloseRange uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BreachRetributionBuilder is a function that can be used to construct a
|
||||||
|
// BreachRetribution from a channel ID and a commitment height.
|
||||||
|
type BreachRetributionBuilder func(id lnwire.ChannelID,
|
||||||
|
commitHeight uint64) (*lnwallet.BreachRetribution,
|
||||||
|
channeldb.ChannelType, error)
|
||||||
|
|
||||||
// newTowerMsg is an internal message we'll use within the TowerClient to signal
|
// newTowerMsg is an internal message we'll use within the TowerClient to signal
|
||||||
// that a new tower can be considered.
|
// that a new tower can be considered.
|
||||||
type newTowerMsg struct {
|
type newTowerMsg struct {
|
||||||
|
@ -517,6 +517,15 @@ func newHarness(t *testing.T, cfg harnessCfg) *testHarness {
|
|||||||
SessionCloseRange: 1,
|
SessionCloseRange: 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.clientCfg.BuildBreachRetribution = func(id lnwire.ChannelID,
|
||||||
|
commitHeight uint64) (*lnwallet.BreachRetribution,
|
||||||
|
channeldb.ChannelType, error) {
|
||||||
|
|
||||||
|
_, retribution := h.channelFromID(id).getState(commitHeight)
|
||||||
|
|
||||||
|
return retribution, channeldb.SingleFunderBit, nil
|
||||||
|
}
|
||||||
|
|
||||||
if !cfg.noServerStart {
|
if !cfg.noServerStart {
|
||||||
h.startServer()
|
h.startServer()
|
||||||
t.Cleanup(h.stopServer)
|
t.Cleanup(h.stopServer)
|
||||||
@ -627,6 +636,21 @@ func (h *testHarness) channel(id uint64) *mockChannel {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// channelFromID retrieves the channel corresponding to id.
|
||||||
|
//
|
||||||
|
// NOTE: The method fails if a channel for id does not exist.
|
||||||
|
func (h *testHarness) channelFromID(chanID lnwire.ChannelID) *mockChannel {
|
||||||
|
h.t.Helper()
|
||||||
|
|
||||||
|
h.mu.Lock()
|
||||||
|
defer h.mu.Unlock()
|
||||||
|
|
||||||
|
c, ok := h.channels[chanID]
|
||||||
|
require.Truef(h.t, ok, "unable to fetch channel %s", chanID)
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
// closeChannel marks a channel as closed.
|
// closeChannel marks a channel as closed.
|
||||||
//
|
//
|
||||||
// NOTE: The method fails if a channel for id does not exist.
|
// NOTE: The method fails if a channel for id does not exist.
|
||||||
|
Reference in New Issue
Block a user