Skip to content

Commit 192d177

Browse files
authored
Merge f1b4534 into b5d88a5
2 parents b5d88a5 + f1b4534 commit 192d177

File tree

25 files changed

+1739
-1108
lines changed

25 files changed

+1739
-1108
lines changed

background-processor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl BackgroundProcessor {
6666
let handle = thread::spawn(move || -> Result<(), std::io::Error> {
6767
let mut current_time = Instant::now();
6868
loop {
69-
let updates_available = manager.wait_timeout(Duration::from_millis(100));
69+
let updates_available = manager.await_persistable_update_timeout(Duration::from_millis(100));
7070
if updates_available {
7171
persist_manager(&*manager)?;
7272
}

c-bindings-gen/src/main.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ fn writeln_opaque<W: std::io::Write>(w: &mut W, ident: &syn::Ident, struct_name:
536536
writeln!(w, "\t/// the Rust equivalent takes an Option, it may be set to null to indicate None.").unwrap();
537537
writeln!(w, "\tpub inner: *mut native{},\n\tpub is_owned: bool,\n}}\n", ident).unwrap();
538538
writeln!(w, "impl Drop for {} {{\n\tfn drop(&mut self) {{", struct_name).unwrap();
539-
writeln!(w, "\t\tif self.is_owned && !self.inner.is_null() {{").unwrap();
539+
writeln!(w, "\t\tif self.is_owned && !<*mut native{}>::is_null(self.inner) {{", ident).unwrap();
540540
writeln!(w, "\t\t\tlet _ = unsafe {{ Box::from_raw(self.inner) }};\n\t\t}}\n\t}}\n}}").unwrap();
541541
writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", struct_name, struct_name).unwrap();
542542
writeln!(w, "#[allow(unused)]").unwrap();
@@ -808,10 +808,10 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
808808
}
809809
}
810810
) );
811-
write!(w, "\t}}\n}}\nuse {}::{} as {}TraitImport;\n", types.orig_crate, full_trait_path, trait_obj.ident).unwrap();
811+
writeln!(w, "\t}}\n}}\n").unwrap();
812812

813813
macro_rules! impl_meth {
814-
($m: expr, $trait: expr, $indent: expr) => {
814+
($m: expr, $trait_path: expr, $trait: expr, $indent: expr) => {
815815
let trait_method = $trait.items.iter().filter_map(|item| {
816816
if let syn::TraitItem::Method(t_m) = item { Some(t_m) } else { None }
817817
}).find(|trait_meth| trait_meth.sig.ident == $m.sig.ident).unwrap();
@@ -842,9 +842,9 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
842842
t_gen_args += "_"
843843
}
844844
if takes_self {
845-
write!(w, "<native{} as {}TraitImport<{}>>::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, $trait.ident, t_gen_args, $m.sig.ident, ident).unwrap();
845+
write!(w, "<native{} as {}::{}<{}>>::{}(unsafe {{ &mut *(this_arg as *mut native{}) }}, ", ident, types.orig_crate, $trait_path, t_gen_args, $m.sig.ident, ident).unwrap();
846846
} else {
847-
write!(w, "<native{} as {}TraitImport<{}>>::{}(", ident, $trait.ident, t_gen_args, $m.sig.ident).unwrap();
847+
write!(w, "<native{} as {}::{}<{}>>::{}(", ident, types.orig_crate, $trait_path, t_gen_args, $m.sig.ident).unwrap();
848848
}
849849

850850
let mut real_type = "".to_string();
@@ -881,20 +881,19 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
881881
for item in i.items.iter() {
882882
match item {
883883
syn::ImplItem::Method(m) => {
884-
impl_meth!(m, trait_obj, "");
884+
impl_meth!(m, full_trait_path, trait_obj, "");
885885
},
886886
syn::ImplItem::Type(_) => {},
887887
_ => unimplemented!(),
888888
}
889889
}
890890
walk_supertraits!(trait_obj, Some(&types), (
891-
(s, t) => {
891+
(s, _) => {
892892
if let Some(supertrait_obj) = types.crate_types.traits.get(s).cloned() {
893-
writeln!(w, "use {}::{} as native{}Trait;", types.orig_crate, s, t).unwrap();
894893
for item in supertrait_obj.items.iter() {
895894
match item {
896895
syn::TraitItem::Method(m) => {
897-
impl_meth!(m, supertrait_obj, "\t");
896+
impl_meth!(m, s, supertrait_obj, "\t");
898897
},
899898
_ => {},
900899
}
@@ -914,7 +913,7 @@ fn writeln_impl<W: std::io::Write>(w: &mut W, i: &syn::ItemImpl, types: &mut Typ
914913
writeln!(w, "impl Clone for {} {{", ident).unwrap();
915914
writeln!(w, "\tfn clone(&self) -> Self {{").unwrap();
916915
writeln!(w, "\t\tSelf {{").unwrap();
917-
writeln!(w, "\t\t\tinner: if self.inner.is_null() {{ std::ptr::null_mut() }} else {{").unwrap();
916+
writeln!(w, "\t\t\tinner: if <*mut native{}>::is_null(self.inner) {{ std::ptr::null_mut() }} else {{", ident).unwrap();
918917
writeln!(w, "\t\t\t\tBox::into_raw(Box::new(unsafe {{ &*self.inner }}.clone())) }},").unwrap();
919918
writeln!(w, "\t\t\tis_owned: true,").unwrap();
920919
writeln!(w, "\t\t}}\n\t}}\n}}").unwrap();

c-bindings-gen/src/types.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
842842
"bitcoin::blockdata::transaction::Transaction" => Some("crate::c_types::Transaction::from_vec(local_"),
843843
"bitcoin::blockdata::transaction::OutPoint" => Some("crate::c_types::bitcoin_to_C_outpoint("),
844844
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some("crate::c_types::TxOut::from_rust("),
845+
"bitcoin::network::constants::Network" => Some("crate::bitcoin::network::Network::from_bitcoin("),
845846
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some("&local_"),
846847
"bitcoin::blockdata::block::Block" if is_ref => Some("crate::c_types::u8slice::from_slice(&local_"),
847848

@@ -899,6 +900,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
899900
"bitcoin::blockdata::transaction::Transaction" => Some(")"),
900901
"bitcoin::blockdata::transaction::OutPoint" => Some(")"),
901902
"bitcoin::blockdata::transaction::TxOut" if !is_ref => Some(")"),
903+
"bitcoin::network::constants::Network" => Some(")"),
902904
"bitcoin::blockdata::block::BlockHeader" if is_ref => Some(""),
903905
"bitcoin::blockdata::block::Block" if is_ref => Some(")"),
904906

@@ -1944,11 +1946,7 @@ impl<'a, 'c: 'a> TypeResolver<'a, 'c> {
19441946
if !self.write_c_path_intern(w, &$p_arg.path, generics, true, true, true) { return false; }
19451947
}
19461948
} else {
1947-
if $p_arg.path.segments.len() == 1 {
1948-
write!(w, "{}", $p_arg.path.segments.iter().next().unwrap().ident).unwrap();
1949-
} else {
1950-
return false;
1951-
}
1949+
write!(w, "{}", $p_arg.path.segments.last().unwrap().ident).unwrap();
19521950
}
19531951
} else if self.is_known_container(&subtype, is_ref) || self.is_transparent_container(&subtype, is_ref) {
19541952
if !self.write_c_mangled_container_path_intern(w, Self::path_to_generic_args(&$p_arg.path), generics,

genbindings.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,16 @@ else
179179
echo "WARNING: Can't use address sanitizer on non-Linux, non-OSX non-x86 platforms"
180180
fi
181181

182-
cargo rustc -v --target=wasm32-wasi -- -C embed-bitcode=yes || echo "WARNING: Failed to generate WASM LLVM-bitcode-embedded library"
183-
CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release --target=wasm32-wasi -- -C opt-level=s -C linker-plugin-lto -C lto || echo "WARNING: Failed to generate WASM LLVM-bitcode-embedded optimized library"
182+
if [ "$(rustc --print target-list | grep wasm32-wasi)" != "" ]; then
183+
# Test to see if clang supports wasm32 as a target (which is needed to build rust-secp256k1)
184+
echo "int main() {}" > genbindings_wasm_test_file.c
185+
clang -nostdlib -o /dev/null --target=wasm32-wasi -Wl,--no-entry genbindings_wasm_test_file.c > /dev/null 2>&1 &&
186+
# And if it does, build a WASM binary without capturing errors
187+
cargo rustc -v --target=wasm32-wasi -- -C embed-bitcode=yes &&
188+
CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release --target=wasm32-wasi -- -C opt-level=s -C linker-plugin-lto -C lto ||
189+
echo "Cannot build WASM lib as clang does not seem to support the wasm32-wasi target"
190+
rm genbindings_wasm_test_file.c
191+
fi
184192

185193
# Now build with LTO on on both C++ and rust, but without cross-language LTO:
186194
CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C lto

lightning-c-bindings/demo.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,10 @@ int main() {
7272
LDKKeysInterface keys_source = KeysManager_as_KeysInterface(&keys);
7373

7474
LDKUserConfig config = UserConfig_default();
75-
76-
LDKChannelManager cm = ChannelManager_new(net, fee_est, mon, broadcast, logger, keys_source, config, 0);
75+
LDKThirtyTwoBytes chain_tip;
76+
memset(&chain_tip, 0, 32);
77+
LDKChainParameters chain = ChainParameters_new(net, chain_tip, 0);
78+
LDKChannelManager cm = ChannelManager_new(fee_est, mon, broadcast, logger, keys_source, config, chain);
7779

7880
LDKCVec_ChannelDetailsZ channels = ChannelManager_list_channels(&cm);
7981
assert((unsigned long)channels.data < 4096); // There's an offset, but it should still be an offset against null in the 0 page

lightning-c-bindings/demo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ int main() {
292292
memset(&null_pk, 0, sizeof(null_pk));
293293

294294
LDKThirtyTwoBytes random_bytes;
295+
LDKThirtyTwoBytes chain_tip;
296+
memset(&chain_tip, 0, sizeof(chain_tip)); // channel_open_header's prev_blockhash is all-0s
295297

296298
LDKNetwork network = LDKNetwork_Testnet;
297299

@@ -352,7 +354,7 @@ int main() {
352354
LDK::KeysInterface keys_source1 = KeysManager_as_KeysInterface(&keys1);
353355
node_secret1 = keys_source1->get_node_secret(keys_source1->this_arg);
354356

355-
LDK::ChannelManager cm1 = ChannelManager_new(network, fee_est, mon1, broadcast, logger1, KeysManager_as_KeysInterface(&keys1), UserConfig_default(), 0);
357+
LDK::ChannelManager cm1 = ChannelManager_new(fee_est, mon1, broadcast, logger1, KeysManager_as_KeysInterface(&keys1), UserConfig_default(), ChainParameters_new(network, chain_tip, 0));
356358

357359
LDK::CVec_ChannelDetailsZ channels = ChannelManager_list_channels(&cm1);
358360
assert(channels->datalen == 0);
@@ -379,7 +381,7 @@ int main() {
379381
LDK::UserConfig config2 = UserConfig_default();
380382
UserConfig_set_own_channel_config(&config2, std::move(handshake_config2));
381383

382-
LDK::ChannelManager cm2 = ChannelManager_new(network, fee_est, mon2, broadcast, logger2, KeysManager_as_KeysInterface(&keys2), std::move(config2), 0);
384+
LDK::ChannelManager cm2 = ChannelManager_new(fee_est, mon2, broadcast, logger2, KeysManager_as_KeysInterface(&keys2), std::move(config2), ChainParameters_new(network, chain_tip, 0));
383385

384386
LDK::CVec_ChannelDetailsZ channels2 = ChannelManager_list_channels(&cm2);
385387
assert(channels2->datalen == 0);

0 commit comments

Comments
 (0)