Merge pull request #197 from TheBlueMatt/master

Fix fuzztarget failures
This commit is contained in:
Matt Corallo 2018-09-29 14:27:01 -04:00 committed by GitHub
commit d4ba4af057
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 7 deletions

View file

@ -365,9 +365,15 @@ impl ChannelManager {
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))?;
let res = channel.get_open_channel(self.genesis_hash.clone(), &*self.fee_estimator);
let mut channel_state = self.channel_state.lock().unwrap();
match channel_state.by_id.insert(channel.channel_id(), channel) {
Some(_) => panic!("RNG is bad???"),
None => {}
match channel_state.by_id.entry(channel.channel_id()) {
hash_map::Entry::Occupied(_) => {
if cfg!(feature = "fuzztarget") {
return Err(APIError::APIMisuseError { err: "Fuzzy bad RNG" });
} else {
panic!("RNG is bad???");
}
},
hash_map::Entry::Vacant(entry) => { entry.insert(channel); }
}
let mut events = self.pending_events.lock().unwrap();
@ -2456,9 +2462,11 @@ mod tests {
}
impl Drop for Node {
fn drop(&mut self) {
// Check that we processed all pending events
assert_eq!(self.node.get_and_clear_pending_events().len(), 0);
assert_eq!(self.chan_monitor.added_monitors.lock().unwrap().len(), 0);
if !::std::thread::panicking() {
// Check that we processed all pending events
assert_eq!(self.node.get_and_clear_pending_events().len(), 0);
assert_eq!(self.chan_monitor.added_monitors.lock().unwrap().len(), 0);
}
}
}

View file

@ -1011,7 +1011,9 @@ impl ChannelMonitor {
/// Attempst to claim a remote HTLC-Success/HTLC-Timeout s outputs using the revocation key
fn check_spend_remote_htlc(&self, tx: &Transaction, commitment_number: u64) -> Option<Transaction> {
let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
if tx.input.len() != 1 || tx.output.len() != 1 {
return None;
}
macro_rules! ignore_error {
( $thing : expr ) => {
@ -1039,6 +1041,7 @@ impl ChannelMonitor {
};
let redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.their_to_self_delay.unwrap(), &delayed_key);
let revokeable_p2wsh = redeemscript.to_v0_p2wsh();
let htlc_txid = tx.txid(); //TODO: This is gonna be a performance bottleneck for watchtowers!
let mut inputs = Vec::new();
let mut amount = 0;