Skip to content

Commit 4afb0d8

Browse files
authored
Merge pull request #53 from savil/rename-error-msg-to-action
[HandleError] rename msg field to action
2 parents de523c4 + 14c02c0 commit 4afb0d8

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
};
@@ -1111,11 +1111,11 @@ impl ChannelMessageHandler for ChannelManager {
11111111
//TODO: Handle errors and close channel (or so)
11121112
fn handle_open_channel(&self, their_node_id: &PublicKey, msg: &msgs::OpenChannel) -> Result<msgs::AcceptChannel, HandleError> {
11131113
if msg.chain_hash != self.genesis_hash {
1114-
return Err(HandleError{err: "Unknown genesis block hash", msg: None});
1114+
return Err(HandleError{err: "Unknown genesis block hash", action: None});
11151115
}
11161116
let mut channel_state = self.channel_state.lock().unwrap();
11171117
if channel_state.by_id.contains_key(&msg.temporary_channel_id) {
1118-
return Err(HandleError{err: "temporary_channel_id collision!", msg: None});
1118+
return Err(HandleError{err: "temporary_channel_id collision!", action: None});
11191119
}
11201120

11211121
let chan_keys = if cfg!(feature = "fuzztarget") {
@@ -1150,12 +1150,12 @@ impl ChannelMessageHandler for ChannelManager {
11501150
match channel_state.by_id.get_mut(&msg.temporary_channel_id) {
11511151
Some(chan) => {
11521152
if chan.get_their_node_id() != *their_node_id {
1153-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1153+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
11541154
}
11551155
chan.accept_channel(&msg)?;
11561156
(chan.get_value_satoshis(), chan.get_funding_redeemscript().to_v0_p2wsh(), chan.get_user_id())
11571157
},
1158-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1158+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
11591159
}
11601160
};
11611161
let mut pending_events = self.pending_events.lock().unwrap();
@@ -1177,7 +1177,7 @@ impl ChannelMessageHandler for ChannelManager {
11771177
match channel_state.by_id.remove(&msg.temporary_channel_id) {
11781178
Some(mut chan) => {
11791179
if chan.get_their_node_id() != *their_node_id {
1180-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1180+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
11811181
}
11821182
match chan.funding_created(msg) {
11831183
Ok((funding_msg, monitor_update)) => {
@@ -1188,7 +1188,7 @@ impl ChannelMessageHandler for ChannelManager {
11881188
}
11891189
}
11901190
},
1191-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1191+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
11921192
}
11931193
}; // Release channel lock for install_watch_outpoint call,
11941194
// note that this means if the remote end is misbehaving and sends a message for the same
@@ -1208,12 +1208,12 @@ impl ChannelMessageHandler for ChannelManager {
12081208
match channel_state.by_id.get_mut(&msg.channel_id) {
12091209
Some(chan) => {
12101210
if chan.get_their_node_id() != *their_node_id {
1211-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1211+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
12121212
}
12131213
let chan_monitor = chan.funding_signed(&msg)?;
12141214
(chan.get_funding_txo().unwrap(), chan.get_user_id(), chan_monitor)
12151215
},
1216-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1216+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
12171217
}
12181218
};
12191219
if let Err(_e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) {
@@ -1232,12 +1232,12 @@ impl ChannelMessageHandler for ChannelManager {
12321232
match channel_state.by_id.get_mut(&msg.channel_id) {
12331233
Some(chan) => {
12341234
if chan.get_their_node_id() != *their_node_id {
1235-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1235+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
12361236
}
12371237
chan.funding_locked(&msg)?;
12381238
return Ok(self.get_announcement_sigs(chan)?);
12391239
},
1240-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1240+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
12411241
};
12421242
}
12431243

@@ -1249,7 +1249,7 @@ impl ChannelMessageHandler for ChannelManager {
12491249
match channel_state.by_id.entry(msg.channel_id.clone()) {
12501250
hash_map::Entry::Occupied(mut chan_entry) => {
12511251
if chan_entry.get().get_their_node_id() != *their_node_id {
1252-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1252+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
12531253
}
12541254
let res = chan_entry.get_mut().shutdown(&*self.fee_estimator, &msg)?;
12551255
if chan_entry.get().is_shutdown() {
@@ -1259,7 +1259,7 @@ impl ChannelMessageHandler for ChannelManager {
12591259
(res, Some(chan_entry.remove_entry().1))
12601260
} else { (res, None) }
12611261
},
1262-
hash_map::Entry::Vacant(_) => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1262+
hash_map::Entry::Vacant(_) => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
12631263
}
12641264
};
12651265
for payment_hash in res.2 {
@@ -1284,7 +1284,7 @@ impl ChannelMessageHandler for ChannelManager {
12841284
match channel_state.by_id.entry(msg.channel_id.clone()) {
12851285
hash_map::Entry::Occupied(mut chan_entry) => {
12861286
if chan_entry.get().get_their_node_id() != *their_node_id {
1287-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1287+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
12881288
}
12891289
let res = chan_entry.get_mut().closing_signed(&*self.fee_estimator, &msg)?;
12901290
if res.1.is_some() {
@@ -1299,7 +1299,7 @@ impl ChannelMessageHandler for ChannelManager {
12991299
(res, Some(chan_entry.remove_entry().1))
13001300
} else { (res, None) }
13011301
},
1302-
hash_map::Entry::Vacant(_) => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1302+
hash_map::Entry::Vacant(_) => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
13031303
}
13041304
};
13051305
if let Some(broadcast_tx) = res.1 {
@@ -1347,7 +1347,7 @@ impl ChannelMessageHandler for ChannelManager {
13471347
($msg: expr, $err_code: expr, $data: expr) => {
13481348
return Err(msgs::HandleError {
13491349
err: $msg,
1350-
msg: Some(msgs::ErrorAction::UpdateFailHTLC {
1350+
action: Some(msgs::ErrorAction::UpdateFailHTLC {
13511351
msg: msgs::UpdateFailHTLC {
13521352
channel_id: msg.channel_id,
13531353
htlc_id: msg.htlc_id,
@@ -1506,16 +1506,16 @@ impl ChannelMessageHandler for ChannelManager {
15061506
let (source_short_channel_id, res) = match channel_state.by_id.get_mut(&msg.channel_id) {
15071507
Some(chan) => {
15081508
if chan.get_their_node_id() != *their_node_id {
1509-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1509+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
15101510
}
15111511
if !chan.is_usable() {
1512-
return Err(HandleError{err: "Channel not yet available for receiving HTLCs", msg: None});
1512+
return Err(HandleError{err: "Channel not yet available for receiving HTLCs", action: None});
15131513
}
15141514
let short_channel_id = chan.get_short_channel_id().unwrap();
15151515
pending_forward_info.prev_short_channel_id = short_channel_id;
15161516
(short_channel_id, chan.update_add_htlc(&msg, pending_forward_info)?)
15171517
},
1518-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None}), //TODO: panic?
1518+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None}), //TODO: panic?
15191519
};
15201520

15211521
match claimable_htlcs_entry {
@@ -1556,11 +1556,11 @@ impl ChannelMessageHandler for ChannelManager {
15561556
match channel_state.by_id.get_mut(&msg.channel_id) {
15571557
Some(chan) => {
15581558
if chan.get_their_node_id() != *their_node_id {
1559-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1559+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
15601560
}
15611561
chan.update_fulfill_htlc(&msg)?
15621562
},
1563-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1563+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
15641564
}
15651565
};
15661566
if let Err(_e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) {
@@ -1574,11 +1574,11 @@ impl ChannelMessageHandler for ChannelManager {
15741574
let payment_hash = match channel_state.by_id.get_mut(&msg.channel_id) {
15751575
Some(chan) => {
15761576
if chan.get_their_node_id() != *their_node_id {
1577-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1577+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
15781578
}
15791579
chan.update_fail_htlc(&msg, HTLCFailReason::ErrorPacket { err: msg.reason.clone() })
15801580
},
1581-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1581+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
15821582
}?;
15831583

15841584
if let Some(pending_htlc) = channel_state.claimable_htlcs.get(&payment_hash) {
@@ -1649,11 +1649,11 @@ impl ChannelMessageHandler for ChannelManager {
16491649
match channel_state.by_id.get_mut(&msg.channel_id) {
16501650
Some(chan) => {
16511651
if chan.get_their_node_id() != *their_node_id {
1652-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1652+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
16531653
}
16541654
chan.update_fail_malformed_htlc(&msg, HTLCFailReason::Reason { failure_code: msg.failure_code, data: Vec::new() })
16551655
},
1656-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1656+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
16571657
}
16581658
}
16591659

@@ -1663,11 +1663,11 @@ impl ChannelMessageHandler for ChannelManager {
16631663
match channel_state.by_id.get_mut(&msg.channel_id) {
16641664
Some(chan) => {
16651665
if chan.get_their_node_id() != *their_node_id {
1666-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1666+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
16671667
}
16681668
chan.commitment_signed(&msg)?
16691669
},
1670-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1670+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
16711671
}
16721672
};
16731673
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
@@ -1683,11 +1683,11 @@ impl ChannelMessageHandler for ChannelManager {
16831683
match channel_state.by_id.get_mut(&msg.channel_id) {
16841684
Some(chan) => {
16851685
if chan.get_their_node_id() != *their_node_id {
1686-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1686+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
16871687
}
16881688
chan.revoke_and_ack(&msg)?
16891689
},
1690-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1690+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
16911691
}
16921692
};
16931693
if let Err(_e) = self.monitor.add_update_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
@@ -1733,11 +1733,11 @@ impl ChannelMessageHandler for ChannelManager {
17331733
match channel_state.by_id.get_mut(&msg.channel_id) {
17341734
Some(chan) => {
17351735
if chan.get_their_node_id() != *their_node_id {
1736-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1736+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
17371737
}
17381738
chan.update_fee(&*self.fee_estimator, &msg)
17391739
},
1740-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1740+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
17411741
}
17421742
}
17431743

@@ -1747,10 +1747,10 @@ impl ChannelMessageHandler for ChannelManager {
17471747
match channel_state.by_id.get_mut(&msg.channel_id) {
17481748
Some(chan) => {
17491749
if chan.get_their_node_id() != *their_node_id {
1750-
return Err(HandleError{err: "Got a message for a channel from the wrong node!", msg: None})
1750+
return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None})
17511751
}
17521752
if !chan.is_usable() {
1753-
return Err(HandleError{err: "Got an announcement_signatures before we were ready for it", msg: None });
1753+
return Err(HandleError{err: "Got an announcement_signatures before we were ready for it", action: None });
17541754
}
17551755

17561756
let our_node_id = self.get_our_node_id();
@@ -1771,7 +1771,7 @@ impl ChannelMessageHandler for ChannelManager {
17711771
contents: announcement,
17721772
}, self.get_channel_update(chan).unwrap()) // can only fail if we're not in a ready state
17731773
},
1774-
None => return Err(HandleError{err: "Failed to find corresponding channel", msg: None})
1774+
None => return Err(HandleError{err: "Failed to find corresponding channel", action: None})
17751775
}
17761776
};
17771777
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
384384
}
385385

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

0 commit comments

Comments
 (0)