Skip to content

Commit 431f807

Browse files
authored
Merge pull request #984 from TheBlueMatt/2021-06-more-chan-data
Expose More Information about Channels and structs
2 parents 84967fa + 46c3ba4 commit 431f807

File tree

11 files changed

+239
-92
lines changed

11 files changed

+239
-92
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ use bitcoin::hashes::sha256::Hash as Sha256;
3030
use bitcoin::hash_types::{BlockHash, WPubkeyHash};
3131

3232
use lightning::chain;
33-
use lightning::chain::{chainmonitor, channelmonitor, Confirm, Watch};
33+
use lightning::chain::{BestBlock, chainmonitor, channelmonitor, Confirm, Watch};
3434
use lightning::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, MonitorEvent};
3535
use lightning::chain::transaction::OutPoint;
3636
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
3737
use lightning::chain::keysinterface::{KeysInterface, InMemorySigner};
3838
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
39-
use lightning::ln::channelmanager::{BestBlock, ChainParameters, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs};
39+
use lightning::ln::channelmanager::{ChainParameters, ChannelManager, PaymentSendFailure, ChannelManagerReadArgs};
4040
use lightning::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
4141
use lightning::ln::msgs::{CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init};
4242
use lightning::util::enforcing_trait_impls::{EnforcingSigner, INITIAL_REVOKED_COMMITMENT_NUMBER};

fuzz/src/full_stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ use bitcoin::hashes::sha256::Hash as Sha256;
2727
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
2828

2929
use lightning::chain;
30-
use lightning::chain::{Confirm, Listen};
30+
use lightning::chain::{BestBlock, Confirm, Listen};
3131
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
3232
use lightning::chain::chainmonitor;
3333
use lightning::chain::transaction::OutPoint;
3434
use lightning::chain::keysinterface::{InMemorySigner, KeysInterface};
3535
use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
36-
use lightning::ln::channelmanager::{BestBlock, ChainParameters, ChannelManager};
36+
use lightning::ln::channelmanager::{ChainParameters, ChannelManager};
3737
use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor};
3838
use lightning::ln::msgs::DecodeError;
3939
use lightning::routing::router::get_route;

fuzz/src/router.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,13 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
212212
remote_network_id: *rnid,
213213
counterparty_features: InitFeatures::known(),
214214
channel_value_satoshis: slice_to_be64(get_slice!(8)),
215-
user_id: 0,
216-
inbound_capacity_msat: 0,
217-
is_outbound: true,
218-
is_funding_locked: true,
219-
is_usable: true,
220-
is_public: true,
215+
user_id: 0, inbound_capacity_msat: 0,
216+
to_self_reserve_satoshis: None,
217+
to_remote_reserve_satoshis: 0,
218+
confirmations_required: None,
219+
spend_csv_on_our_commitment_funds: None,
220+
is_outbound: true, is_funding_locked: true,
221+
is_usable: true, is_public: true,
221222
outbound_capacity_msat: 0,
222223
counterparty_forwarding_info: None,
223224
});

lightning-background-processor/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,12 @@ mod tests {
174174
use bitcoin::blockdata::constants::genesis_block;
175175
use bitcoin::blockdata::transaction::{Transaction, TxOut};
176176
use bitcoin::network::constants::Network;
177-
use lightning::chain::Confirm;
178-
use lightning::chain::chainmonitor;
177+
use lightning::chain::{BestBlock, Confirm, chainmonitor};
179178
use lightning::chain::channelmonitor::ANTI_REORG_DELAY;
180179
use lightning::chain::keysinterface::{InMemorySigner, KeysInterface, KeysManager};
181180
use lightning::chain::transaction::OutPoint;
182181
use lightning::get_event_msg;
183-
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, BestBlock, ChainParameters, ChannelManager, SimpleArcChannelManager};
182+
use lightning::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChainParameters, ChannelManager, SimpleArcChannelManager};
184183
use lightning::ln::features::InitFeatures;
185184
use lightning::ln::msgs::ChannelMessageHandler;
186185
use lightning::ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor};

lightning/src/chain/channelmonitor.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ use ln::{PaymentHash, PaymentPreimage};
3737
use ln::msgs::DecodeError;
3838
use ln::chan_utils;
3939
use ln::chan_utils::{CounterpartyCommitmentSecrets, HTLCOutputInCommitment, HTLCType, ChannelTransactionParameters, HolderCommitmentTransaction};
40-
use ln::channelmanager::{BestBlock, HTLCSource};
40+
use ln::channelmanager::HTLCSource;
4141
use chain;
42-
use chain::WatchedOutput;
42+
use chain::{BestBlock, WatchedOutput};
4343
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
4444
use chain::transaction::{OutPoint, TransactionData};
4545
use chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, Sign, KeysInterface};
@@ -1189,6 +1189,12 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
11891189
txids.dedup();
11901190
txids
11911191
}
1192+
1193+
/// Gets the latest best block which was connected either via the [`chain::Listen`] or
1194+
/// [`chain::Confirm`] interfaces.
1195+
pub fn current_best_block(&self) -> BestBlock {
1196+
self.inner.lock().unwrap().best_block.clone()
1197+
}
11921198
}
11931199

11941200
impl<Signer: Sign> ChannelMonitorImpl<Signer> {
@@ -2827,11 +2833,11 @@ mod tests {
28272833
use bitcoin::hash_types::Txid;
28282834
use bitcoin::network::constants::Network;
28292835
use hex;
2836+
use chain::BestBlock;
28302837
use chain::channelmonitor::ChannelMonitor;
28312838
use chain::package::{WEIGHT_OFFERED_HTLC, WEIGHT_RECEIVED_HTLC, WEIGHT_REVOKED_OFFERED_HTLC, WEIGHT_REVOKED_RECEIVED_HTLC, WEIGHT_REVOKED_OUTPUT};
28322839
use chain::transaction::OutPoint;
28332840
use ln::{PaymentPreimage, PaymentHash};
2834-
use ln::channelmanager::BestBlock;
28352841
use ln::chan_utils;
28362842
use ln::chan_utils::{HTLCOutputInCommitment, ChannelPublicKeys, ChannelTransactionParameters, HolderCommitmentTransaction, CounterpartyChannelTransactionParameters};
28372843
use util::test_utils::{TestLogger, TestBroadcaster, TestFeeEstimator};

lightning/src/chain/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
//! Structs and traits which allow other parts of rust-lightning to interact with the blockchain.
1111
1212
use bitcoin::blockdata::block::{Block, BlockHeader};
13+
use bitcoin::blockdata::constants::genesis_block;
1314
use bitcoin::blockdata::script::Script;
1415
use bitcoin::blockdata::transaction::{Transaction, TxOut};
1516
use bitcoin::hash_types::{BlockHash, Txid};
17+
use bitcoin::network::constants::Network;
1618

1719
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateErr, MonitorEvent};
1820
use chain::keysinterface::Sign;
@@ -28,6 +30,35 @@ pub mod keysinterface;
2830
pub(crate) mod onchaintx;
2931
pub(crate) mod package;
3032

33+
/// The best known block as identified by its hash and height.
34+
#[derive(Clone, Copy, PartialEq)]
35+
pub struct BestBlock {
36+
block_hash: BlockHash,
37+
height: u32,
38+
}
39+
40+
impl BestBlock {
41+
/// Constructs a `BestBlock` that represents the genesis block at height 0 of the given
42+
/// network.
43+
pub fn from_genesis(network: Network) -> Self {
44+
BestBlock {
45+
block_hash: genesis_block(network).header.block_hash(),
46+
height: 0,
47+
}
48+
}
49+
50+
/// Returns a `BestBlock` as identified by the given block hash and height.
51+
pub fn new(block_hash: BlockHash, height: u32) -> Self {
52+
BestBlock { block_hash, height }
53+
}
54+
55+
/// Returns the best block hash.
56+
pub fn block_hash(&self) -> BlockHash { self.block_hash }
57+
58+
/// Returns the best block height.
59+
pub fn height(&self) -> u32 { self.height }
60+
}
61+
3162
/// An error when accessing the chain via [`Access`].
3263
#[derive(Clone)]
3364
pub enum AccessError {

0 commit comments

Comments
 (0)