Merge pull request #10 from TheBlueMatt/2021-03-enable-wallclock
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Wed, 31 Mar 2021 19:34:13 +0000 (19:34 +0000)
committerGitHub <noreply@github.com>
Wed, 31 Mar 2021 19:34:13 +0000 (19:34 +0000)
Optionally enable allow_wallclock_use

.github/workflows/build.yml
c-bindings-gen/src/types.rs
genbindings.sh
lightning-c-bindings/Cargo.toml
lightning-c-bindings/include/lightning.h
lightning-c-bindings/src/ln/channelmanager.rs

index 9511edfbc321ad99541403a8567b7b037af8639f..2db5936984a1cbf9c77170372b6be8d9ab5cdcb6 100644 (file)
@@ -25,8 +25,10 @@ jobs:
         run: cargo install --force cbindgen
       - name: Checkout Rust-Lightning git
         run: git clone https://github.com/rust-bitcoin/rust-lightning
+      - name: Rebuild bindings without std, and check the sample app builds + links
+        run: ./genbindings.sh ./rust-lightning false
       - name: Rebuild bindings, and check the sample app builds + links
-        run: ./genbindings.sh ./rust-lightning
+        run: ./genbindings.sh ./rust-lightning true
       - name: Check that the latest bindings are in git
         run: |
           git checkout lightning-c-bindings/Cargo.toml # genbindings edits this to update the path
index 0b8e10d6ee02b7330573e6034edc8e3512ed3077..10f83e5079d20051b568f2af3612eaf071f4907f 100644 (file)
@@ -82,12 +82,21 @@ pub fn export_status(attrs: &[syn::Attribute]) -> ExportStatus {
                                                        if i == "any" {
                                                                // #[cfg(any(test, feature = ""))]
                                                                if let TokenTree::Group(g) = iter.next().unwrap() {
-                                                                       if let TokenTree::Ident(i) = g.stream().into_iter().next().unwrap() {
-                                                                               if i == "test" || i == "feature" {
-                                                                                       // If its cfg(feature(...)) we assume its test-only
-                                                                                       return ExportStatus::TestOnly;
+                                                                       let mut all_test = true;
+                                                                       for token in g.stream().into_iter() {
+                                                                               if let TokenTree::Ident(i) = token {
+                                                                                       match format!("{}", i).as_str() {
+                                                                                               "test" => {},
+                                                                                               "feature" => {},
+                                                                                               _ => all_test = false,
+                                                                                       }
+                                                                               } else if let TokenTree::Literal(lit) = token {
+                                                                                       if format!("{}", lit) != "fuzztarget" {
+                                                                                               all_test = false;
+                                                                                       }
                                                                                }
                                                                        }
+                                                                       if all_test { return ExportStatus::TestOnly; }
                                                                }
                                                        } else if i == "test" || i == "feature" {
                                                                // If its cfg(feature(...)) we assume its test-only
index 0f74c4b302fe0181d95616e2b3c91b65891f3ee9..0d03950f106dcff10f9f1d8ffcb889e0dd4d07c0 100755 (executable)
@@ -3,11 +3,17 @@
 set -e
 set -x
 
-if [ ! -d "$1/lightning" ]; then
-       echo "USAGE: $0 path-to-rust-lightning"
+if [ ! -d "$1/lightning" -o "$2" != "true" -a "$2" != "false" ]; then
+       echo "USAGE: $0 path-to-rust-lightning allow-std"
+       echo "allow-std must be either 'true' or 'false' to indicate if we should be built relying on time and pthread support"
        exit 1
 fi
 
+if [ "$2" = "true" ]; then
+       FEATURES_ARGS='--features=allow_wallclock_use'
+       FEATURES='"allow_wallclock_use"'
+fi
+
 # On reasonable systems, we can use realpath here, but OSX is a diva with 20-year-old software.
 ORIG_PWD="$(pwd)"
 cd "$1/lightning"
@@ -38,16 +44,16 @@ OUT_CPP="$(pwd)/lightning-c-bindings/include/lightningpp.hpp"
 BIN="$(pwd)/c-bindings-gen/target/release/c-bindings-gen"
 
 pushd "$LIGHTNING_PATH"
-RUSTC_BOOTSTRAP=1 cargo rustc --profile=check -- -Zunstable-options --pretty=expanded |
+RUSTC_BOOTSTRAP=1 cargo rustc $FEATURES_ARGS --profile=check -- -Zunstable-options --pretty=expanded |
        RUST_BACKTRACE=1 "$BIN" "$OUT/" lightning "$OUT_TEMPL" "$OUT_F" "$OUT_CPP"
 popd
 
 HOST_PLATFORM="$(rustc --version --verbose | grep "host:")"
 if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then
        # OSX sed is for some reason not compatible with GNU sed
-       sed -i '' 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'" }|' lightning-c-bindings/Cargo.toml
+       sed -i '' 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'", features = ['"$FEATURES"'] }|' lightning-c-bindings/Cargo.toml
 else
-       sed -i 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'" }|' lightning-c-bindings/Cargo.toml
+       sed -i 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'", features = ['"$FEATURES"'] }|' lightning-c-bindings/Cargo.toml
 fi
 
 # Set path to include our rustc wrapper as well as cbindgen
index 1ba86322b06b572e1eaccad7f45464434ed55d07..e8e556b58afa352488e10954613ea721f6db8272 100644 (file)
@@ -18,7 +18,7 @@ crate-type = ["staticlib"
 bitcoin = "0.26"
 secp256k1 = { version = "0.20.1", features = ["global-context-less-secure"] }
 # Note that the following line is matched by genbindings to update the path
-lightning = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3" }
+lightning = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3", features = ["allow_wallclock_use"] }
 
 [patch.crates-io]
 # Rust-Secp256k1 PR 279. Should be dropped once merged.
index 60ba6f714d10b7c967d16a2636296bd03b75c6e3..bdeb29858d5c9e60954c4eaebab3f4e1e0909a5f 100644 (file)
@@ -11191,6 +11191,15 @@ void ChannelManager_block_connected(const struct LDKChannelManager *NONNULL_PTR
  */
 void ChannelManager_block_disconnected(const struct LDKChannelManager *NONNULL_PTR this_arg, const uint8_t (*header)[80]);
 
+/**
+ * Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
+ * indicating whether persistence is necessary. Only one listener on
+ * `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
+ * up.
+ * Note that the feature `allow_wallclock_use` must be enabled to use this function.
+ */
+MUST_USE_RES bool ChannelManager_await_persistable_update_timeout(const struct LDKChannelManager *NONNULL_PTR this_arg, uint64_t max_wait);
+
 /**
  * Blocks until ChannelManager needs to be persisted. Only one listener on
  * `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
index f28f7de77403a1f5b4f7b237b640e3decf79e6b4..89a3b249e39078d61bf7915cf5b4e7471b940d3a 100644 (file)
@@ -941,6 +941,18 @@ pub extern "C" fn ChannelManager_block_disconnected(this_arg: &ChannelManager, h
        unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap())
 }
 
+/// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
+/// indicating whether persistence is necessary. Only one listener on
+/// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
+/// up.
+/// Note that the feature `allow_wallclock_use` must be enabled to use this function.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn ChannelManager_await_persistable_update_timeout(this_arg: &ChannelManager, mut max_wait: u64) -> bool {
+       let mut ret = unsafe { &*this_arg.inner }.await_persistable_update_timeout(std::time::Duration::from_secs(max_wait));
+       ret
+}
+
 /// Blocks until ChannelManager needs to be persisted. Only one listener on
 /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
 /// up.