Skip to content

Commit c971970

Browse files
committed
Refer to generic types by importing them instead of a super-mod.
This avoids one case the bindings generation hasn't bothered to handle by simply importing types that are referred to.
1 parent 81aac1c commit c971970

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use util::ser::{Writeable, Writer, Readable};
3333

3434
use ln::chan_utils;
3535
use ln::chan_utils::{HTLCOutputInCommitment, make_funding_redeemscript, ChannelPublicKeys, LocalCommitmentTransaction, PreCalculatedTxCreationKeys};
36-
use ln::msgs;
36+
use ln::msgs::UnsignedChannelAnnouncement;
3737

3838
use std::sync::atomic::{AtomicUsize, Ordering};
3939
use std::io::Error;
@@ -316,7 +316,7 @@ pub trait ChannelKeys : Send+Clone {
316316
/// Note that if this fails or is rejected, the channel will not be publicly announced and
317317
/// our counterparty may (though likely will not) close the channel on us for violating the
318318
/// protocol.
319-
fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
319+
fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
320320

321321
/// Set the remote channel basepoints and remote/local to_self_delay.
322322
/// This is done immediately on incoming channels and as soon as the channel is accepted on outgoing channels.
@@ -584,7 +584,7 @@ impl ChannelKeys for InMemoryChannelKeys {
584584
Ok(secp_ctx.sign(&sighash, &self.funding_key))
585585
}
586586

587-
fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
587+
fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
588588
let msghash = hash_to_message!(&Sha256dHash::hash(&msg.encode()[..])[..]);
589589
Ok(secp_ctx.sign(&msghash, &self.funding_key))
590590
}

lightning/src/ln/chan_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use util::byte_utils;
3030

3131
use bitcoin::secp256k1::key::{SecretKey, PublicKey};
3232
use bitcoin::secp256k1::{Secp256k1, Signature};
33+
use bitcoin::secp256k1::Error as SecpError;
3334
use bitcoin::secp256k1;
3435

3536
use std::{cmp, mem};
@@ -357,7 +358,7 @@ impl_writeable!(ChannelPublicKeys, 33*5, {
357358

358359
impl TxCreationKeys {
359360
/// Create a new TxCreationKeys from channel base points and the per-commitment point
360-
pub fn new<T: secp256k1::Signing + secp256k1::Verification>(secp_ctx: &Secp256k1<T>, per_commitment_point: &PublicKey, a_delayed_payment_base: &PublicKey, a_htlc_base: &PublicKey, b_revocation_base: &PublicKey, b_htlc_base: &PublicKey) -> Result<TxCreationKeys, secp256k1::Error> {
361+
pub fn new<T: secp256k1::Signing + secp256k1::Verification>(secp_ctx: &Secp256k1<T>, per_commitment_point: &PublicKey, a_delayed_payment_base: &PublicKey, a_htlc_base: &PublicKey, b_revocation_base: &PublicKey, b_htlc_base: &PublicKey) -> Result<TxCreationKeys, SecpError> {
361362
Ok(TxCreationKeys {
362363
per_commitment_point: per_commitment_point.clone(),
363364
revocation_key: derive_public_revocation_key(&secp_ctx, &per_commitment_point, &b_revocation_base)?,

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpd
4242
use ln::features::{InitFeatures, NodeFeatures};
4343
use routing::router::{Route, RouteHop};
4444
use ln::msgs;
45+
use ln::msgs::NetAddress;
4546
use ln::onion_utils;
4647
use ln::msgs::{ChannelMessageHandler, DecodeError, LightningError, OptionalField};
4748
use chain::keysinterface::{ChannelKeys, KeysInterface, KeysManager, InMemoryChannelKeys};
4849
use util::config::UserConfig;
50+
use util::events::{Event, EventsProvider, MessageSendEvent, MessageSendEventsProvider};
4951
use util::{byte_utils, events};
5052
use util::ser::{Readable, ReadableArgs, MaybeReadable, Writeable, Writer};
5153
use util::chacha20::{ChaCha20, ChaChaReader};
@@ -312,7 +314,7 @@ pub(super) struct ChannelHolder<ChanSigner: ChannelKeys> {
312314
claimable_htlcs: HashMap<(PaymentHash, Option<PaymentSecret>), Vec<ClaimableHTLC>>,
313315
/// Messages to send to peers - pushed to in the same lock that they are generated in (except
314316
/// for broadcast messages, where ordering isn't as strict).
315-
pub(super) pending_msg_events: Vec<events::MessageSendEvent>,
317+
pub(super) pending_msg_events: Vec<MessageSendEvent>,
316318
}
317319

318320
/// State we hold per-peer. In the future we should put channels in here, but for now we only hold
@@ -1483,7 +1485,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
14831485
// be absurd. We ensure this by checking that at least 500 (our stated public contract on when
14841486
// broadcast_node_announcement panics) of the maximum-length addresses would fit in a 64KB
14851487
// message...
1486-
const HALF_MESSAGE_IS_ADDRS: u32 = ::std::u16::MAX as u32 / (msgs::NetAddress::MAX_LEN as u32 + 1) / 2;
1488+
const HALF_MESSAGE_IS_ADDRS: u32 = ::std::u16::MAX as u32 / (NetAddress::MAX_LEN as u32 + 1) / 2;
14871489
#[deny(const_err)]
14881490
#[allow(dead_code)]
14891491
// ...by failing to compile if the number of addresses that would be half of a message is
@@ -1503,7 +1505,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
15031505
/// only Tor Onion addresses.
15041506
///
15051507
/// Panics if addresses is absurdly large (more than 500).
1506-
pub fn broadcast_node_announcement(&self, rgb: [u8; 3], alias: [u8; 32], addresses: Vec<msgs::NetAddress>) {
1508+
pub fn broadcast_node_announcement(&self, rgb: [u8; 3], alias: [u8; 32], addresses: Vec<NetAddress>) {
15071509
let _ = self.total_consistency_lock.read().unwrap();
15081510

15091511
if addresses.len() > 500 {
@@ -2968,14 +2970,14 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
29682970
}
29692971
}
29702972

2971-
impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> events::MessageSendEventsProvider for ChannelManager<ChanSigner, M, T, K, F, L>
2973+
impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> MessageSendEventsProvider for ChannelManager<ChanSigner, M, T, K, F, L>
29722974
where M::Target: ManyChannelMonitor<Keys=ChanSigner>,
29732975
T::Target: BroadcasterInterface,
29742976
K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
29752977
F::Target: FeeEstimator,
29762978
L::Target: Logger,
29772979
{
2978-
fn get_and_clear_pending_msg_events(&self) -> Vec<events::MessageSendEvent> {
2980+
fn get_and_clear_pending_msg_events(&self) -> Vec<MessageSendEvent> {
29792981
// TODO: Event release to users and serialization is currently race-y: it's very easy for a
29802982
// user to serialize a ChannelManager with pending events in it and lose those events on
29812983
// restart. This is doubly true for the fail/fulfill-backs from monitor events!
@@ -2999,14 +3001,14 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
29993001
}
30003002
}
30013003

3002-
impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> events::EventsProvider for ChannelManager<ChanSigner, M, T, K, F, L>
3004+
impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> EventsProvider for ChannelManager<ChanSigner, M, T, K, F, L>
30033005
where M::Target: ManyChannelMonitor<Keys=ChanSigner>,
30043006
T::Target: BroadcasterInterface,
30053007
K::Target: KeysInterface<ChanKeySigner = ChanSigner>,
30063008
F::Target: FeeEstimator,
30073009
L::Target: Logger,
30083010
{
3009-
fn get_and_clear_pending_events(&self) -> Vec<events::Event> {
3011+
fn get_and_clear_pending_events(&self) -> Vec<Event> {
30103012
// TODO: Event release to users and serialization is currently race-y: it's very easy for a
30113013
// user to serialize a ChannelManager with pending events in it and lose those events on
30123014
// restart. This is doubly true for the fail/fulfill-backs from monitor events!

lightning/src/ln/channelmonitor.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ use chain::keysinterface::{SpendableOutputDescriptor, ChannelKeys};
4747
use util::logger::Logger;
4848
use util::ser::{Readable, MaybeReadable, Writer, Writeable, U48};
4949
use util::{byte_utils, events};
50+
use util::events::Event;
5051

5152
use std::collections::{HashMap, hash_map};
5253
use std::sync::Mutex;
5354
use std::{hash,cmp, mem};
5455
use std::ops::Deref;
56+
use std::io::Error;
5557

5658
/// An update generated by the underlying Channel itself which contains some new information the
5759
/// ChannelMonitor should be made aware of.
@@ -307,7 +309,7 @@ impl<Key : Send + cmp::Eq + hash::Hash, ChanSigner: ChannelKeys, T: Deref, F: De
307309
L::Target: Logger,
308310
C::Target: ChainWatchInterface,
309311
{
310-
fn get_and_clear_pending_events(&self) -> Vec<events::Event> {
312+
fn get_and_clear_pending_events(&self) -> Vec<Event> {
311313
let mut pending_events = Vec::new();
312314
for chan in self.monitors.lock().unwrap().values_mut() {
313315
pending_events.append(&mut chan.get_and_clear_pending_events());
@@ -785,7 +787,7 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
785787
payment_preimages: HashMap<PaymentHash, PaymentPreimage>,
786788

787789
pending_htlcs_updated: Vec<HTLCUpdate>,
788-
pending_events: Vec<events::Event>,
790+
pending_events: Vec<Event>,
789791

790792
// Used to track onchain events, i.e transactions parts of channels confirmed on chain, on which
791793
// we have to take actions once they reach enough confs. Key is a block height timer, i.e we enforce
@@ -936,7 +938,7 @@ impl<ChanSigner: ChannelKeys + Writeable> ChannelMonitor<ChanSigner> {
936938
/// the "reorg path" (ie disconnecting blocks until you find a common ancestor from both the
937939
/// returned block hash and the the current chain and then reconnecting blocks to get to the
938940
/// best chain) upon deserializing the object!
939-
pub fn write_for_disk<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
941+
pub fn write_for_disk<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
940942
//TODO: We still write out all the serialization here manually instead of using the fancy
941943
//serialization framework we have, we should migrate things over to it.
942944
writer.write_all(&[SERIALIZATION_VERSION; 1])?;
@@ -1456,7 +1458,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
14561458
/// This is called by ManyChannelMonitor::get_and_clear_pending_events() and is equivalent to
14571459
/// EventsProvider::get_and_clear_pending_events() except that it requires &mut self as we do
14581460
/// no internal locking in ChannelMonitors.
1459-
pub fn get_and_clear_pending_events(&mut self) -> Vec<events::Event> {
1461+
pub fn get_and_clear_pending_events(&mut self) -> Vec<Event> {
14601462
let mut ret = Vec::new();
14611463
mem::swap(&mut ret, &mut self.pending_events);
14621464
ret
@@ -1959,7 +1961,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
19591961
},
19601962
OnchainEvent::MaturingOutput { descriptor } => {
19611963
log_trace!(logger, "Descriptor {} has got enough confirmations to be passed upstream", log_spendable!(descriptor));
1962-
self.pending_events.push(events::Event::SpendableOutputs {
1964+
self.pending_events.push(Event::SpendableOutputs {
19631965
outputs: vec![descriptor]
19641966
});
19651967
}
@@ -2429,7 +2431,7 @@ impl<ChanSigner: ChannelKeys + Readable> Readable for (BlockHash, ChannelMonitor
24292431
}
24302432

24312433
let pending_events_len: u64 = Readable::read(reader)?;
2432-
let mut pending_events = Vec::with_capacity(cmp::min(pending_events_len as usize, MAX_ALLOC_SIZE / mem::size_of::<events::Event>()));
2434+
let mut pending_events = Vec::with_capacity(cmp::min(pending_events_len as usize, MAX_ALLOC_SIZE / mem::size_of::<Event>()));
24332435
for _ in 0..pending_events_len {
24342436
if let Some(event) = MaybeReadable::read(reader)? {
24352437
pending_events.push(event);

lightning/src/routing/network_graph.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use bitcoin::blockdata::opcodes;
2020

2121
use chain::chaininterface::{ChainError, ChainWatchInterface};
2222
use ln::features::{ChannelFeatures, NodeFeatures};
23-
use ln::msgs::{DecodeError, ErrorAction, LightningError, RoutingMessageHandler, NetAddress, OptionalField, MAX_VALUE_MSAT};
23+
use ln::msgs::{DecodeError, ErrorAction, LightningError, RoutingMessageHandler, NetAddress, MAX_VALUE_MSAT};
24+
use ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, OptionalField};
2425
use ln::msgs;
2526
use util::ser::{Writeable, Readable, Writer};
2627
use util::logger::Logger;
@@ -154,7 +155,7 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
154155
self.network_graph.write().unwrap().update_channel(msg, Some(&self.secp_ctx))
155156
}
156157

157-
fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, Option<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> {
158+
fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(ChannelAnnouncement, Option<ChannelUpdate>, Option<ChannelUpdate>)> {
158159
let network_graph = self.network_graph.read().unwrap();
159160
let mut result = Vec::with_capacity(batch_amount as usize);
160161
let mut iter = network_graph.get_channels().range(starting_point..);
@@ -182,7 +183,7 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
182183
result
183184
}
184185

185-
fn get_next_node_announcements(&self, starting_point: Option<&PublicKey>, batch_amount: u8) -> Vec<msgs::NodeAnnouncement> {
186+
fn get_next_node_announcements(&self, starting_point: Option<&PublicKey>, batch_amount: u8) -> Vec<NodeAnnouncement> {
186187
let network_graph = self.network_graph.read().unwrap();
187188
let mut result = Vec::with_capacity(batch_amount as usize);
188189
let mut iter = if let Some(pubkey) = starting_point {

0 commit comments

Comments
 (0)