@@ -149,34 +149,43 @@ async fn handle_ldk_events(
149
149
. funding_transaction_generated ( & temporary_channel_id, final_tx)
150
150
. unwrap ( ) ;
151
151
}
152
- Event :: PaymentReceived { payment_hash, .. } => {
152
+ Event :: PaymentReceived { payment_hash, payment_secret , amt } => {
153
153
let mut payments = inbound_payments. lock ( ) . unwrap ( ) ;
154
154
if let Some ( payment) = payments. get_mut ( & payment_hash) {
155
- assert ! ( loop_channel_manager. claim_funds(
156
- payment. preimage. unwrap( ) . clone( ) ,
157
- & payment. secret,
158
- payment. amt_msat. 0 . unwrap( ) ,
159
- ) ) ;
160
- println ! (
161
- "\n EVENT: received payment from payment_hash {} of {} millisatoshis" ,
162
- hex_utils:: hex_str( & payment_hash. 0 ) ,
163
- payment. amt_msat
164
- ) ;
165
- print ! ( "> " ) ;
166
- io:: stdout ( ) . flush ( ) . unwrap ( ) ;
167
- payment. status = HTLCStatus :: Succeeded ;
155
+ if payment. secret == payment_secret {
156
+ assert ! ( loop_channel_manager. claim_funds(
157
+ payment. preimage. unwrap( ) . clone( ) ,
158
+ & payment. secret,
159
+ payment. amt_msat. 0 . unwrap( ) ,
160
+ ) ) ;
161
+ println ! (
162
+ "\n EVENT: received payment from payment hash {} of {} millisatoshis" ,
163
+ hex_utils:: hex_str( & payment_hash. 0 ) ,
164
+ payment. amt_msat
165
+ ) ;
166
+ print ! ( "> " ) ;
167
+ io:: stdout ( ) . flush ( ) . unwrap ( ) ;
168
+ payment. status = HTLCStatus :: Succeeded ;
169
+ } else {
170
+ loop_channel_manager
171
+ . fail_htlc_backwards ( & payment_hash, & payment. secret ) ;
172
+ println ! ( "\n ERROR: we received a payment from payment hash {} but the payment secret didn't match" , hex_utils:: hex_str( & payment_hash. 0 ) ) ;
173
+ print ! ( "> " ) ;
174
+ io:: stdout ( ) . flush ( ) . unwrap ( ) ;
175
+ payment. status = HTLCStatus :: Failed ;
176
+ }
168
177
} else {
169
- println ! ( "\n ERROR: we received a payment but didn't know the preimage" ) ;
178
+ loop_channel_manager. fail_htlc_backwards ( & payment_hash, & payment_secret) ;
179
+ println ! ( "\n ERROR: we received a payment for payment hash {} but didn't know the preimage" , hex_utils:: hex_str( & payment_hash. 0 ) ) ;
170
180
print ! ( "> " ) ;
171
181
io:: stdout ( ) . flush ( ) . unwrap ( ) ;
172
- loop_channel_manager. fail_htlc_backwards ( & payment_hash, & None ) ;
173
182
payments. insert (
174
183
payment_hash,
175
184
PaymentInfo {
176
185
preimage : None ,
177
- secret : None ,
186
+ secret : payment_secret ,
178
187
status : HTLCStatus :: Failed ,
179
- amt_msat : MillisatAmount ( None ) ,
188
+ amt_msat : MillisatAmount ( Some ( amt ) ) ,
180
189
} ,
181
190
) ;
182
191
}
0 commit comments