mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-19 12:01:27 +02:00
multi: refactor NewAnchorResolutions to return fixed values
This commit adds a new struct AnchorResolutions which wraps the anchor resolutions for local/remote/pending remote commitment transactions. It is then returned from NewAnchorResolutions. Thus the caller knows how to retrieve a certain anchor resolution.
This commit is contained in:
@@ -241,7 +241,7 @@ type arbChannel struct {
|
||||
// commitment transactions.
|
||||
//
|
||||
// NOTE: Part of the ArbChannel interface.
|
||||
func (a *arbChannel) NewAnchorResolutions() ([]*lnwallet.AnchorResolution,
|
||||
func (a *arbChannel) NewAnchorResolutions() (*lnwallet.AnchorResolutions,
|
||||
error) {
|
||||
|
||||
// Get a fresh copy of the database state to base the anchor resolutions
|
||||
|
@@ -91,7 +91,7 @@ type ArbChannel interface {
|
||||
|
||||
// NewAnchorResolutions returns the anchor resolutions for currently
|
||||
// valid commitment transactions.
|
||||
NewAnchorResolutions() ([]*lnwallet.AnchorResolution, error)
|
||||
NewAnchorResolutions() (*lnwallet.AnchorResolutions, error)
|
||||
}
|
||||
|
||||
// ChannelArbitratorConfig contains all the functionality that the
|
||||
@@ -1087,14 +1087,18 @@ func (c *ChannelArbitrator) stateStep(
|
||||
// sweepAnchors offers all given anchor resolutions to the sweeper. It requests
|
||||
// sweeping at the minimum fee rate. This fee rate can be upped manually by the
|
||||
// user via the BumpFee rpc.
|
||||
func (c *ChannelArbitrator) sweepAnchors(anchors []*lnwallet.AnchorResolution,
|
||||
func (c *ChannelArbitrator) sweepAnchors(anchors *lnwallet.AnchorResolutions,
|
||||
heightHint uint32) error {
|
||||
|
||||
// Use the chan id as the exclusive group. This prevents any of the
|
||||
// anchors from being batched together.
|
||||
exclusiveGroup := c.cfg.ShortChanID.ToUint64()
|
||||
|
||||
for _, anchor := range anchors {
|
||||
// TODO: refactor this function in next commit.
|
||||
for _, anchor := range []*lnwallet.AnchorResolution{
|
||||
anchors.Local, anchors.Remote, anchors.RemotePending,
|
||||
} {
|
||||
|
||||
log.Debugf("ChannelArbitrator(%v): pre-confirmation sweep of "+
|
||||
"anchor of tx %v", c.cfg.ChanPoint, anchor.CommitAnchor)
|
||||
|
||||
|
@@ -2119,9 +2119,7 @@ func TestChannelArbitratorAnchors(t *testing.T) {
|
||||
|
||||
// Setup two pre-confirmation anchor resolutions on the mock channel.
|
||||
chanArb.cfg.Channel.(*mockChannel).anchorResolutions =
|
||||
[]*lnwallet.AnchorResolution{
|
||||
{}, {},
|
||||
}
|
||||
&lnwallet.AnchorResolutions{}
|
||||
|
||||
if err := chanArb.Start(nil); err != nil {
|
||||
t.Fatalf("unable to start ChannelArbitrator: %v", err)
|
||||
@@ -2286,13 +2284,16 @@ func assertResolverReport(t *testing.T, reports chan *channeldb.ResolverReport,
|
||||
}
|
||||
|
||||
type mockChannel struct {
|
||||
anchorResolutions []*lnwallet.AnchorResolution
|
||||
anchorResolutions *lnwallet.AnchorResolutions
|
||||
}
|
||||
|
||||
func (m *mockChannel) NewAnchorResolutions() ([]*lnwallet.AnchorResolution,
|
||||
func (m *mockChannel) NewAnchorResolutions() (*lnwallet.AnchorResolutions,
|
||||
error) {
|
||||
if m.anchorResolutions != nil {
|
||||
return m.anchorResolutions, nil
|
||||
}
|
||||
|
||||
return m.anchorResolutions, nil
|
||||
return &lnwallet.AnchorResolutions{}, nil
|
||||
}
|
||||
|
||||
func (m *mockChannel) ForceCloseChan() (*lnwallet.LocalForceCloseSummary, error) {
|
||||
|
Reference in New Issue
Block a user