Skip to content

Pre-C bindings cleanups (2) #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 changes: 1 addition & 1 deletion fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
let mut posn = Vec::with_capacity(channel_txn.len());
for i in 0..channel_txn.len() {
txn.push(&channel_txn[i]);
posn.push(i as u32 + 1);
posn.push(i + 1);
}
$node.block_connected(&header, 1, &txn, &posn);
for i in 2..100 {
Expand Down
6 changes: 3 additions & 3 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl<'a> MoneyLossDetector<'a> {
hash_map::Entry::Vacant(e) => {
e.insert(self.height);
txn.push(tx);
txn_idxs.push(idx as u32 + 1);
txn_idxs.push(idx + 1);
},
_ => {},
}
Expand Down Expand Up @@ -400,7 +400,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
},
4 => {
let value = slice_to_be24(get_slice!(3)) as u64;
let route = match get_route(&our_id, &net_graph_msg_handler, &get_pubkey!(), None, &Vec::new(), value, 42, Arc::clone(&logger)) {
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)) {
Ok(route) => route,
Err(_) => return,
};
Expand All @@ -417,7 +417,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
},
15 => {
let value = slice_to_be24(get_slice!(3)) as u64;
let mut route = match get_route(&our_id, &net_graph_msg_handler, &get_pubkey!(), None, &Vec::new(), value, 42, Arc::clone(&logger)) {
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)) {
Ok(route) => route,
Err(_) => return,
};
Expand Down
7 changes: 3 additions & 4 deletions fuzz/src/router.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use bitcoin::blockdata::script::{Script, Builder};
use bitcoin::blockdata::block::Block;
use bitcoin::blockdata::transaction::Transaction;
use bitcoin::hash_types::{Txid, BlockHash};

use lightning::chain::chaininterface::{ChainError,ChainWatchInterface};
Expand Down Expand Up @@ -76,8 +75,8 @@ impl ChainWatchInterface for DummyChainWatcher {
fn install_watch_tx(&self, _txid: &Txid, _script_pub_key: &Script) { }
fn install_watch_outpoint(&self, _outpoint: (Txid, u32), _out_script: &Script) { }
fn watch_all_txn(&self) { }
fn filter_block<'a>(&self, _block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>) {
(Vec::new(), Vec::new())
fn filter_block(&self, _block: &Block) -> Vec<usize> {
Vec::new()
}
fn reentered(&self) -> usize { 0 }

Expand Down Expand Up @@ -228,7 +227,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
}
&last_hops_vec[..]
};
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));
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));
},
_ => return,
}
Expand Down
26 changes: 14 additions & 12 deletions lightning/src/chain/chaininterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pub trait ChainWatchInterface: Sync + Send {
/// final two the output within the transaction.
fn get_chain_utxo(&self, genesis_hash: BlockHash, unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError>;

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

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

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

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

fn filter_block<'a>(&self, block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>) {
let mut matched = Vec::new();
fn filter_block(&self, block: &Block) -> Vec<usize> {
let mut matched_index = Vec::new();
{
let watched = self.watched.lock().unwrap();
for (index, transaction) in block.txdata.iter().enumerate() {
if self.does_match_tx_unguarded(transaction, &watched) {
matched.push(transaction);
matched_index.push(index as u32);
matched_index.push(index);
}
}
}
(matched, matched_index)
matched_index
}

fn reentered(&self) -> usize {
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/chain/keysinterface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ impl Readable for SpendableOutputDescriptor {
// ChannelMonitors instead of expecting to clone the one out of the Channel into the monitors.
pub trait ChannelKeys : Send+Clone {
/// Gets the commitment seed
fn commitment_seed<'a>(&'a self) -> &'a [u8; 32];
fn commitment_seed(&self) -> &[u8; 32];
/// Gets the local channel public keys and basepoints
fn pubkeys<'a>(&'a self) -> &'a ChannelPublicKeys;
fn pubkeys(&self) -> &ChannelPublicKeys;
/// Gets arbitrary identifiers describing the set of keys which are provided back to you in
/// some SpendableOutputDescriptor types. These should be sufficient to identify this
/// ChannelKeys object uniquely and lookup or re-derive its keys.
Expand Down Expand Up @@ -405,7 +405,7 @@ impl InMemoryChannelKeys {

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

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>), ()> {
Expand Down
Loading