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

lightningnetwork / lnd / 14388908780

10 Apr 2025 07:39PM UTC coverage: 56.811% (-12.3%) from 69.08%
14388908780

Pull #9702

github

web-flow
Merge f006bbf4d into b732525a9
Pull Request #9702: multi: make payment address mandatory

28 of 42 new or added lines in 11 files covered. (66.67%)

23231 existing lines in 283 files now uncovered.

107286 of 188846 relevant lines covered (56.81%)

22749.28 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 {
42✔
31

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

39
// someEvent returns the target type as a protocol event option.
UNCOV
40
func someEvent[T ProtocolEvent](m T) fn.Option[ProtocolEvent] {
×
UNCOV
41
        return fn.Some(ProtocolEvent(m))
×
UNCOV
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,
UNCOV
47
        fromPub btcec.PublicKey) bool {
×
UNCOV
48

×
UNCOV
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.
UNCOV
54
func (r *RbfMsgMapper) MapMsg(wireMsg msgmux.PeerMsg) fn.Option[ProtocolEvent] {
×
UNCOV
55
        switch msg := wireMsg.Message.(type) {
×
UNCOV
56
        case *lnwire.Shutdown:
×
UNCOV
57
                if !r.isForUs(msg.ChannelID, wireMsg.PeerPub) {
×
58
                        return fn.None[ProtocolEvent]()
×
59
                }
×
60

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

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

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

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

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

UNCOV
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