if htlc_amount_msat == 0 {
return Err(HandleError{err: "Unable to find a pending HTLC which matched the given payment preimage", msg: None});
}
+ self.channel_monitor.provide_payment_preimage(&payment_preimage);
//TODO: This is racy af, they may have pending messages in flight to us that will not have
//received this yet!
self.value_to_self_msat -= htlc.amount_msat;
}
}
+ self.channel_monitor.provide_payment_preimage(&msg.payment_preimage);
Ok(())
}
false
},
PendingOutboundHTLC::IntermediaryHopData { source_short_channel_id, .. } => {
- let (node_id, fulfill_msg) = {
+ let (node_id, fulfill_msg, monitor) = {
let chan_id = match channel_state.short_to_id.get(&source_short_channel_id) {
Some(chan_id) => chan_id.clone(),
None => return false
let chan = channel_state.by_id.get_mut(&chan_id).unwrap();
match chan.get_update_fulfill_htlc(payment_preimage) {
- Ok(msg) => (chan.get_their_node_id(), msg),
+ Ok(msg) => (chan.get_their_node_id(), msg, if from_user { Some(chan.channel_monitor()) } else { None }),
Err(_e) => {
//TODO: Do something with e?
return false;
}
};
- mem::drop(channel_state);
- let mut pending_events = self.pending_events.lock().unwrap();
- pending_events.push(events::Event::SendFulfillHTLC {
- node_id: node_id,
- msg: fulfill_msg
- });
+ {
+ mem::drop(channel_state);
+ let mut pending_events = self.pending_events.lock().unwrap();
+ pending_events.push(events::Event::SendFulfillHTLC {
+ node_id: node_id,
+ msg: fulfill_msg
+ });
+ }
- true
+ //TODO: It may not be possible to handle add_update_monitor fails gracefully, maybe
+ //it should return no Err? Sadly, panic!()s instead doesn't help much :(
+ if from_user {
+ match self.monitor.add_update_monitor(monitor.as_ref().unwrap().get_funding_txo().unwrap(), monitor.unwrap()) {
+ Ok(()) => true,
+ Err(_) => true,
+ }
+ } else { true }
},
}
}
}
fn handle_update_fulfill_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFulfillHTLC) -> Result<(), HandleError> {
- {
+ let monitor = {
let mut channel_state = self.channel_state.lock().unwrap();
match channel_state.by_id.get_mut(&msg.channel_id) {
Some(chan) => {
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
}
chan.update_fulfill_htlc(&msg)?;
+ chan.channel_monitor()
},
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
}
- }
+ };
//TODO: Delay the claimed_funds relaying just like we do outbound relay!
self.claim_funds_internal(msg.payment_preimage.clone(), false);
+ self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor)?;
Ok(())
}
min
}
+ pub fn provide_payment_preimage(&mut self, payment_preimage: &[u8; 32]) {
+ //TODO: Some kind of timeout here or ability to mark all states containing this preimage
+ //revoked?
+ self.payment_preimages.push(payment_preimage.clone());
+ }
+
#[inline]
fn check_spend_transaction(&self, tx: &Transaction, height: u32) -> Vec<Transaction> {
// Most secp and related errors trying to create keys means we have no hope of constructing