Skip to content

Commit aef2aa6

Browse files
authored
Merge branch 'lightningdevkit:main' into main
2 parents bb6c7f6 + be4bb58 commit aef2aa6

File tree

26 files changed

+2235
-224
lines changed

26 files changed

+2235
-224
lines changed

.github/workflows/build.yml

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,68 @@ jobs:
1212
beta,
1313
# 1.41.1 is MSRV for Rust-Lightning, lightning-invoice, and lightning-persister
1414
1.41.1,
15-
# 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, lightning-background-processor, and coverage generation
15+
# 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, lightning-background-processor
1616
1.45.2,
1717
# 1.47.0 will be the MSRV for no-std builds using hashbrown once core2 is updated
18-
1.47.0]
18+
1.47.0,
19+
# 1.59.0 is the MSRV for lightning-transaction-sync
20+
1.59.0]
1921
include:
2022
- toolchain: stable
2123
build-net-tokio: true
2224
build-no-std: true
2325
build-futures: true
26+
build-tx-sync: true
27+
coverage: true
2428
- toolchain: stable
2529
platform: macos-latest
2630
build-net-tokio: true
2731
build-no-std: true
2832
build-futures: true
33+
build-tx-sync: true
2934
- toolchain: beta
3035
platform: macos-latest
3136
build-net-tokio: true
3237
build-no-std: true
3338
build-futures: true
39+
build-tx-sync: true
3440
- toolchain: stable
3541
platform: windows-latest
3642
build-net-tokio: true
3743
build-no-std: true
3844
build-futures: true
45+
build-tx-sync: false
3946
- toolchain: beta
4047
platform: windows-latest
4148
build-net-tokio: true
4249
build-no-std: true
4350
build-futures: true
51+
build-tx-sync: false
4452
- toolchain: beta
4553
build-net-tokio: true
4654
build-no-std: true
4755
build-futures: true
56+
build-tx-sync: true
4857
- toolchain: 1.41.1
4958
build-no-std: false
5059
test-log-variants: true
5160
build-futures: false
61+
build-tx-sync: false
5262
- toolchain: 1.45.2
5363
build-net-old-tokio: true
5464
build-net-tokio: true
5565
build-no-std: false
5666
build-futures: true
57-
coverage: true
67+
build-tx-sync: false
5868
- toolchain: 1.47.0
5969
build-futures: true
6070
build-no-std: true
71+
build-tx-sync: false
72+
- toolchain: 1.59.0
73+
build-net-tokio: false
74+
build-no-std: false
75+
build-futures: false
76+
build-tx-sync: true
6177
runs-on: ${{ matrix.platform }}
6278
steps:
6379
- name: Checkout source code
@@ -73,10 +89,10 @@ jobs:
7389
run: cargo update -p tokio --precise "1.14.0" --verbose
7490
env:
7591
CARGO_NET_GIT_FETCH_WITH_CLI: "true"
76-
- name: Build on Rust ${{ matrix.toolchain }} with net-tokio
77-
if: "matrix.build-net-tokio && !matrix.coverage"
92+
- name: Build on Rust ${{ matrix.toolchain }} with net-tokio and tx-sync
93+
if: "matrix.build-net-tokio && !matrix.coverage && matrix.build-tx-sync"
7894
run: cargo build --verbose --color always
79-
- name: Build on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
95+
- name: Build on Rust ${{ matrix.toolchain }} with net-tokio, tx-sync, and full code-linking for coverage generation
8096
if: matrix.coverage
8197
run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
8298
- name: Build on Rust ${{ matrix.toolchain }}
@@ -108,14 +124,32 @@ jobs:
108124
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
109125
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
110126
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
127+
- name: Build Transaction Sync Clients on Rust ${{ matrix.toolchain }} with features
128+
if: "matrix.build-tx-sync && !matrix.coverage"
129+
run: |
130+
cd lightning-transaction-sync
131+
cargo build --verbose --color always --features esplora-blocking
132+
cargo build --verbose --color always --features esplora-async
133+
- name: Build transaction sync clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
134+
if: "matrix.build-tx-sync && matrix.coverage"
135+
run: |
136+
cd lightning-transaction-sync
137+
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-blocking
138+
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async
139+
- name: Test transaction sync clients on Rust ${{ matrix.toolchain }} with features
140+
if: "matrix.build-tx-sync"
141+
run: |
142+
cd lightning-transaction-sync
143+
cargo test --verbose --color always --features esplora-blocking
144+
cargo test --verbose --color always --features esplora-async
111145
- name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }}
112146
if: "matrix.toolchain == 'stable'"
113147
run: |
114148
cd lightning && cargo test --verbose --color always --features backtrace
115149
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio
116-
if: "matrix.build-net-tokio && !matrix.coverage"
150+
if: "matrix.build-net-tokio && !matrix.coverage && matrix.build-tx-sync"
117151
run: cargo test --verbose --color always
118-
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
152+
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio, tx-sync, and full code-linking for coverage generation
119153
if: matrix.coverage
120154
run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
121155
- name: Test no-std builds on Rust ${{ matrix.toolchain }}
@@ -349,7 +383,7 @@ jobs:
349383
linting:
350384
runs-on: ubuntu-latest
351385
env:
352-
TOOLCHAIN: 1.47.0
386+
TOOLCHAIN: stable
353387
steps:
354388
- name: Checkout source code
355389
uses: actions/checkout@v3

ARCH.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ At a high level, some of the common interfaces fit together as follows:
5151
--------------- / (as EventsProvider) ^ | |
5252
| PeerManager |- \ | | |
5353
--------------- \ | (is-a) | |
54-
| ----------------- \ _---------------- / /
55-
| | chain::Access | \ / | ChainMonitor |---------------
56-
| ----------------- \ / ----------------
54+
| -------------- \ _---------------- / /
55+
| | UtxoLookup | \ / | ChainMonitor |---------------
56+
| -------------- \ / ----------------
5757
| ^ \ / |
5858
(as RoutingMessageHandler) | v v
5959
\ ----------------- --------- -----------------

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
members = [
44
"lightning",
55
"lightning-block-sync",
6+
"lightning-transaction-sync",
67
"lightning-invoice",
78
"lightning-net-tokio",
89
"lightning-persister",

fuzz/src/full_stack.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,Ig
4141
use lightning::ln::msgs::{self, DecodeError};
4242
use lightning::ln::script::ShutdownScript;
4343
use lightning::routing::gossip::{P2PGossipSync, NetworkGraph};
44+
use lightning::routing::utxo::UtxoLookup;
4445
use lightning::routing::router::{find_route, InFlightHtlcs, PaymentParameters, Route, RouteHop, RouteParameters, Router};
4546
use lightning::routing::scoring::FixedPenaltyScorer;
4647
use lightning::util::config::UserConfig;
@@ -183,7 +184,7 @@ impl<'a> std::hash::Hash for Peer<'a> {
183184
type ChannelMan<'a> = ChannelManager<
184185
Arc<chainmonitor::ChainMonitor<EnforcingSigner, Arc<dyn chain::Filter>, Arc<TestBroadcaster>, Arc<FuzzEstimator>, Arc<dyn Logger>, Arc<TestPersister>>>,
185186
Arc<TestBroadcaster>, Arc<KeyProvider>, Arc<KeyProvider>, Arc<KeyProvider>, Arc<FuzzEstimator>, &'a FuzzRouter, Arc<dyn Logger>>;
186-
type PeerMan<'a> = PeerManager<Peer<'a>, Arc<ChannelMan<'a>>, Arc<P2PGossipSync<Arc<NetworkGraph<Arc<dyn Logger>>>, Arc<dyn chain::Access>, Arc<dyn Logger>>>, IgnoringMessageHandler, Arc<dyn Logger>, IgnoringMessageHandler, Arc<KeyProvider>>;
187+
type PeerMan<'a> = PeerManager<Peer<'a>, Arc<ChannelMan<'a>>, Arc<P2PGossipSync<Arc<NetworkGraph<Arc<dyn Logger>>>, Arc<dyn UtxoLookup>, Arc<dyn Logger>>>, IgnoringMessageHandler, Arc<dyn Logger>, IgnoringMessageHandler, Arc<KeyProvider>>;
187188

188189
struct MoneyLossDetector<'a> {
189190
manager: Arc<ChannelMan<'a>>,

fuzz/src/router.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use bitcoin::blockdata::script::Builder;
1111
use bitcoin::blockdata::transaction::TxOut;
1212
use bitcoin::hash_types::BlockHash;
1313

14-
use lightning::chain;
1514
use lightning::chain::transaction::OutPoint;
1615
use lightning::ln::channelmanager::{self, ChannelDetails, ChannelCounterparty};
1716
use lightning::ln::msgs;
1817
use lightning::routing::gossip::{NetworkGraph, RoutingFees};
18+
use lightning::routing::utxo::{UtxoFuture, UtxoLookup, UtxoLookupError, UtxoResult};
1919
use lightning::routing::router::{find_route, PaymentParameters, RouteHint, RouteHintHop, RouteParameters};
2020
use lightning::routing::scoring::FixedPenaltyScorer;
2121
use lightning::util::config::UserConfig;
@@ -81,17 +81,36 @@ impl InputData {
8181
}
8282
}
8383

84-
struct FuzzChainSource {
84+
struct FuzzChainSource<'a, 'b, Out: test_logger::Output> {
8585
input: Arc<InputData>,
86+
net_graph: &'a NetworkGraph<&'b test_logger::TestLogger<Out>>,
8687
}
87-
impl chain::Access for FuzzChainSource {
88-
fn get_utxo(&self, _genesis_hash: &BlockHash, _short_channel_id: u64) -> Result<TxOut, chain::AccessError> {
89-
match self.input.get_slice(2) {
90-
Some(&[0, _]) => Err(chain::AccessError::UnknownChain),
91-
Some(&[1, _]) => Err(chain::AccessError::UnknownTx),
92-
Some(&[_, x]) => Ok(TxOut { value: 0, script_pubkey: Builder::new().push_int(x as i64).into_script().to_v0_p2wsh() }),
93-
None => Err(chain::AccessError::UnknownTx),
94-
_ => unreachable!(),
88+
impl<Out: test_logger::Output> UtxoLookup for FuzzChainSource<'_, '_, Out> {
89+
fn get_utxo(&self, _genesis_hash: &BlockHash, _short_channel_id: u64) -> UtxoResult {
90+
let input_slice = self.input.get_slice(2);
91+
if input_slice.is_none() { return UtxoResult::Sync(Err(UtxoLookupError::UnknownTx)); }
92+
let input_slice = input_slice.unwrap();
93+
let txo_res = TxOut {
94+
value: if input_slice[0] % 2 == 0 { 1_000_000 } else { 1_000 },
95+
script_pubkey: Builder::new().push_int(input_slice[1] as i64).into_script().to_v0_p2wsh(),
96+
};
97+
match input_slice {
98+
&[0, _] => UtxoResult::Sync(Err(UtxoLookupError::UnknownChain)),
99+
&[1, _] => UtxoResult::Sync(Err(UtxoLookupError::UnknownTx)),
100+
&[2, _] => {
101+
let future = UtxoFuture::new();
102+
future.resolve_without_forwarding(self.net_graph, Ok(txo_res));
103+
UtxoResult::Async(future.clone())
104+
},
105+
&[3, _] => {
106+
let future = UtxoFuture::new();
107+
future.resolve_without_forwarding(self.net_graph, Err(UtxoLookupError::UnknownTx));
108+
UtxoResult::Async(future.clone())
109+
},
110+
&[4, _] => {
111+
UtxoResult::Async(UtxoFuture::new()) // the future will never resolve
112+
},
113+
&[..] => UtxoResult::Sync(Ok(txo_res)),
95114
}
96115
}
97116
}
@@ -171,6 +190,10 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
171190

172191
let our_pubkey = get_pubkey!();
173192
let net_graph = NetworkGraph::new(genesis_block(Network::Bitcoin).header.block_hash(), &logger);
193+
let chain_source = FuzzChainSource {
194+
input: Arc::clone(&input),
195+
net_graph: &net_graph,
196+
};
174197

175198
let mut node_pks = HashSet::new();
176199
let mut scid = 42;
@@ -191,13 +214,14 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
191214
let msg = decode_msg_with_len16!(msgs::UnsignedChannelAnnouncement, 32+8+33*4);
192215
node_pks.insert(get_pubkey_from_node_id!(msg.node_id_1));
193216
node_pks.insert(get_pubkey_from_node_id!(msg.node_id_2));
194-
let _ = net_graph.update_channel_from_unsigned_announcement::<&FuzzChainSource>(&msg, &None);
217+
let _ = net_graph.update_channel_from_unsigned_announcement::
218+
<&FuzzChainSource<'_, '_, Out>>(&msg, &None);
195219
},
196220
2 => {
197221
let msg = decode_msg_with_len16!(msgs::UnsignedChannelAnnouncement, 32+8+33*4);
198222
node_pks.insert(get_pubkey_from_node_id!(msg.node_id_1));
199223
node_pks.insert(get_pubkey_from_node_id!(msg.node_id_2));
200-
let _ = net_graph.update_channel_from_unsigned_announcement(&msg, &Some(&FuzzChainSource { input: Arc::clone(&input) }));
224+
let _ = net_graph.update_channel_from_unsigned_announcement(&msg, &Some(&chain_source));
201225
},
202226
3 => {
203227
let _ = net_graph.update_channel_unsigned(&decode_msg!(msgs::UnsignedChannelUpdate, 72));

0 commit comments

Comments
 (0)