• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13536249039

26 Feb 2025 03:42AM UTC coverage: 57.462% (-1.4%) from 58.835%
13536249039

Pull #8453

github

Roasbeef
peer: update chooseDeliveryScript to gen script if needed

In this commit, we update `chooseDeliveryScript` to generate a new
script if needed. This allows us to fold in a few other lines that
always followed this function into this expanded function.

The tests have been updated accordingly.
Pull Request #8453: [4/4] - multi: integrate new rbf coop close FSM into the existing peer flow

275 of 1318 new or added lines in 22 files covered. (20.86%)

19521 existing lines in 257 files now uncovered.

103858 of 180741 relevant lines covered (57.46%)

24750.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

20.0
/lnwallet/chancloser/rbf_coop_msg_mapper.go
1
package chancloser
2

3
import (
4
        "github.com/btcsuite/btcd/btcec/v2"
5
        "github.com/lightningnetwork/lnd/fn/v2"
6
        "github.com/lightningnetwork/lnd/lnwire"
7
        "github.com/lightningnetwork/lnd/msgmux"
8
)
9

10
// RbfMsgMapper is a struct that implements the MsgMapper interface for the
11
// rbf-coop close state machine. This enables the state machine to be used with
12
// protofsm.
13
type RbfMsgMapper struct {
14
        // blockHeight is the height of the block when the co-op close request
15
        // was initiated. This is used to validate conditions related to the
16
        // thaw height.
17
        blockHeight uint32
18

19
        // chanID is the channel ID of the channel being closed.
20
        chanID lnwire.ChannelID
21

22
        // peerPub is the public key of the peer that the channel is being
23
        // closed.
24
        peerPub btcec.PublicKey
25
}
26

27
// NewRbfMsgMapper creates a new RbfMsgMapper instance given the current block
28
// height when the co-op close request was initiated.
29
func NewRbfMsgMapper(blockHeight uint32,
30
        chanID lnwire.ChannelID, peerPub btcec.PublicKey) *RbfMsgMapper {
27✔
31

27✔
32
        return &RbfMsgMapper{
27✔
33
                blockHeight: blockHeight,
27✔
34
                chanID:      chanID,
27✔
35
                peerPub:     peerPub,
27✔
36
        }
27✔
37
}
27✔
38

39
// someEvent returns the target type as a protocol event option.
40
func someEvent[T ProtocolEvent](m T) fn.Option[ProtocolEvent] {
×
41
        return fn.Some(ProtocolEvent(m))
×
42
}
×
43

44
// isForUs returns true if the channel ID + pubkey of the message matches the
45
// bound instance.
46
func (r *RbfMsgMapper) isForUs(chanID lnwire.ChannelID,
NEW
47
        fromPub btcec.PublicKey) bool {
×
NEW
48

×
NEW
49
        return r.chanID == chanID && r.peerPub.IsEqual(&fromPub)
×
UNCOV
50
}
×
51

52
// MapMsg maps a wire message into a FSM event. If the message is not mappable,
53
// then an error is returned.
NEW
54
func (r *RbfMsgMapper) MapMsg(wireMsg msgmux.PeerMsg) fn.Option[ProtocolEvent] {
×
NEW
55
        switch msg := wireMsg.Message.(type) {
×
56
        case *lnwire.Shutdown:
×
NEW
57
                if !r.isForUs(msg.ChannelID, wireMsg.PeerPub) {
×
58
                        return fn.None[ProtocolEvent]()
×
59
                }
×
60

61
                return someEvent(&ShutdownReceived{
×
62
                        BlockHeight:    r.blockHeight,
×
63
                        ShutdownScript: msg.Address,
×
64
                })
×
65

66
        case *lnwire.ClosingComplete:
×
NEW
67
                if !r.isForUs(msg.ChannelID, wireMsg.PeerPub) {
×
68
                        return fn.None[ProtocolEvent]()
×
69
                }
×
70

71
                return someEvent(&OfferReceivedEvent{
×
72
                        SigMsg: *msg,
×
73
                })
×
74

75
        case *lnwire.ClosingSig:
×
NEW
76
                if !r.isForUs(msg.ChannelID, wireMsg.PeerPub) {
×
77
                        return fn.None[ProtocolEvent]()
×
78
                }
×
79

80
                return someEvent(&LocalSigReceived{
×
81
                        SigMsg: *msg,
×
82
                })
×
83
        }
84

85
        return fn.None[ProtocolEvent]()
×
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc