Skip to content

Commit d4ba4af

Browse files
authored
Merge pull request #197 from TheBlueMatt/master
Fix fuzztarget failures
2 parents 0112394 + 8d70678 commit d4ba4af

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/ln/channelmanager.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,15 @@ impl ChannelManager {
365365
let channel = Channel::new_outbound(&*self.fee_estimator, chan_keys, their_network_key, channel_value_satoshis, push_msat, self.announce_channels_publicly, user_id, Arc::clone(&self.logger))?;
366366
let res = channel.get_open_channel(self.genesis_hash.clone(), &*self.fee_estimator);
367367
let mut channel_state = self.channel_state.lock().unwrap();
368-
match channel_state.by_id.insert(channel.channel_id(), channel) {
369-
Some(_) => panic!("RNG is bad???"),
370-
None => {}
368+
match channel_state.by_id.entry(channel.channel_id()) {
369+
hash_map::Entry::Occupied(_) => {
370+
if cfg!(feature = "fuzztarget") {
371+
return Err(APIError::APIMisuseError { err: "Fuzzy bad RNG" });
372+
} else {
373+
panic!("RNG is bad???");
374+
}
375+
},
376+
hash_map::Entry::Vacant(entry) => { entry.insert(channel); }
371377
}
372378

373379
let mut events = self.pending_events.lock().unwrap();
@@ -2456,9 +2462,11 @@ mod tests {
24562462
}
24572463
impl Drop for Node {
24582464
fn drop(&mut self) {
2459-
// Check that we processed all pending events
2460-
assert_eq!(self.node.get_and_clear_pending_events().len(), 0);
2461-
assert_eq!(self.chan_monitor.added_monitors.lock().unwrap().len(), 0);
2465+
if !::std::thread::panicking() {
2466+
// Check that we processed all pending events
2467+
assert_eq!(self.node.get_and_clear_pending_events().len(), 0);
2468+
assert_eq!(self.chan_monitor.added_monitors.lock().unwrap().len(), 0);
2469+
}
24622470
}
24632471
}
24642472

src/ln/channelmonitor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,9 @@ impl ChannelMonitor {
10111011

10121012
/// Attempst to claim a remote HTLC-Success/HTLC-Timeout s outputs using the revocation key
10131013
fn check_spend_remote_htlc(&self, tx: &Transaction, commitment_number: u64) -> Option<Transaction> {
1014-
let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
1014+
if tx.input.len() != 1 || tx.output.len() != 1 {
1015+
return None;
1016+
}
10151017

10161018
macro_rules! ignore_error {
10171019
( $thing : expr ) => {
@@ -1039,6 +1041,7 @@ impl ChannelMonitor {
10391041
};
10401042
let redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.their_to_self_delay.unwrap(), &delayed_key);
10411043
let revokeable_p2wsh = redeemscript.to_v0_p2wsh();
1044+
let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
10421045

10431046
let mut inputs = Vec::new();
10441047
let mut amount = 0;

0 commit comments

Comments
 (0)