@@ -26,8 +26,20 @@ pub struct BroadcasterInterface {
26
26
/// An opaque pointer which is passed to your function implementations as an argument.
27
27
/// This has no meaning in the LDK, and can be NULL or any other value.
28
28
pub this_arg : * mut c_void ,
29
- /// Sends a transaction out to (hopefully) be mined.
30
- pub broadcast_transaction : extern "C" fn ( this_arg : * const c_void , tx : crate :: c_types:: Transaction ) ,
29
+ /// Sends a list of transactions out to (hopefully) be mined.
30
+ /// This only needs to handle the actual broadcasting of transactions, LDK will automatically
31
+ /// rebroadcast transactions that haven't made it into a block.
32
+ ///
33
+ /// In some cases LDK may attempt to broadcast a transaction which double-spends another
34
+ /// and this isn't a bug and can be safely ignored.
35
+ ///
36
+ /// If more than one transaction is given, these transactions should be considered to be a
37
+ /// package and broadcast together. Some of the transactions may or may not depend on each other,
38
+ /// be sure to manage both cases correctly.
39
+ ///
40
+ /// Bitcoin transaction packages are defined in BIP 331 and here:
41
+ /// https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md
42
+ pub broadcast_transactions : extern "C" fn ( this_arg : * const c_void , txs : crate :: c_types:: derived:: CVec_TransactionZ ) ,
31
43
/// Frees any resources associated with this object given its this_arg pointer.
32
44
/// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
33
45
pub free : Option < extern "C" fn ( this_arg : * mut c_void ) > ,
@@ -38,15 +50,16 @@ unsafe impl Sync for BroadcasterInterface {}
38
50
pub ( crate ) extern "C" fn BroadcasterInterface_clone_fields ( orig : & BroadcasterInterface ) -> BroadcasterInterface {
39
51
BroadcasterInterface {
40
52
this_arg : orig. this_arg ,
41
- broadcast_transaction : Clone :: clone ( & orig. broadcast_transaction ) ,
53
+ broadcast_transactions : Clone :: clone ( & orig. broadcast_transactions ) ,
42
54
free : Clone :: clone ( & orig. free ) ,
43
55
}
44
56
}
45
57
46
58
use lightning:: chain:: chaininterface:: BroadcasterInterface as rustBroadcasterInterface;
47
59
impl rustBroadcasterInterface for BroadcasterInterface {
48
- fn broadcast_transaction ( & self , mut tx : & bitcoin:: blockdata:: transaction:: Transaction ) {
49
- ( self . broadcast_transaction ) ( self . this_arg , crate :: c_types:: Transaction :: from_bitcoin ( tx) )
60
+ fn broadcast_transactions ( & self , mut txs : & [ & bitcoin:: blockdata:: transaction:: Transaction ] ) {
61
+ let mut local_txs = Vec :: new ( ) ; for item in txs. iter ( ) { local_txs. push ( { crate :: c_types:: Transaction :: from_bitcoin ( ( * item) ) } ) ; } ;
62
+ ( self . broadcast_transactions ) ( self . this_arg , local_txs. into ( ) )
50
63
}
51
64
}
52
65
@@ -68,17 +81,26 @@ impl Drop for BroadcasterInterface {
68
81
}
69
82
}
70
83
}
71
- /// An enum that represents the speed at which we want a transaction to confirm used for feerate
84
+ /// An enum that represents the priority at which we want a transaction to confirm used for feerate
72
85
/// estimation.
73
86
#[ derive( Clone ) ]
74
87
#[ must_use]
75
88
#[ repr( C ) ]
76
89
pub enum ConfirmationTarget {
77
- /// We are happy with this transaction confirming slowly when feerate drops some.
90
+ /// We'd like a transaction to confirm in the future, but don't want to commit most of the fees
91
+ /// required to do so yet. The remaining fees will come via a Child-Pays-For-Parent (CPFP) fee
92
+ /// bump of the transaction.
93
+ ///
94
+ /// The feerate returned should be the absolute minimum feerate required to enter most node
95
+ /// mempools across the network. Note that if you are not able to obtain this feerate estimate,
96
+ /// you should likely use the furthest-out estimate allowed by your fee estimator.
97
+ MempoolMinimum ,
98
+ /// We are happy with a transaction confirming slowly, at least within a day or so worth of
99
+ /// blocks.
78
100
Background ,
79
- /// We'd like this transaction to confirm without major delay, but 12-18 blocks is fine .
101
+ /// We'd like a transaction to confirm without major delayed, i.e., within the next 12-24 blocks.
80
102
Normal ,
81
- /// We'd like this transaction to confirm in the next few blocks.
103
+ /// We'd like a transaction to confirm in the next few blocks.
82
104
HighPriority ,
83
105
}
84
106
use lightning:: chain:: chaininterface:: ConfirmationTarget as ConfirmationTargetImport ;
@@ -88,6 +110,7 @@ impl ConfirmationTarget {
88
110
#[ allow( unused) ]
89
111
pub ( crate ) fn to_native ( & self ) -> nativeConfirmationTarget {
90
112
match self {
113
+ ConfirmationTarget :: MempoolMinimum => nativeConfirmationTarget:: MempoolMinimum ,
91
114
ConfirmationTarget :: Background => nativeConfirmationTarget:: Background ,
92
115
ConfirmationTarget :: Normal => nativeConfirmationTarget:: Normal ,
93
116
ConfirmationTarget :: HighPriority => nativeConfirmationTarget:: HighPriority ,
@@ -96,6 +119,7 @@ impl ConfirmationTarget {
96
119
#[ allow( unused) ]
97
120
pub ( crate ) fn into_native ( self ) -> nativeConfirmationTarget {
98
121
match self {
122
+ ConfirmationTarget :: MempoolMinimum => nativeConfirmationTarget:: MempoolMinimum ,
99
123
ConfirmationTarget :: Background => nativeConfirmationTarget:: Background ,
100
124
ConfirmationTarget :: Normal => nativeConfirmationTarget:: Normal ,
101
125
ConfirmationTarget :: HighPriority => nativeConfirmationTarget:: HighPriority ,
@@ -104,6 +128,7 @@ impl ConfirmationTarget {
104
128
#[ allow( unused) ]
105
129
pub ( crate ) fn from_native ( native : & nativeConfirmationTarget ) -> Self {
106
130
match native {
131
+ nativeConfirmationTarget:: MempoolMinimum => ConfirmationTarget :: MempoolMinimum ,
107
132
nativeConfirmationTarget:: Background => ConfirmationTarget :: Background ,
108
133
nativeConfirmationTarget:: Normal => ConfirmationTarget :: Normal ,
109
134
nativeConfirmationTarget:: HighPriority => ConfirmationTarget :: HighPriority ,
@@ -112,6 +137,7 @@ impl ConfirmationTarget {
112
137
#[ allow( unused) ]
113
138
pub ( crate ) fn native_into ( native : nativeConfirmationTarget ) -> Self {
114
139
match native {
140
+ nativeConfirmationTarget:: MempoolMinimum => ConfirmationTarget :: MempoolMinimum ,
115
141
nativeConfirmationTarget:: Background => ConfirmationTarget :: Background ,
116
142
nativeConfirmationTarget:: Normal => ConfirmationTarget :: Normal ,
117
143
nativeConfirmationTarget:: HighPriority => ConfirmationTarget :: HighPriority ,
@@ -124,6 +150,10 @@ pub extern "C" fn ConfirmationTarget_clone(orig: &ConfirmationTarget) -> Confirm
124
150
orig. clone ( )
125
151
}
126
152
#[ no_mangle]
153
+ /// Utility method to constructs a new MempoolMinimum-variant ConfirmationTarget
154
+ pub extern "C" fn ConfirmationTarget_mempool_minimum ( ) -> ConfirmationTarget {
155
+ ConfirmationTarget :: MempoolMinimum }
156
+ #[ no_mangle]
127
157
/// Utility method to constructs a new Background-variant ConfirmationTarget
128
158
pub extern "C" fn ConfirmationTarget_background ( ) -> ConfirmationTarget {
129
159
ConfirmationTarget :: Background }
@@ -153,6 +183,11 @@ pub extern "C" fn ConfirmationTarget_eq(a: &ConfirmationTarget, b: &Confirmation
153
183
/// A trait which should be implemented to provide feerate information on a number of time
154
184
/// horizons.
155
185
///
186
+ /// If access to a local mempool is not feasible, feerate estimates should be fetched from a set of
187
+ /// third-parties hosting them. Note that this enables them to affect the propagation of your
188
+ /// pre-signed transactions at any time and therefore endangers the safety of channels funds. It
189
+ /// should be considered carefully as a deployment.
190
+ ///
156
191
/// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
157
192
/// called from inside the library in response to chain events, P2P events, or timer events).
158
193
#[ repr( C ) ]
@@ -168,7 +203,6 @@ pub struct FeeEstimator {
168
203
/// The following unit conversions can be used to convert to sats/KW:
169
204
/// * satoshis-per-byte * 250
170
205
/// * satoshis-per-kbyte / 4
171
- #[ must_use]
172
206
pub get_est_sat_per_1000_weight : extern "C" fn ( this_arg : * const c_void , confirmation_target : crate :: lightning:: chain:: chaininterface:: ConfirmationTarget ) -> u32 ,
173
207
/// Frees any resources associated with this object given its this_arg pointer.
174
208
/// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
0 commit comments