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

lightningnetwork / lnd / 15429933215

03 Jun 2025 11:27PM UTC coverage: 58.29% (+0.6%) from 57.711%
15429933215

Pull #9725

github

web-flow
Merge 946ae4c80 into 239aab8b9
Pull Request #9725: protofsm: add ConfMapper to allow conf attribute projection for new events

0 of 6 new or added lines in 1 file covered. (0.0%)

69 existing lines in 10 files now uncovered.

97460 of 167199 relevant lines covered (58.29%)

1.81 hits per line

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

0.0
/protofsm/daemon_events.go
1
package protofsm
2

3
import (
4
        "github.com/btcsuite/btcd/btcec/v2"
5
        "github.com/btcsuite/btcd/chaincfg/chainhash"
6
        "github.com/btcsuite/btcd/wire"
7
        "github.com/lightningnetwork/lnd/chainntnfs"
8
        "github.com/lightningnetwork/lnd/fn/v2"
9
        "github.com/lightningnetwork/lnd/lnwire"
10
)
11

12
// DaemonEvent is a special event that can be emitted by a state transition
13
// function. A state machine can use this to perform side effects, such as
14
// sending a message to a peer, or broadcasting a transaction.
15
type DaemonEvent interface {
16
        daemonSealed()
17
}
18

19
// DaemonEventSet is a set of daemon events that can be emitted by a state
20
// transition.
21
type DaemonEventSet []DaemonEvent
22

23
// DaemonEvents is a special type constraint that enumerates all the possible
24
// types of daemon events.
25
type DaemonEvents interface {
26
        SendMsgEvent[any] | BroadcastTxn | RegisterSpend[any] |
27
                RegisterConf[any]
28
}
29

30
// SendPredicate is a function that returns true if the target message should
31
// sent.
32
type SendPredicate = func() bool
33

34
// SendMsgEvent is a special event that can be emitted by a state transition
35
// that instructs the daemon to send the contained message to the target peer.
36
type SendMsgEvent[Event any] struct {
37
        // TargetPeer is the peer to send the message to.
38
        TargetPeer btcec.PublicKey
39

40
        // Msgs is the set of messages to send to the target peer.
41
        Msgs []lnwire.Message
42

43
        // SendWhen implements a system for a conditional send once a special
44
        // send predicate has been met.
45
        //
46
        // TODO(roasbeef): contrast with usage of OnCommitFlush, etc
47
        SendWhen fn.Option[SendPredicate]
48

49
        // PostSendEvent is an optional event that is to be emitted after the
50
        // message has been sent. If a SendWhen is specified, then this will
51
        // only be executed after that returns true to unblock the send.
52
        PostSendEvent fn.Option[Event]
53
}
54

55
// daemonSealed indicates that this struct is a DaemonEvent instance.
56
func (s *SendMsgEvent[E]) daemonSealed() {}
×
57

58
// BroadcastTxn indicates the target transaction should be broadcast to the
59
// network.
60
type BroadcastTxn struct {
61
        // Tx is the transaction to broadcast.
62
        Tx *wire.MsgTx
63

64
        // Label is an optional label to attach to the transaction.
65
        Label string
66
}
67

68
// daemonSealed indicates that this struct is a DaemonEvent instance.
69
func (b *BroadcastTxn) daemonSealed() {}
×
70

71
// SpendMapper is a function that's used to map a spend notification to a
72
// custom state machine event.
73
type SpendMapper[Event any] func(*chainntnfs.SpendDetail) Event
74

75
// ConfMapper is a function that's used to map a confirmation notification to a
76
// custom state machine event.
77
type ConfMapper[Event any] func(*chainntnfs.TxConfirmation) Event
78

79
// RegisterSpend is used to request that a certain event is sent into the state
80
// machine once the specified outpoint has been spent.
81
type RegisterSpend[Event any] struct {
82
        // OutPoint is the outpoint on chain to watch.
83
        OutPoint wire.OutPoint
84

85
        // PkScript is the script that we expect to be spent along with the
86
        // outpoint.
87
        PkScript []byte
88

89
        // HeightHint is a value used to give the chain scanner a hint on how
90
        // far back it needs to start its search.
91
        HeightHint uint32
92

93
        // PostSpendEvent is a special spend mapper, that if present, will be
94
        // used to map the protofsm spend event to a custom event.
95
        PostSpendEvent fn.Option[SpendMapper[Event]]
96
}
97

98
// daemonSealed indicates that this struct is a DaemonEvent instance.
99
func (r *RegisterSpend[E]) daemonSealed() {}
×
100

101
// RegisterConf is used to request that a certain event is sent into the state
102
// machien once the specified outpoint has been spent.
103
type RegisterConf[Event any] struct {
104
        // Txid is the txid of the txn we want to watch the chain for.
105
        Txid chainhash.Hash
106

107
        // PkScript is the script that we expect to be created along with the
108
        // outpoint.
109
        PkScript []byte
110

111
        // HeightHint is a value used to give the chain scanner a hint on how
112
        // far back it needs to start its search.
113
        HeightHint uint32
114

115
        // NumConfs is the number of confirmations that the spending
116
        // transaction needs to dispatch an event.
117
        NumConfs fn.Option[uint32]
118

119
        // PostConfMapper is a special conf mapper, that if present, will be
120
        // used to map the protofsm confirmation event to a custom event.
121
        PostConfMapper fn.Option[ConfMapper[Event]]
122
}
123

124
// daemonSealed indicates that this struct is a DaemonEvent instance.
125
func (r *RegisterConf[E]) daemonSealed() {}
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