Skip to content

Commit 1051e53

Browse files
committed
Stop adding remote's payment_preimages to our channel monitor
1 parent b22519c commit 1051e53

File tree

2 files changed

+13
-21
lines changed

2 files changed

+13
-21
lines changed

src/ln/channel.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,7 @@ impl Channel {
13561356
Err(HandleError{err: "Remote tried to fulfill/fail an HTLC we couldn't find", action: None})
13571357
}
13581358

1359-
pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<ChannelMonitor, HandleError> {
1359+
pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(), HandleError> {
13601360
if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
13611361
return Err(HandleError{err: "Got add HTLC message when channel was not in an operational state", action: None});
13621362
}
@@ -1366,9 +1366,8 @@ impl Channel {
13661366
let mut payment_hash = [0; 32];
13671367
sha.result(&mut payment_hash);
13681368

1369-
self.channel_monitor.provide_payment_preimage(&payment_hash, &msg.payment_preimage);
13701369
self.mark_outbound_htlc_removed(msg.htlc_id, Some(payment_hash), None)?;
1371-
Ok(self.channel_monitor.clone())
1370+
Ok(())
13721371
}
13731372

13741373
pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<[u8; 32], HandleError> {

src/ln/channelmanager.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,22 +1682,16 @@ impl ChannelMessageHandler for ChannelManager {
16821682
// is broken, we may have enough info to get our own money!
16831683
self.claim_funds_internal(msg.payment_preimage.clone(), false);
16841684

1685-
let monitor = {
1686-
let mut channel_state = self.channel_state.lock().unwrap();
1687-
match channel_state.by_id.get_mut(&msg.channel_id) {
1688-
Some(chan) => {
1689-
if chan.get_their_node_id() != *their_node_id {
1690-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
1691-
}
1692-
chan.update_fulfill_htlc(&msg)?
1693-
},
1694-
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
1695-
}
1696-
};
1697-
if let Err(_e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) {
1698-
unimplemented!();
1685+
let mut channel_state = self.channel_state.lock().unwrap();
1686+
match channel_state.by_id.get_mut(&msg.channel_id) {
1687+
Some(chan) => {
1688+
if chan.get_their_node_id() != *their_node_id {
1689+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
1690+
}
1691+
chan.update_fulfill_htlc(&msg)
1692+
},
1693+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
16991694
}
1700-
Ok(())
17011695
}
17021696

17031697
fn handle_update_fail_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailHTLC) -> Result<Option<msgs::HTLCFailChannelUpdate>, HandleError> {
@@ -2492,10 +2486,9 @@ mod tests {
24922486
{
24932487
let mut added_monitors = $node.chan_monitor.added_monitors.lock().unwrap();
24942488
if $last_node {
2495-
assert_eq!(added_monitors.len(), 1);
2489+
assert_eq!(added_monitors.len(), 0);
24962490
} else {
2497-
assert_eq!(added_monitors.len(), 2);
2498-
assert!(added_monitors[0].0 != added_monitors[1].0);
2491+
assert_eq!(added_monitors.len(), 1);
24992492
}
25002493
added_monitors.clear();
25012494
}

0 commit comments

Comments
 (0)