Skip to content

Commit ed9e7d0

Browse files
committed
Implement chain::Access trait
1 parent 389f960 commit ed9e7d0

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

src/lib.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mod error;
2929
pub mod event;
3030
mod hex_utils;
3131
mod io_utils;
32+
mod scid_utils;
3233
mod logger;
3334
mod peer_store;
3435

@@ -45,7 +46,7 @@ use logger::{
4546
};
4647

4748
use lightning::chain::keysinterface::{InMemorySigner, KeysInterface, KeysManager, Recipient};
48-
use lightning::chain::{chainmonitor, Access, BestBlock, Confirm, Filter, Watch};
49+
use lightning::chain::{chainmonitor, BestBlock, Confirm, Filter, Watch};
4950
use lightning::ln::channelmanager;
5051
use lightning::ln::channelmanager::{
5152
ChainParameters, ChannelManagerReadArgs, SimpleArcChannelManager,
@@ -227,8 +228,12 @@ impl LdkLiteBuilder {
227228
let blockchain = EsploraBlockchain::new(&config.esplora_server_url, BDK_CLIENT_STOP_GAP)
228229
.with_concurrency(BDK_CLIENT_CONCURRENCY);
229230

230-
let chain_access =
231-
Arc::new(LdkLiteChainAccess::new(blockchain, bdk_wallet, Arc::clone(&logger)));
231+
let chain_access = Arc::new(LdkLiteChainAccess::new(
232+
blockchain,
233+
bdk_wallet,
234+
Arc::clone(&config),
235+
Arc::clone(&logger),
236+
));
232237

233238
// Step 3: Initialize Persist
234239
let persister = Arc::new(FilesystemPersister::new(ldk_data_dir.clone()));
@@ -303,7 +308,7 @@ impl LdkLiteBuilder {
303308
Arc::new(io_utils::read_network_graph(Arc::clone(&config), Arc::clone(&logger))?);
304309
let gossip_sync = Arc::new(P2PGossipSync::new(
305310
Arc::clone(&network_graph),
306-
None::<Arc<dyn Access + Send + Sync>>,
311+
Some(Arc::clone(&chain_access)),
307312
Arc::clone(&logger),
308313
));
309314

@@ -963,7 +968,7 @@ type PeerManager = SimpleArcPeerManager<
963968
ChainMonitor,
964969
LdkLiteChainAccess<bdk::sled::Tree>,
965970
LdkLiteChainAccess<bdk::sled::Tree>,
966-
dyn Access + Send + Sync,
971+
LdkLiteChainAccess<bdk::sled::Tree>,
967972
FilesystemLogger,
968973
>;
969974

@@ -985,8 +990,11 @@ type InvoicePayer<F> = payment::InvoicePayer<
985990
type Router = DefaultRouter<Arc<NetworkGraph>, Arc<FilesystemLogger>>;
986991
type Scorer = ProbabilisticScorer<Arc<NetworkGraph>, Arc<FilesystemLogger>>;
987992

988-
type GossipSync =
989-
P2PGossipSync<Arc<NetworkGraph>, Arc<dyn Access + Send + Sync>, Arc<FilesystemLogger>>;
993+
type GossipSync = P2PGossipSync<
994+
Arc<NetworkGraph>,
995+
Arc<LdkLiteChainAccess<bdk::sled::Tree>>,
996+
Arc<FilesystemLogger>,
997+
>;
990998

991999
pub(crate) type NetworkGraph = gossip::NetworkGraph<Arc<FilesystemLogger>>;
9921000

src/scid_utils.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copied from `rust-lightning`
2+
//
3+
// This file is Copyright its original authors, visible in version control
4+
// history.
5+
//
6+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
7+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
9+
// You may not use this file except in accordance with one or both of these
10+
// licenses.
11+
12+
/// Maximum transaction index that can be used in a `short_channel_id`.
13+
/// This value is based on the 3-bytes available for tx index.
14+
pub const MAX_SCID_TX_INDEX: u64 = 0x00ffffff;
15+
16+
/// Maximum vout index that can be used in a `short_channel_id`. This
17+
/// value is based on the 2-bytes available for the vout index.
18+
pub const MAX_SCID_VOUT_INDEX: u64 = 0xffff;
19+
20+
/// Extracts the block height (most significant 3-bytes) from the `short_channel_id`
21+
pub fn block_from_scid(short_channel_id: &u64) -> u32 {
22+
return (short_channel_id >> 40) as u32;
23+
}
24+
25+
/// Extracts the tx index (bytes [2..4]) from the `short_channel_id`
26+
pub fn tx_index_from_scid(short_channel_id: &u64) -> u32 {
27+
return ((short_channel_id >> 16) & MAX_SCID_TX_INDEX) as u32;
28+
}
29+
30+
/// Extracts the vout (bytes [0..2]) from the `short_channel_id`
31+
pub fn vout_from_scid(short_channel_id: &u64) -> u16 {
32+
return ((short_channel_id) & MAX_SCID_VOUT_INDEX) as u16;
33+
}

0 commit comments

Comments
 (0)