Skip to content

Commit bc5867c

Browse files
committed
Incorporate upstream changes
* change fn signature of `filter_block` * Use u32 instead of u64 for fee_est. * Change fields in `DynamicOutputP2WSH`
1 parent edfc12a commit bc5867c

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

bindings/src/adaptors/mod.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl From<ConfirmationTarget> for FFIConfirmationTarget {
8484

8585
pub mod fee_estimator_fn {
8686
use super::{FFIConfirmationTarget};
87-
pub type GetEstSatPer1000WeightPtr = extern "cdecl" fn (FFIConfirmationTarget) -> u64;
87+
pub type GetEstSatPer1000WeightPtr = extern "cdecl" fn (FFIConfirmationTarget) -> u32;
8888
}
8989

9090
#[repr(C)]
@@ -94,7 +94,7 @@ pub struct FFIFeeEstimator {
9494
}
9595

9696
impl FeeEstimator for FFIFeeEstimator {
97-
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u64 {
97+
fn get_est_sat_per_1000_weight(&self, confirmation_target: ConfirmationTarget) -> u32 {
9898
(self.get_est_sat_per_1000_weight_ptr)(confirmation_target.into())
9999
}
100100
}
@@ -197,7 +197,7 @@ pub mod chain_watch_interface_fn {
197197
pub type InstallWatchOutpointPtr = extern "cdecl" fn(outpoint: *const FFIOutPoint, out_script: *const FFIScript);
198198
pub type WatchAllTxnPtr = extern "cdecl" fn();
199199
pub type GetChainUtxoPtr = extern "cdecl" fn(genesis_hash: *const Bytes32, unspent_tx_output_identifier: u64, err: *mut FFIChainError, script_ptr: *mut u8, script_len: *mut usize, amount_satoshis: *mut u64);
200-
pub type FilterBlock = extern "cdecl" fn(block_ptr: *const u8, block_len: usize, matched_index_ptr: *mut u8, matched_inedx_len: *mut usize);
200+
pub type FilterBlock = extern "cdecl" fn(block_ptr: *const u8, block_len: usize, matched_index_ptr: *mut usize, matched_inedx_len: *mut usize);
201201
pub type ReEntered = extern "cdecl" fn() -> usize;
202202
}
203203

@@ -268,25 +268,18 @@ impl ChainWatchInterface for FFIChainWatchInterface {
268268
}
269269
}
270270

271-
fn filter_block<'a>(&self, block: &'a Block) -> (Vec<&'a Transaction>, Vec<u32>) {
271+
fn filter_block<'a>(&self, block: &'a Block) -> Vec<usize> {
272272
let block_bytes = bitcoin_serialize(block);
273273
// the minimum weight for one tx is 440. So the max number of tx in one block is 9090.
274-
// so the max size of the buffer we have to prepare is.
275-
// `2 + (9090 * 4) = 36362`.
276-
let mut matched_tx_index = [0u8; 36864];
277-
let mut matched_tx_index_len_ptr: &mut usize = todo!();
274+
let mut matched_tx_index = [0; 9091];
275+
let mut matched_tx_index_len_ptr: &mut usize = &mut usize::MAX;
278276
println!("coinbase tx in rl {:?}", block.txdata[0]);
279277
(self.filter_block_ptr)(block_bytes.as_ptr(), block_bytes.len(), matched_tx_index.as_mut_ptr(), matched_tx_index_len_ptr as *mut _);
280278
if (matched_tx_index_len_ptr.clone() == usize::MAX) {
281279
panic!("FFI failure. the caller must set the actual serialized length of the tx-indexes in filter_block");
282280
}
283-
let mut matched_tx_index: &[u8] = unsafe_block!("We know the caller has set the value for serialized tx index" => &matched_tx_index[..(*matched_tx_index_len_ptr)]);
284-
let matched_tx_indexes: Vec<u32> = lightning::util::ser::Readable::read(&mut std::io::Cursor::new(matched_tx_index)).unwrap();
285-
let mut matched_txs = Vec::with_capacity(matched_tx_indexes.len());
286-
for i in matched_tx_indexes.iter() {
287-
matched_txs.push(&block.txdata[i.clone() as usize]);
288-
}
289-
(matched_txs, matched_tx_indexes)
281+
let mut matched_tx_indexes: &[usize] = unsafe_block!("We know the caller has set the value for serialized tx index" => &matched_tx_index[..(*matched_tx_index_len_ptr)]);
282+
matched_tx_indexes.to_vec()
290283
}
291284

292285
fn reentered(&self) -> usize {
@@ -410,6 +403,8 @@ impl From<FFILightningError> for LightningError {
410403
}
411404
}
412405

406+
// --- routing stuff ---
407+
/// TODO: enable to pass routing handler from outside.
413408
pub mod routing_msg_descriptor_fn {
414409
use super::*;
415410
use crate::adaptors::primitives::Bytes33;

bindings/src/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ ffi! {
273273
FFIResult::ok()
274274
}
275275

276-
fn update_fee(channel_id: Ref<[u8; 32]>, feerate_per_kw: u64, handle: FFIArcChannelManagerHandle) -> FFIResult {
276+
fn update_fee(channel_id: Ref<[u8; 32]>, feerate_per_kw: u32, handle: FFIArcChannelManagerHandle) -> FFIResult {
277277
let chan_man: &FFIArcChannelManager = unsafe_block!("We know handle points to valid channel_manager" => handle.as_ref());
278278
let channel_id: &[u8;32] = unsafe_block!("" => channel_id.as_ref());
279279
chan_man.update_fee(channel_id.clone(), feerate_per_kw)?;

bindings/src/ffi_test_utils.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ffi! {
2828
let mut events = Vec::with_capacity(5);
2929

3030
let txid = bitcoin::consensus::deserialize(&hex::decode("4141414141414141414141414141414141414141414141414141414141414142").unwrap()).unwrap();
31-
let funding_txo= OutPoint::new(txid, 1);
31+
let funding_txo = OutPoint{ txid, index: 1};
3232
let user_channel_id = 1111;
3333
events.push(Event::FundingBroadcastSafe {funding_txo, user_channel_id} );
3434

@@ -54,13 +54,15 @@ ffi! {
5454
let output = TxOut {value: 255, script_pubkey: bitcoin::blockdata::script::Script::new() };
5555
let static_output = SpendableOutputDescriptor::StaticOutput {outpoint, output: output.clone()};
5656

57-
let key = bitcoin::secp256k1::key::SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()).unwrap();
57+
let per_commitment_point = bitcoin::secp256k1::key::PublicKey::from_slice(&hex::decode("02aca35d6de21baefaf65db590611fabd42ed4d52683c36caff58761d309314f65").unwrap()).unwrap();
58+
let remote_revocation_pubkey = bitcoin::secp256k1::key::PublicKey::from_slice(&hex::decode("02812cb18bf5c19374b34419095a09aa0b0d5559a24ce0ef558845230b0a096161").unwrap()).unwrap();
5859
let dynamic_output_p2wsh = SpendableOutputDescriptor::DynamicOutputP2WSH {
5960
outpoint,
60-
key,
61-
witness_script: bitcoin::blockdata::script::Script::new(),
61+
per_commitment_point,
6262
to_self_delay: 144,
63-
output
63+
key_derivation_params: (3, 4),
64+
output,
65+
remote_revocation_pubkey
6466
};
6567
let outputs = vec![static_output, dynamic_output_p2wsh];
6668
events.push(Event::SpendableOutputs {outputs});

bindings/src/peermanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
};
2323
use crate::channelmanager::FFIArcChannelManagerHandle;
2424

25-
type FFISimpleArcPeerManager = PeerManager<FFISocketDescriptor, Arc<FFIArcChannelManager>, Arc<FFILogger>>;
25+
type FFISimpleArcPeerManager = PeerManager<FFISocketDescriptor, Arc<FFIArcChannelManager>, Arc<NetGraphMsgHandler<Arc<FFIChainWatchInterface>, Arc<FFILogger>>>, Arc<FFILogger>>;
2626
type FFIArcPeerManagerHandle<'a> = HandleShared<'a, FFISimpleArcPeerManager>;
2727

2828
lazy_static! {

lightning/src/ln/peer_handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ pub struct PeerManager<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: De
196196
CM::Target: ChannelMessageHandler,
197197
RM::Target: RoutingMessageHandler,
198198
L::Target: Logger {
199-
message_handler: MessageHandler<CM, RM>,
199+
/// MessageHandler for this PeerManager
200+
pub message_handler: MessageHandler<CM, RM>,
200201
peers: Mutex<PeerHolder<Descriptor>>,
201202
our_node_secret: SecretKey,
202203
ephemeral_key_midstate: Sha256Engine,

0 commit comments

Comments
 (0)