Skip to content

Commit 8fae0c0

Browse files
authored
Merge pull request #638 from TheBlueMatt/2020-06-c-bindings-cleanups-2
Pre-C bindings cleanups (2)
2 parents 70fca07 + 5c37023 commit 8fae0c0

17 files changed

+187
-176
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
311311
let mut posn = Vec::with_capacity(channel_txn.len());
312312
for i in 0..channel_txn.len() {
313313
txn.push(&channel_txn[i]);
314-
posn.push(i as u32 + 1);
314+
posn.push(i + 1);
315315
}
316316
$node.block_connected(&header, 1, &txn, &posn);
317317
for i in 2..100 {

fuzz/src/full_stack.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'a> MoneyLossDetector<'a> {
183183
hash_map::Entry::Vacant(e) => {
184184
e.insert(self.height);
185185
txn.push(tx);
186-
txn_idxs.push(idx as u32 + 1);
186+
txn_idxs.push(idx + 1);
187187
},
188188
_ => {},
189189
}
@@ -400,7 +400,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
400400
},
401401
4 => {
402402
let value = slice_to_be24(get_slice!(3)) as u64;
403-
let route = match get_route(&our_id, &net_graph_msg_handler, &get_pubkey!(), None, &Vec::new(), value, 42, Arc::clone(&logger)) {
403+
let route = match get_route(&our_id, &net_graph_msg_handler.network_graph.read().unwrap(), &get_pubkey!(), None, &Vec::new(), value, 42, Arc::clone(&logger)) {
404404
Ok(route) => route,
405405
Err(_) => return,
406406
};
@@ -417,7 +417,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
417417
},
418418
15 => {
419419
let value = slice_to_be24(get_slice!(3)) as u64;
420-
let mut route = match get_route(&our_id, &net_graph_msg_handler, &get_pubkey!(), None, &Vec::new(), value, 42, Arc::clone(&logger)) {
420+
let mut route = match get_route(&our_id, &net_graph_msg_handler.network_graph.read().unwrap(), &get_pubkey!(), None, &Vec::new(), value, 42, Arc::clone(&logger)) {
421421
Ok(route) => route,
422422
Err(_) => return,
423423
};

fuzz/src/router.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use bitcoin::blockdata::script::{Script, Builder};
22
use bitcoin::blockdata::block::Block;
3-
use bitcoin::blockdata::transaction::Transaction;
43
use bitcoin::hash_types::{Txid, BlockHash};
54

65
use lightning::chain::chaininterface::{ChainError,ChainWatchInterface};
@@ -76,8 +75,8 @@ impl ChainWatchInterface for DummyChainWatcher {
7675
fn install_watch_tx(&self, _txid: &Txid, _script_pub_key: &Script) { }
7776
fn install_watch_outpoint(&self, _outpoint: (Txid, u32), _out_script: &Script) { }
7877
fn watch_all_txn(&self) { }
79-
fn filter_block<'a>(&self, _block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>) {
80-
(Vec::new(), Vec::new())
78+
fn filter_block(&self, _block: &Block) -> Vec<usize> {
79+
Vec::new()
8180
}
8281
fn reentered(&self) -> usize { 0 }
8382

@@ -228,7 +227,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
228227
}
229228
&last_hops_vec[..]
230229
};
231-
let _ = get_route(&our_pubkey, &net_graph_msg_handler, &target, first_hops, last_hops, slice_to_be64(get_slice!(8)), slice_to_be32(get_slice!(4)), Arc::clone(&logger));
230+
let _ = get_route(&our_pubkey, &net_graph_msg_handler.network_graph.read().unwrap(), &target, first_hops, last_hops, slice_to_be64(get_slice!(8)), slice_to_be32(get_slice!(4)), Arc::clone(&logger));
232231
},
233232
_ => return,
234233
}

lightning/src/chain/chaininterface.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ pub trait ChainWatchInterface: Sync + Send {
5353
/// final two the output within the transaction.
5454
fn get_chain_utxo(&self, genesis_hash: BlockHash, unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError>;
5555

56-
/// Gets the list of transactions and transaction indices that the ChainWatchInterface is
56+
/// Gets the list of transaction indices within a given block that the ChainWatchInterface is
5757
/// watching for.
58-
fn filter_block<'a>(&self, block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>);
58+
fn filter_block(&self, block: &Block) -> Vec<usize>;
5959

6060
/// Returns a usize that changes when the ChainWatchInterface's watched data is modified.
6161
/// Users of `filter_block` should pre-save a copy of `reentered`'s return value and use it to
@@ -86,7 +86,7 @@ pub trait ChainListener: Sync + Send {
8686
///
8787
/// This also means those counting confirmations using block_connected callbacks should watch
8888
/// for duplicate headers and not count them towards confirmations!
89-
fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]);
89+
fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[usize]);
9090
/// Notifies a listener that a block was disconnected.
9191
/// Unlike block_connected, this *must* never be called twice for the same disconnect event.
9292
/// Height must be the one of the block which was disconnected (not new height of the best chain)
@@ -274,11 +274,15 @@ impl<'a, CL: Deref<Target = ChainListener + 'a> + 'a, C: Deref> BlockNotifier<'a
274274
///
275275
/// Handles re-scanning the block and calling block_connected again if listeners register new
276276
/// watch data during the callbacks for you (see ChainListener::block_connected for more info).
277-
pub fn block_connected<'b>(&self, block: &'b Block, height: u32) {
277+
pub fn block_connected(&self, block: &Block, height: u32) {
278278
let mut reentered = true;
279279
while reentered {
280-
let (matched, matched_index) = self.chain_monitor.filter_block(block);
281-
reentered = self.block_connected_checked(&block.header, height, matched.as_slice(), matched_index.as_slice());
280+
let matched_indexes = self.chain_monitor.filter_block(block);
281+
let mut matched_txn = Vec::new();
282+
for index in matched_indexes.iter() {
283+
matched_txn.push(&block.txdata[*index]);
284+
}
285+
reentered = self.block_connected_checked(&block.header, height, matched_txn.as_slice(), matched_indexes.as_slice());
282286
}
283287
}
284288

@@ -288,7 +292,7 @@ impl<'a, CL: Deref<Target = ChainListener + 'a> + 'a, C: Deref> BlockNotifier<'a
288292
/// Returns true if notified listeners registered additional watch data (implying that the
289293
/// block must be re-scanned and this function called again prior to further block_connected
290294
/// calls, see ChainListener::block_connected for more info).
291-
pub fn block_connected_checked(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]) -> bool {
295+
pub fn block_connected_checked(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[usize]) -> bool {
292296
let last_seen = self.chain_monitor.reentered();
293297

294298
let listeners = self.listeners.lock().unwrap();
@@ -357,19 +361,17 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil {
357361
Err(ChainError::NotSupported)
358362
}
359363

360-
fn filter_block<'a>(&self, block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>) {
361-
let mut matched = Vec::new();
364+
fn filter_block(&self, block: &Block) -> Vec<usize> {
362365
let mut matched_index = Vec::new();
363366
{
364367
let watched = self.watched.lock().unwrap();
365368
for (index, transaction) in block.txdata.iter().enumerate() {
366369
if self.does_match_tx_unguarded(transaction, &watched) {
367-
matched.push(transaction);
368-
matched_index.push(index as u32);
370+
matched_index.push(index);
369371
}
370372
}
371373
}
372-
(matched, matched_index)
374+
matched_index
373375
}
374376

375377
fn reentered(&self) -> usize {

lightning/src/chain/keysinterface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ impl Readable for SpendableOutputDescriptor {
196196
// ChannelMonitors instead of expecting to clone the one out of the Channel into the monitors.
197197
pub trait ChannelKeys : Send+Clone {
198198
/// Gets the commitment seed
199-
fn commitment_seed<'a>(&'a self) -> &'a [u8; 32];
199+
fn commitment_seed(&self) -> &[u8; 32];
200200
/// Gets the local channel public keys and basepoints
201-
fn pubkeys<'a>(&'a self) -> &'a ChannelPublicKeys;
201+
fn pubkeys(&self) -> &ChannelPublicKeys;
202202
/// Gets arbitrary identifiers describing the set of keys which are provided back to you in
203203
/// some SpendableOutputDescriptor types. These should be sufficient to identify this
204204
/// ChannelKeys object uniquely and lookup or re-derive its keys.
@@ -405,7 +405,7 @@ impl InMemoryChannelKeys {
405405

406406
impl ChannelKeys for InMemoryChannelKeys {
407407
fn commitment_seed(&self) -> &[u8; 32] { &self.commitment_seed }
408-
fn pubkeys<'a>(&'a self) -> &'a ChannelPublicKeys { &self.local_channel_pubkeys }
408+
fn pubkeys(&self) -> &ChannelPublicKeys { &self.local_channel_pubkeys }
409409
fn key_derivation_params(&self) -> (u64, u64) { self.key_derivation_params }
410410

411411
fn sign_remote_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, feerate_per_kw: u32, commitment_tx: &Transaction, keys: &TxCreationKeys, htlcs: &[&HTLCOutputInCommitment], to_self_delay: u16, secp_ctx: &Secp256k1<T>) -> Result<(Signature, Vec<Signature>), ()> {

0 commit comments

Comments
 (0)