Skip to content

Commit 5a2ed03

Browse files
authored
Merge pull request #594 from TheBlueMatt/2020-04-cleanups
Trivial Cleanups
2 parents 900d900 + c89514c commit 5a2ed03

File tree

9 files changed

+73
-118
lines changed

9 files changed

+73
-118
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ impl Writer for VecWriter {
7373
}
7474
}
7575

76-
pub struct TestChannelMonitor {
76+
struct TestChannelMonitor {
7777
pub logger: Arc<dyn Logger>,
78-
pub simple_monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<BroadcasterInterface>, Arc<FeeEstimator>>>,
78+
pub simple_monitor: Arc<channelmonitor::SimpleManyChannelMonitor<OutPoint, EnforcingChannelKeys, Arc<TestBroadcaster>, Arc<FuzzEstimator>>>,
7979
pub update_ret: Mutex<Result<(), channelmonitor::ChannelMonitorUpdateErr>>,
8080
// If we reload a node with an old copy of ChannelMonitors, the ChannelManager deserialization
8181
// logic will automatically force-close our channels for us (as we don't have an up-to-date
@@ -86,7 +86,7 @@ pub struct TestChannelMonitor {
8686
pub should_update_manager: atomic::AtomicBool,
8787
}
8888
impl TestChannelMonitor {
89-
pub fn new(chain_monitor: Arc<dyn chaininterface::ChainWatchInterface>, broadcaster: Arc<dyn chaininterface::BroadcasterInterface>, logger: Arc<dyn Logger>, feeest: Arc<FeeEstimator>) -> Self {
89+
pub fn new(chain_monitor: Arc<dyn chaininterface::ChainWatchInterface>, broadcaster: Arc<TestBroadcaster>, logger: Arc<dyn Logger>, feeest: Arc<FuzzEstimator>) -> Self {
9090
Self {
9191
simple_monitor: Arc::new(channelmonitor::SimpleManyChannelMonitor::new(chain_monitor, broadcaster, logger.clone(), feeest)),
9292
logger,

lightning/src/chain/keysinterface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,6 @@ impl KeysInterface for KeysManager {
620620
let child_privkey = self.channel_id_master_key.ckd_priv(&self.secp_ctx, ChildNumber::from_hardened_idx(child_ix as u32).expect("key space exhausted")).expect("Your RNG is busted");
621621
sha.input(&child_privkey.private_key.key[..]);
622622

623-
(Sha256::from_engine(sha).into_inner())
623+
Sha256::from_engine(sha).into_inner()
624624
}
625625
}

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
14321432
};
14331433
// Because we have exclusive ownership of the channel here we can release the channel_state
14341434
// lock before add_monitor
1435-
if let Err(e) = self.monitor.add_monitor(chan_monitor.get_funding_txo().unwrap(), chan_monitor) {
1435+
if let Err(e) = self.monitor.add_monitor(chan_monitor.get_funding_txo(), chan_monitor) {
14361436
match e {
14371437
ChannelMonitorUpdateErr::PermanentFailure => {
14381438
match handle_error!(self, Err(MsgHandleErrInternal::from_finish_shutdown("ChannelMonitor storage failure", *temporary_channel_id, chan.force_shutdown(true), None)), chan.get_their_node_id()) {
@@ -2293,7 +2293,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
22932293
};
22942294
// Because we have exclusive ownership of the channel here we can release the channel_state
22952295
// lock before add_monitor
2296-
if let Err(e) = self.monitor.add_monitor(monitor_update.get_funding_txo().unwrap(), monitor_update) {
2296+
if let Err(e) = self.monitor.add_monitor(monitor_update.get_funding_txo(), monitor_update) {
22972297
match e {
22982298
ChannelMonitorUpdateErr::PermanentFailure => {
22992299
// Note that we reply with the new channel_id in error messages if we gave up on the

lightning/src/ln/channelmonitor.rs

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

lightning/src/ln/functional_test_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
148148
{
149149
let mut channel_monitors = HashMap::new();
150150
for monitor in deserialized_monitors.iter_mut() {
151-
channel_monitors.insert(monitor.get_funding_txo().unwrap(), monitor);
151+
channel_monitors.insert(monitor.get_funding_txo(), monitor);
152152
}
153153

154154
let mut w = test_utils::TestVecWriter(Vec::new());
@@ -167,7 +167,7 @@ impl<'a, 'b, 'c> Drop for Node<'a, 'b, 'c> {
167167
let chain_watch = Arc::new(chaininterface::ChainWatchInterfaceUtil::new(Network::Testnet, Arc::clone(&self.logger) as Arc<Logger>));
168168
let channel_monitor = test_utils::TestChannelMonitor::new(chain_watch.clone(), self.tx_broadcaster.clone(), self.logger.clone(), &feeest);
169169
for deserialized_monitor in deserialized_monitors.drain(..) {
170-
if let Err(_) = channel_monitor.add_monitor(deserialized_monitor.get_funding_txo().unwrap(), deserialized_monitor) {
170+
if let Err(_) = channel_monitor.add_monitor(deserialized_monitor.get_funding_txo(), deserialized_monitor) {
171171
panic!();
172172
}
173173
}

lightning/src/ln/functional_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3766,7 +3766,7 @@ fn test_no_txn_manager_serialize_deserialize() {
37663766
keys_manager = test_utils::TestKeysInterface::new(&nodes[0].node_seed, Network::Testnet, Arc::new(test_utils::TestLogger::new()));
37673767
let (_, nodes_0_deserialized_tmp) = {
37683768
let mut channel_monitors = HashMap::new();
3769-
channel_monitors.insert(chan_0_monitor.get_funding_txo().unwrap(), &mut chan_0_monitor);
3769+
channel_monitors.insert(chan_0_monitor.get_funding_txo(), &mut chan_0_monitor);
37703770
<(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
37713771
default_config: config,
37723772
keys_manager: &keys_manager,
@@ -3780,7 +3780,7 @@ fn test_no_txn_manager_serialize_deserialize() {
37803780
nodes_0_deserialized = nodes_0_deserialized_tmp;
37813781
assert!(nodes_0_read.is_empty());
37823782

3783-
assert!(nodes[0].chan_monitor.add_monitor(chan_0_monitor.get_funding_txo().unwrap(), chan_0_monitor).is_ok());
3783+
assert!(nodes[0].chan_monitor.add_monitor(chan_0_monitor.get_funding_txo(), chan_0_monitor).is_ok());
37843784
nodes[0].node = &nodes_0_deserialized;
37853785
nodes[0].block_notifier.register_listener(nodes[0].node);
37863786
assert_eq!(nodes[0].node.list_channels().len(), 1);
@@ -3839,7 +3839,7 @@ fn test_simple_manager_serialize_deserialize() {
38393839
keys_manager = test_utils::TestKeysInterface::new(&nodes[0].node_seed, Network::Testnet, Arc::new(test_utils::TestLogger::new()));
38403840
let (_, nodes_0_deserialized_tmp) = {
38413841
let mut channel_monitors = HashMap::new();
3842-
channel_monitors.insert(chan_0_monitor.get_funding_txo().unwrap(), &mut chan_0_monitor);
3842+
channel_monitors.insert(chan_0_monitor.get_funding_txo(), &mut chan_0_monitor);
38433843
<(Sha256dHash, ChannelManager<EnforcingChannelKeys, &test_utils::TestChannelMonitor, &test_utils::TestBroadcaster, &test_utils::TestKeysInterface, &test_utils::TestFeeEstimator>)>::read(&mut nodes_0_read, ChannelManagerReadArgs {
38443844
default_config: UserConfig::default(),
38453845
keys_manager: &keys_manager,
@@ -3853,7 +3853,7 @@ fn test_simple_manager_serialize_deserialize() {
38533853
nodes_0_deserialized = nodes_0_deserialized_tmp;
38543854
assert!(nodes_0_read.is_empty());
38553855

3856-
assert!(nodes[0].chan_monitor.add_monitor(chan_0_monitor.get_funding_txo().unwrap(), chan_0_monitor).is_ok());
3856+
assert!(nodes[0].chan_monitor.add_monitor(chan_0_monitor.get_funding_txo(), chan_0_monitor).is_ok());
38573857
nodes[0].node = &nodes_0_deserialized;
38583858
check_added_monitors!(nodes[0], 1);
38593859

@@ -3935,7 +3935,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
39353935
monitor: nodes[0].chan_monitor,
39363936
tx_broadcaster: nodes[0].tx_broadcaster.clone(),
39373937
logger: Arc::new(test_utils::TestLogger::new()),
3938-
channel_monitors: &mut node_0_stale_monitors.iter_mut().map(|monitor| { (monitor.get_funding_txo().unwrap(), monitor) }).collect(),
3938+
channel_monitors: &mut node_0_stale_monitors.iter_mut().map(|monitor| { (monitor.get_funding_txo(), monitor) }).collect(),
39393939
}) { } else {
39403940
panic!("If the monitor(s) are stale, this indicates a bug and we should get an Err return");
39413941
};
@@ -3949,7 +3949,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
39493949
monitor: nodes[0].chan_monitor,
39503950
tx_broadcaster: nodes[0].tx_broadcaster.clone(),
39513951
logger: Arc::new(test_utils::TestLogger::new()),
3952-
channel_monitors: &mut node_0_monitors.iter_mut().map(|monitor| { (monitor.get_funding_txo().unwrap(), monitor) }).collect(),
3952+
channel_monitors: &mut node_0_monitors.iter_mut().map(|monitor| { (monitor.get_funding_txo(), monitor) }).collect(),
39533953
}).unwrap();
39543954
nodes_0_deserialized = nodes_0_deserialized_tmp;
39553955
assert!(nodes_0_read.is_empty());
@@ -3962,7 +3962,7 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
39623962
}
39633963

39643964
for monitor in node_0_monitors.drain(..) {
3965-
assert!(nodes[0].chan_monitor.add_monitor(monitor.get_funding_txo().unwrap(), monitor).is_ok());
3965+
assert!(nodes[0].chan_monitor.add_monitor(monitor.get_funding_txo(), monitor).is_ok());
39663966
check_added_monitors!(nodes[0], 1);
39673967
}
39683968
nodes[0].node = &nodes_0_deserialized;

lightning/src/ln/msgs.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use bitcoin::blockdata::script::Script;
2323

2424
use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
2525

26-
use std::error::Error;
2726
use std::{cmp, fmt};
2827
use std::io::Read;
2928
use std::result::Result;
@@ -688,21 +687,16 @@ pub(crate) struct OnionErrorPacket {
688687
pub(crate) data: Vec<u8>,
689688
}
690689

691-
impl Error for DecodeError {
692-
fn description(&self) -> &str {
693-
match *self {
694-
DecodeError::UnknownVersion => "Unknown realm byte in Onion packet",
695-
DecodeError::UnknownRequiredFeature => "Unknown required feature preventing decode",
696-
DecodeError::InvalidValue => "Nonsense bytes didn't map to the type they were interpreted as",
697-
DecodeError::ShortRead => "Packet extended beyond the provided bytes",
698-
DecodeError::BadLengthDescriptor => "A length descriptor in the packet didn't describe the later data correctly",
699-
DecodeError::Io(ref e) => e.description(),
700-
}
701-
}
702-
}
703690
impl fmt::Display for DecodeError {
704691
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
705-
f.write_str(self.description())
692+
match *self {
693+
DecodeError::UnknownVersion => f.write_str("Unknown realm byte in Onion packet"),
694+
DecodeError::UnknownRequiredFeature => f.write_str("Unknown required feature preventing decode"),
695+
DecodeError::InvalidValue => f.write_str("Nonsense bytes didn't map to the type they were interpreted as"),
696+
DecodeError::ShortRead => f.write_str("Packet extended beyond the provided bytes"),
697+
DecodeError::BadLengthDescriptor => f.write_str("A length descriptor in the packet didn't describe the later data correctly"),
698+
DecodeError::Io(ref e) => e.fmt(f),
699+
}
706700
}
707701
}
708702

lightning/src/ln/onchaintx.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -713,18 +713,14 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
713713

714714
// Build, bump and rebroadcast tx accordingly
715715
log_trace!(self, "Bumping {} candidates", bump_candidates.len());
716-
let mut pending_claim_updates = Vec::with_capacity(bump_candidates.len());
717716
for (first_claim_txid, claim_material) in bump_candidates.iter() {
718717
if let Some((new_timer, new_feerate, bump_tx)) = self.generate_claim_tx(height, &claim_material, &*fee_estimator) {
719718
log_trace!(self, "Broadcast onchain {}", log_tx!(bump_tx));
720719
broadcaster.broadcast_transaction(&bump_tx);
721-
pending_claim_updates.push((*first_claim_txid, new_timer, new_feerate));
722-
}
723-
}
724-
for updates in pending_claim_updates {
725-
if let Some(claim_material) = self.pending_claim_requests.get_mut(&updates.0) {
726-
claim_material.height_timer = updates.1;
727-
claim_material.feerate_previous = updates.2;
720+
if let Some(claim_material) = self.pending_claim_requests.get_mut(first_claim_txid) {
721+
claim_material.height_timer = new_timer;
722+
claim_material.feerate_previous = new_feerate;
723+
}
728724
}
729725
}
730726
}

lightning/src/util/macro_logger.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,10 @@ macro_rules! log_funding_channel_id {
5555
}
5656
}
5757

58-
pub(crate) struct DebugFundingInfo<'a, T: 'a>(pub &'a Option<(OutPoint, T)>);
58+
pub(crate) struct DebugFundingInfo<'a, T: 'a>(pub &'a (OutPoint, T));
5959
impl<'a, T> std::fmt::Display for DebugFundingInfo<'a, T> {
6060
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
61-
match self.0.as_ref() {
62-
Some(&(ref funding_output, _)) => DebugBytes(&funding_output.to_channel_id()[..]).fmt(f),
63-
None => write!(f, "without funding output set"),
64-
}
61+
DebugBytes(&(self.0).0.to_channel_id()[..]).fmt(f)
6562
}
6663
}
6764
macro_rules! log_funding_info {

0 commit comments

Comments
 (0)