Skip to content

Commit f1a26e6

Browse files
author
Antoine Riard
committed
Refactor handle_update_fee to wrapper error handling function
1 parent d6726d6 commit f1a26e6

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/ln/channelmanager.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,20 @@ impl ChannelManager {
18991899
Ok(res)
19001900
}
19011901

1902+
fn internal_update_fee(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFee) -> Result<(), MsgHandleErrInternal> {
1903+
let mut channel_state = self.channel_state.lock().unwrap();
1904+
match channel_state.by_id.get_mut(&msg.channel_id) {
1905+
Some(chan) => {
1906+
if chan.get_their_node_id() != *their_node_id {
1907+
//TODO: here and below MsgHandleErrInternal, #153 case
1908+
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id));
1909+
}
1910+
chan.update_fee(&*self.fee_estimator, &msg).map_err(|e| MsgHandleErrInternal::from_maybe_close(e))
1911+
},
1912+
None => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel", msg.channel_id))
1913+
}
1914+
}
1915+
19021916
fn internal_announcement_signatures(&self, their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) -> Result<(), MsgHandleErrInternal> {
19031917
let (chan_announcement, chan_update) = {
19041918
let mut channel_state = self.channel_state.lock().unwrap();
@@ -2153,16 +2167,7 @@ impl ChannelMessageHandler for ChannelManager {
21532167
}
21542168

21552169
fn handle_update_fee(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFee) -> Result<(), HandleError> {
2156-
let mut channel_state = self.channel_state.lock().unwrap();
2157-
match channel_state.by_id.get_mut(&msg.channel_id) {
2158-
Some(chan) => {
2159-
if chan.get_their_node_id() != *their_node_id {
2160-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
2161-
}
2162-
chan.update_fee(&*self.fee_estimator, &msg)
2163-
},
2164-
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
2165-
}
2170+
handle_error!(self, self.internal_update_fee(their_node_id, msg), their_node_id)
21662171
}
21672172

21682173
fn handle_announcement_signatures(&self, their_node_id: &PublicKey, msg: &msgs::AnnouncementSignatures) -> Result<(), HandleError> {

0 commit comments

Comments
 (0)