Skip to content

Commit fd141bb

Browse files
committed
[Error] rename msg field to action
this was a TODO and also briefly discussed in #43 (review) I'm not fully sure how to remove the `Option`, and make it completely required. Would love suggestions. So, have omitted that for now. Plus, better to make smaller, incremental changes. Test Plan: `cargo build` `cargo test`
1 parent 8916716 commit fd141bb

File tree

7 files changed

+135
-135
lines changed

7 files changed

+135
-135
lines changed

src/ln/channel.rs

Lines changed: 74 additions & 74 deletions
Large diffs are not rendered by default.

src/ln/channelmanager.rs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ macro_rules! secp_call {
167167
match $res {
168168
Ok(key) => key,
169169
//TODO: Make the err a parameter!
170-
Err(_) => return Err(HandleError{err: "Key error", msg: None})
170+
Err(_) => return Err(HandleError{err: "Key error", action: None})
171171
}
172172
};
173173
}
@@ -311,7 +311,7 @@ impl ChannelManager {
311311
(res, Some(chan_entry.remove_entry().1))
312312
} else { (res, None) }
313313
},
314-
hash_map::Entry::Vacant(_) => return Err(HandleError{err: "No such channel", msg: None})
314+
hash_map::Entry::Vacant(_) => return Err(HandleError{err: "No such channel", action: None})
315315
}
316316
};
317317
for payment_hash in res.1 {
@@ -443,11 +443,11 @@ impl ChannelManager {
443443
};
444444
cur_value_msat += hop.fee_msat;
445445
if cur_value_msat >= 21000000 * 100000000 * 1000 {
446-
return Err(HandleError{err: "Channel fees overflowed?!", msg: None});
446+
return Err(HandleError{err: "Channel fees overflowed?!", action: None});
447447
}
448448
cur_cltv += hop.cltv_expiry_delta as u32;
449449
if cur_cltv >= 500000000 {
450-
return Err(HandleError{err: "Channel CLTV overflowed?!", msg: None});
450+
return Err(HandleError{err: "Channel CLTV overflowed?!", action: None});
451451
}
452452
last_short_channel_id = hop.short_channel_id;
453453
}
@@ -576,7 +576,7 @@ impl ChannelManager {
576576
/// only fails if the channel does not yet have an assigned short_id
577577
fn get_channel_update(&self, chan: &Channel) -> Result<msgs::ChannelUpdate, HandleError> {
578578
let short_channel_id = match chan.get_short_channel_id() {
579-
None => return Err(HandleError{err: "Channel not yet established", msg: None}),
579+
None => return Err(HandleError{err: "Channel not yet established", action: None}),
580580
Some(id) => id,
581581
};
582582

@@ -609,12 +609,12 @@ impl ChannelManager {
609609
/// May generate a SendHTLCs event on success, which should be relayed.
610610
pub fn send_payment(&self, route: Route, payment_hash: [u8; 32]) -> Result<(), HandleError> {
611611
if route.hops.len() < 1 || route.hops.len() > 20 {
612-
return Err(HandleError{err: "Route didn't go anywhere/had bogus size", msg: None});
612+
return Err(HandleError{err: "Route didn't go anywhere/had bogus size", action: None});
613613
}
614614
let our_node_id = self.get_our_node_id();
615615
for (idx, hop) in route.hops.iter().enumerate() {
616616
if idx != route.hops.len() - 1 && hop.pubkey == our_node_id {
617-
return Err(HandleError{err: "Route went through us but wasn't a simple rebalance loop to us", msg: None});
617+
return Err(HandleError{err: "Route went through us but wasn't a simple rebalance loop to us", action: None});
618618
}
619619
}
620620

@@ -633,13 +633,13 @@ impl ChannelManager {
633633
let (first_hop_node_id, (update_add, commitment_signed, chan_monitor)) = {
634634
let mut channel_state = self.channel_state.lock().unwrap();
635635
let id = match channel_state.short_to_id.get(&route.hops.first().unwrap().short_channel_id) {
636-
None => return Err(HandleError{err: "No channel available with first hop!", msg: None}),
636+
None => return Err(HandleError{err: "No channel available with first hop!", action: None}),
637637
Some(id) => id.clone()
638638
};
639639
let res = {
640640
let chan = channel_state.by_id.get_mut(&id).unwrap();
641641
if chan.get_their_node_id() != route.hops.first().unwrap().pubkey {
642-
return Err(HandleError{err: "Node ID mismatch on first hop!", msg: None});
642+
return Err(HandleError{err: "Node ID mismatch on first hop!", action: None});
643643
}
644644
chan.send_htlc_and_commit(htlc_msat, payment_hash.clone(), htlc_cltv, onion_packet)?
645645
};
@@ -1099,11 +1099,11 @@ impl ChannelMessageHandler for ChannelManager {
10991099
//TODO: Handle errors and close channel (or so)
11001100
fn handle_open_channel(&self, their_node_id: &PublicKey, msg: &msgs::OpenChannel) -> Result<msgs::AcceptChannel, HandleError> {
11011101
if msg.chain_hash != self.genesis_hash {
1102-
return Err(HandleError{err: "Unknown genesis block hash", msg: None});
1102+
return Err(HandleError{err: "Unknown genesis block hash", action: None});
11031103
}
11041104
let mut channel_state = self.channel_state.lock().unwrap();
11051105
if channel_state.by_id.contains_key(&msg.temporary_channel_id) {
1106-
return Err(HandleError{err: "temporary_channel_id collision!", msg: None});
1106+
return Err(HandleError{err: "temporary_channel_id collision!", action: None});
11071107
}
11081108

11091109
let chan_keys = if cfg!(feature = "fuzztarget") {
@@ -1138,12 +1138,12 @@ impl ChannelMessageHandler for ChannelManager {
11381138
match channel_state.by_id.get_mut(&msg.temporary_channel_id) {
11391139
Some(chan) => {
11401140
if chan.get_their_node_id() != *their_node_id {
1141-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1141+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
11421142
}
11431143
chan.accept_channel(&msg)?;
11441144
(chan.get_value_satoshis(), chan.get_funding_redeemscript().to_v0_p2wsh(), chan.get_user_id())
11451145
},
1146-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1146+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
11471147
}
11481148
};
11491149
let mut pending_events = self.pending_events.lock().unwrap();
@@ -1165,7 +1165,7 @@ impl ChannelMessageHandler for ChannelManager {
11651165
match channel_state.by_id.remove(&msg.temporary_channel_id) {
11661166
Some(mut chan) => {
11671167
if chan.get_their_node_id() != *their_node_id {
1168-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1168+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
11691169
}
11701170
match chan.funding_created(msg) {
11711171
Ok((funding_msg, monitor_update)) => {
@@ -1176,7 +1176,7 @@ impl ChannelMessageHandler for ChannelManager {
11761176
}
11771177
}
11781178
},
1179-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1179+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
11801180
}
11811181
}; // Release channel lock for install_watch_outpoint call,
11821182
// note that this means if the remote end is misbehaving and sends a message for the same
@@ -1196,12 +1196,12 @@ impl ChannelMessageHandler for ChannelManager {
11961196
match channel_state.by_id.get_mut(&msg.channel_id) {
11971197
Some(chan) => {
11981198
if chan.get_their_node_id() != *their_node_id {
1199-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1199+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
12001200
}
12011201
let chan_monitor = chan.funding_signed(&msg)?;
12021202
(chan.get_funding_txo().unwrap(), chan.get_user_id(), chan_monitor)
12031203
},
1204-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1204+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
12051205
}
12061206
};
12071207
if let Err(_e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) {
@@ -1220,12 +1220,12 @@ impl ChannelMessageHandler for ChannelManager {
12201220
match channel_state.by_id.get_mut(&msg.channel_id) {
12211221
Some(chan) => {
12221222
if chan.get_their_node_id() != *their_node_id {
1223-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1223+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
12241224
}
12251225
chan.funding_locked(&msg)?;
12261226
return Ok(self.get_announcement_sigs(chan)?);
12271227
},
1228-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1228+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
12291229
};
12301230
}
12311231

@@ -1237,7 +1237,7 @@ impl ChannelMessageHandler for ChannelManager {
12371237
match channel_state.by_id.entry(msg.channel_id.clone()) {
12381238
hash_map::Entry::Occupied(mut chan_entry) => {
12391239
if chan_entry.get().get_their_node_id() != *their_node_id {
1240-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1240+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
12411241
}
12421242
let res = chan_entry.get_mut().shutdown(&*self.fee_estimator, &msg)?;
12431243
if chan_entry.get().is_shutdown() {
@@ -1247,7 +1247,7 @@ impl ChannelMessageHandler for ChannelManager {
12471247
(res, Some(chan_entry.remove_entry().1))
12481248
} else { (res, None) }
12491249
},
1250-
hash_map::Entry::Vacant(_) => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1250+
hash_map::Entry::Vacant(_) => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
12511251
}
12521252
};
12531253
for payment_hash in res.2 {
@@ -1272,7 +1272,7 @@ impl ChannelMessageHandler for ChannelManager {
12721272
match channel_state.by_id.entry(msg.channel_id.clone()) {
12731273
hash_map::Entry::Occupied(mut chan_entry) => {
12741274
if chan_entry.get().get_their_node_id() != *their_node_id {
1275-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1275+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
12761276
}
12771277
let res = chan_entry.get_mut().closing_signed(&*self.fee_estimator, &msg)?;
12781278
if res.1.is_some() {
@@ -1287,7 +1287,7 @@ impl ChannelMessageHandler for ChannelManager {
12871287
(res, Some(chan_entry.remove_entry().1))
12881288
} else { (res, None) }
12891289
},
1290-
hash_map::Entry::Vacant(_) => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1290+
hash_map::Entry::Vacant(_) => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
12911291
}
12921292
};
12931293
if let Some(broadcast_tx) = res.1 {
@@ -1335,7 +1335,7 @@ impl ChannelMessageHandler for ChannelManager {
13351335
($msg: expr, $err_code: expr, $data: expr) => {
13361336
return Err(msgs::HandleError {
13371337
err: $msg,
1338-
msg: Some(msgs::ErrorAction::UpdateFailHTLC {
1338+
action: Some(msgs::ErrorAction::UpdateFailHTLC {
13391339
msg: msgs::UpdateFailHTLC {
13401340
channel_id: msg.channel_id,
13411341
htlc_id: msg.htlc_id,
@@ -1494,16 +1494,16 @@ impl ChannelMessageHandler for ChannelManager {
14941494
let (source_short_channel_id, res) = match channel_state.by_id.get_mut(&msg.channel_id) {
14951495
Some(chan) => {
14961496
if chan.get_their_node_id() != *their_node_id {
1497-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1497+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
14981498
}
14991499
if !chan.is_usable() {
1500-
return Err(HandleError{err: "Channel not yet available for receiving HTLCs", msg: None});
1500+
return Err(HandleError{err: "Channel not yet available for receiving HTLCs", action: None});
15011501
}
15021502
let short_channel_id = chan.get_short_channel_id().unwrap();
15031503
pending_forward_info.prev_short_channel_id = short_channel_id;
15041504
(short_channel_id, chan.update_add_htlc(&msg, pending_forward_info)?)
15051505
},
1506-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None}), //TODO: panic?
1506+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None}), //TODO: panic?
15071507
};
15081508

15091509
match claimable_htlcs_entry {
@@ -1544,11 +1544,11 @@ impl ChannelMessageHandler for ChannelManager {
15441544
match channel_state.by_id.get_mut(&msg.channel_id) {
15451545
Some(chan) => {
15461546
if chan.get_their_node_id() != *their_node_id {
1547-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1547+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
15481548
}
15491549
chan.update_fulfill_htlc(&msg)?
15501550
},
1551-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1551+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
15521552
}
15531553
};
15541554
if let Err(_e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) {
@@ -1562,11 +1562,11 @@ impl ChannelMessageHandler for ChannelManager {
15621562
let payment_hash = match channel_state.by_id.get_mut(&msg.channel_id) {
15631563
Some(chan) => {
15641564
if chan.get_their_node_id() != *their_node_id {
1565-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1565+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
15661566
}
15671567
chan.update_fail_htlc(&msg, HTLCFailReason::ErrorPacket { err: msg.reason.clone() })
15681568
},
1569-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1569+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
15701570
}?;
15711571

15721572
if let Some(pending_htlc) = channel_state.claimable_htlcs.get(&payment_hash) {
@@ -1637,11 +1637,11 @@ impl ChannelMessageHandler for ChannelManager {
16371637
match channel_state.by_id.get_mut(&msg.channel_id) {
16381638
Some(chan) => {
16391639
if chan.get_their_node_id() != *their_node_id {
1640-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1640+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
16411641
}
16421642
chan.update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() })
16431643
},
1644-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1644+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
16451645
}
16461646
}
16471647

@@ -1651,11 +1651,11 @@ impl ChannelMessageHandler for ChannelManager {
16511651
match channel_state.by_id.get_mut(&msg.channel_id) {
16521652
Some(chan) => {
16531653
if chan.get_their_node_id() != *their_node_id {
1654-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1654+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
16551655
}
16561656
chan.commitment_signed(&msg)?
16571657
},
1658-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1658+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
16591659
}
16601660
};
16611661
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
@@ -1671,11 +1671,11 @@ impl ChannelMessageHandler for ChannelManager {
16711671
match channel_state.by_id.get_mut(&msg.channel_id) {
16721672
Some(chan) => {
16731673
if chan.get_their_node_id() != *their_node_id {
1674-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1674+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
16751675
}
16761676
chan.revoke_and_ack(&msg)?
16771677
},
1678-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1678+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
16791679
}
16801680
};
16811681
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
@@ -1721,11 +1721,11 @@ impl ChannelMessageHandler for ChannelManager {
17211721
match channel_state.by_id.get_mut(&msg.channel_id) {
17221722
Some(chan) => {
17231723
if chan.get_their_node_id() != *their_node_id {
1724-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1724+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
17251725
}
17261726
chan.update_fee(&*self.fee_estimator, &msg)
17271727
},
1728-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1728+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
17291729
}
17301730
}
17311731

@@ -1735,10 +1735,10 @@ impl ChannelMessageHandler for ChannelManager {
17351735
match channel_state.by_id.get_mut(&msg.channel_id) {
17361736
Some(chan) => {
17371737
if chan.get_their_node_id() != *their_node_id {
1738-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1738+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
17391739
}
17401740
if !chan.is_usable() {
1741-
return Err(HandleError{err: "Got an announcement_signatures before we were ready for it", msg: None });
1741+
return Err(HandleError{err: "Got an announcement_signatures before we were ready for it", action: None });
17421742
}
17431743

17441744
let our_node_id = self.get_our_node_id();
@@ -1759,7 +1759,7 @@ impl ChannelMessageHandler for ChannelManager {
17591759
contents: announcement,
17601760
}, self.get_channel_update(chan).unwrap()) // can only fail if we're not in a ready state
17611761
},
1762-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1762+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
17631763
}
17641764
};
17651765
let mut pending_events = self.pending_events.lock().unwrap();

src/ln/channelmonitor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl ChannelMonitor {
316316
for i in 0..pos {
317317
let (old_secret, old_idx) = self.old_secrets[i as usize];
318318
if ChannelMonitor::derive_secret(secret, pos, old_idx) != old_secret {
319-
return Err(HandleError{err: "Previous secret did not match new one", msg: None})
319+
return Err(HandleError{err: "Previous secret did not match new one", action: None})
320320
}
321321
}
322322
self.old_secrets[pos as usize] = (secret, idx);
@@ -421,7 +421,7 @@ impl ChannelMonitor {
421421
pub fn insert_combine(&mut self, mut other: ChannelMonitor) -> Result<(), HandleError> {
422422
if self.funding_txo.is_some() {
423423
if other.funding_txo.is_some() && other.funding_txo.as_ref().unwrap() != self.funding_txo.as_ref().unwrap() {
424-
return Err(HandleError{err: "Funding transaction outputs are not identical!", msg: None});
424+
return Err(HandleError{err: "Funding transaction outputs are not identical!", action: None});
425425
}
426426
} else {
427427
self.funding_txo = other.funding_txo.take();
@@ -882,7 +882,7 @@ impl ChannelMonitor {
882882
}
883883
}
884884
assert!(idx < self.get_min_seen_secret());
885-
Err(HandleError{err: "idx too low", msg: None})
885+
Err(HandleError{err: "idx too low", action: None})
886886
}
887887

888888
pub fn get_min_seen_secret(&self) -> u64 {

src/ln/msgs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ pub enum ErrorAction {
380380

381381
pub struct HandleError { //TODO: rename me
382382
pub err: &'static str,
383-
pub msg: Option<ErrorAction>, //TODO: Make this required and rename it
383+
pub action: Option<ErrorAction>, //TODO: Make this required and rename it
384384
}
385385

386386
/// Struct used to return values from revoke_and_ack messages, containing a bunch of commitment

0 commit comments

Comments
 (0)