Skip to content

Commit 8879be7

Browse files
authored
Add support for async testing and bitcoin tx and block serialization (#26)
* add bitcoin block and transaction serialization helpers * replicate EXC_BAD_ACCESS that occurs with invoice payer * start anchoring objects in constructor calls * test channel balance updates with regular and zero amount invoice payment * make CI tests async * use swift 5.6 for async support * update expected shasum value * use Swift Crypto for bitcoin hash testing instead of CryptoKit * improve Record formatting in test logger * add support for post-init anchor generation * automatically add anchors for constructors that take struct objects as arguments * add multiple test runs, one with and one without the address sanitizer * experiment with workflow dependencies * iterate on workflow syntax * iterate on workflow syntax * iterate on workflow syntax * iterate on workflow syntax * iterate on workflow syntax * iterate on workflow syntax * iterate on workflow syntax * iterate on workflow syntax * iterate on workflow syntax * iterate on workflow syntax * iterate on workflow syntax * iterate on workflow syntax * reduce output amount of test suite with address sanitation
1 parent d946dd0 commit 8879be7

File tree

124 files changed

+4390
-2123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+4390
-2123
lines changed

.github/workflows/swift.yml

Lines changed: 85 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jobs:
1212
uses: actions/checkout@v2
1313
- name: Checkout Rust-Lightning and LDK-C-Bindings git
1414
run: |
15+
cd bindings/LDK
16+
ls -ll
17+
cd ../../ci
1518
git config --global user.email "[email protected]"
1619
git config --global user.name "LDK CI"
1720
# Note this is a different endpoint, as we need one non-upstream commit!
@@ -31,20 +34,7 @@ jobs:
3134
# git checkout 1bb5ae1b34aeb74009b7b4b5ebefc957cddc30a6
3235
echo "ldk-c-bindings commit hash:"
3336
git rev-parse HEAD
34-
cd ..
35-
- name: Install Swift Toolchain
36-
run: |
37-
curl --verbose -L -o swift-5.4.2-RELEASE-ubuntu20.04.tar.gz https://swift.org/builds/swift-5.4.2-release/ubuntu2004/swift-5.4.2-RELEASE/swift-5.4.2-RELEASE-ubuntu20.04.tar.gz
38-
echo "Sha sum: $(sha256sum swift-5.4.2-RELEASE-ubuntu20.04.tar.gz | awk '{ print $1 }')"
39-
if [ "$(sha256sum swift-5.4.2-RELEASE-ubuntu20.04.tar.gz | awk '{ print $1 }')" != "${EXPECTED_SWIFT_SHASUM}" ]; then
40-
echo "Bad hash"
41-
echo "Contents: \n$(cat swift-5.4.2-RELEASE-ubuntu20.04.tar.gz)"
42-
exit 1
43-
fi
44-
tar xvvf swift-5.4.2-RELEASE-ubuntu20.04.tar.gz
45-
env:
46-
EXPECTED_SWIFT_SHASUM: 86b849d9f6ba2eda4e12ea5eafaa0748bffcd6272466b514c2b0fd4a829c63a4
47-
- name: Install native Rust toolchain, Valgrind, and build utilitis
37+
- name: Install native Rust toolchain, Valgrind, and build utilities
4838
run: |
4939
sudo apt-get update
5040
sudo apt-get -y dist-upgrade
@@ -53,58 +43,118 @@ jobs:
5343
run: cargo install --force cbindgen
5444
- name: Regenerate C bindings
5545
run: |
56-
cd ldk-c-bindings
46+
pwd
47+
cd ci/ldk-c-bindings
48+
pwd
5749
./genbindings.sh ../rust-lightning true
5850
cd ..
59-
- name: Debug bindings target directory structure
60-
run: |
61-
python ci/walker.py ldk-c-bindings/lightning-c-bindings/target
6251
- name: Copy new headers into bindings
6352
run: |
64-
mkdir -p ci/LDKSwift/Sources/LDKHeaders/include
65-
cp ldk-c-bindings/lightning-c-bindings/include/*.h ci/LDKSwift/Sources/LDKHeaders/include/
66-
cp ldk-c-bindings/ldk-net/ldk_net.h ci/LDKSwift/Sources/LDKHeaders/include/
67-
cp ldk-c-bindings/ldk-net/ldk_net.c ci/LDKSwift/Sources/LDKHeaders/
53+
cd ci
54+
mkdir -p ./LDKSwift/Sources/LDKHeaders/include
55+
cp ldk-c-bindings/lightning-c-bindings/include/*.h ./LDKSwift/Sources/LDKHeaders/include/
56+
cp ldk-c-bindings/ldk-net/ldk_net.h ./LDKSwift/Sources/LDKHeaders/include/
57+
cp ldk-c-bindings/ldk-net/ldk_net.c ./LDKSwift/Sources/LDKHeaders/
6858
- name: Set up Python
6959
uses: actions/setup-python@v2
7060
- name: Fix header files
7161
run: |
72-
python ci/fix_header_includes.py
62+
cd ci
63+
python ./fix_header_includes.py
7364
- name: Generate (copy for debugging) Swift bindings and copy batteries
7465
run: |
75-
python ./ # Generate bindings
66+
pwd
67+
python ./ # Generate bindings into ci subdirectory
7668
7769
# TODO: switch back to generation method after debugging
7870
# mkdir -p ci/LDKSwift/Sources/LDKSwift
7971
# cp -a bindings/LDK/. ci/LDKSwift/Sources/LDKSwift
8072
8173
cp -R bindings/batteries ci/LDKSwift/Sources/LDKSwift
8274
env:
83-
LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH: ldk-c-bindings/lightning-c-bindings/include/lightning.h
75+
LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH: ci/ldk-c-bindings/lightning-c-bindings/include/lightning.h
8476
LDK_SWIFT_GENERATOR_OUTPUT_DIRECTORY_PATH: ci/LDKSwift/Sources/LDKSwift
77+
- name: Check that the latest auto-generated Swift files are in the repo
78+
run: |
79+
python ./ # Generate bindings into local directory
80+
python ci/walker.py bindings/LDK
81+
git diff --exit-code bindings/LDK ':(exclude)bindings/LDK/Bindings.swift'
82+
env:
83+
LDK_SWIFT_GENERATOR_INPUT_HEADER_PATH: ci/ldk-c-bindings/lightning-c-bindings/include/lightning.h
8584
- name: Fix Swift files
8685
run: |
87-
python ci/fix_swift_imports.py
88-
- name: Debug CI directory structure
86+
cd ci
87+
python ./fix_swift_imports.py
88+
- name: Install Swift Toolchain
8989
run: |
90-
python ci/walker.py ci/
90+
curl --verbose -L -o swift-5.6-RELEASE-ubuntu20.04.tar.gz https://download.swift.org/swift-5.6-release/ubuntu2004/swift-5.6-RELEASE/swift-5.6-RELEASE-ubuntu20.04.tar.gz
91+
echo "Sha sum: $(sha256sum swift-5.6-RELEASE-ubuntu20.04.tar.gz | awk '{ print $1 }')"
92+
if [ "$(sha256sum swift-5.6-RELEASE-ubuntu20.04.tar.gz | awk '{ print $1 }')" != "${EXPECTED_SWIFT_SHASUM}" ]; then
93+
echo "Bad hash"
94+
echo "Contents: \n$(cat swift-5.6-RELEASE-ubuntu20.04.tar.gz)"
95+
exit 1
96+
fi
97+
tar xvvf swift-5.6-RELEASE-ubuntu20.04.tar.gz
98+
env:
99+
EXPECTED_SWIFT_SHASUM: 3f0d926bfc08eea00a69b1d992f2ab5e08155d97476096a3ef959fe7c4cbd58b
91100
- name: Build Swift bindings package
92101
run: |
93102
cd ci/LDKSwift
94-
../../swift-5.4.2-RELEASE-ubuntu20.04/usr/bin/swift build
95-
cd ../../
103+
../../swift-5.6-RELEASE-ubuntu20.04/usr/bin/swift build
96104
env:
97105
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ldk-c-bindings
98106
LLVM_CLANG_ASAN_PATH: /usr/lib/llvm-11/lib/clang/11.0.0/lib/linux/libclang_rt.asan-x86_64.a
99107
RUST_BACKTRACE: 1
100-
- name: Test Swift bindings package
108+
- name: Test Swift bindings package without address sanitizer
101109
run: |
110+
python ci/toggle_address_sanitation_library.py off
102111
cd ci/LDKSwift
103-
../../swift-5.4.2-RELEASE-ubuntu20.04/usr/bin/swift test -v
112+
../../swift-5.6-RELEASE-ubuntu20.04/usr/bin/swift test -v
104113
env:
105-
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ldk-c-bindings
114+
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ci/ldk-c-bindings
106115
LLVM_CLANG_ASAN_PATH: /usr/lib/llvm-11/lib/clang/11.0.0/lib/linux/libclang_rt.asan-x86_64.a
107116
RUST_BACKTRACE: 1
108-
- name: Check that the latest headers are in the swift repo
117+
- name: Archive code coverage results
118+
uses: actions/upload-artifact@v3
119+
with:
120+
name: ci_archive
121+
path: ci
122+
123+
test_bindings_with_sanitizer:
124+
runs-on: ubuntu-20.04
125+
needs: check_bindings
126+
steps:
127+
- name: Download code coverage results archive
128+
uses: actions/download-artifact@v3
129+
with:
130+
name: ci_archive
131+
path: ci
132+
- name: Set up Python
133+
uses: actions/setup-python@v2
134+
- name: Install Swift Toolchain
135+
run: |
136+
curl --verbose -L -o swift-5.6-RELEASE-ubuntu20.04.tar.gz https://download.swift.org/swift-5.6-release/ubuntu2004/swift-5.6-RELEASE/swift-5.6-RELEASE-ubuntu20.04.tar.gz
137+
echo "Sha sum: $(sha256sum swift-5.6-RELEASE-ubuntu20.04.tar.gz | awk '{ print $1 }')"
138+
if [ "$(sha256sum swift-5.6-RELEASE-ubuntu20.04.tar.gz | awk '{ print $1 }')" != "${EXPECTED_SWIFT_SHASUM}" ]; then
139+
echo "Bad hash"
140+
echo "Contents: \n$(cat swift-5.6-RELEASE-ubuntu20.04.tar.gz)"
141+
exit 1
142+
fi
143+
tar xvvf swift-5.6-RELEASE-ubuntu20.04.tar.gz
144+
env:
145+
EXPECTED_SWIFT_SHASUM: 3f0d926bfc08eea00a69b1d992f2ab5e08155d97476096a3ef959fe7c4cbd58b
146+
- name: Install Valgrind and build utilities
109147
run: |
110-
git diff --exit-code
148+
sudo apt-get update
149+
sudo apt-get -y dist-upgrade
150+
sudo apt-get -y install valgrind lld g++ clang
151+
- name: Test Swift bindings package with address sanitizer
152+
run: |
153+
python ci/toggle_address_sanitation_library.py on
154+
cd ci/LDKSwift
155+
../../swift-5.6-RELEASE-ubuntu20.04/usr/bin/swift test -Xswiftc -suppress-warnings
156+
env:
157+
LDK_C_BINDINGS_BASE: /home/runner/work/ldk-swift/ldk-swift/ci/ldk-c-bindings
158+
LLVM_CLANG_ASAN_PATH: /usr/lib/llvm-11/lib/clang/11.0.0/lib/linux/libclang_rt.asan-x86_64.a
159+
RUST_BACKTRACE: 1
160+

bindings/LDK/Bindings.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4983,6 +4983,16 @@ public class Bindings {
49834983

49844984
CResult_ProbabilisticScoringParametersDecodeErrorZ_is_ok(oPointer)
49854985

4986+
}
4987+
4988+
}
4989+
public class func swift_CResult_ProbabilisticScorerDecodeErrorZ_is_ok(o: Result_ProbabilisticScorerDecodeErrorZ) -> Bool {
4990+
4991+
4992+
return withUnsafePointer(to: o.cOpaqueStruct!) { (oPointer: UnsafePointer<LDKCResult_ProbabilisticScorerDecodeErrorZ>) in
4993+
4994+
CResult_ProbabilisticScorerDecodeErrorZ_is_ok(oPointer)
4995+
49864996
}
49874997

49884998
}
@@ -6450,7 +6460,7 @@ withUnsafePointer(to: scorer.cOpaqueStruct!) { (scorerPointer: UnsafePointer<LDK
64506460
*/
64516461

64526462
public class func get_ldk_swift_bindings_version() -> String {
6453-
return "722d6c573ab71c35eb9373e2d7b368f33c3a0dd0"
6463+
return "a086cb7d66870a61b4c5b98ae5d293d840342ad0"
64546464
}
64556465

64566466
}

bindings/LDK/structs/AnnouncementSignatures.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class AnnouncementSignatures: NativeTypeWrapper {
1313

1414
self.cOpaqueStruct = AnnouncementSignatures_new(Bindings.new_LDKThirtyTwoBytes(array: channel_id_arg), short_channel_id_arg, Bindings.new_LDKSignature(array: node_signature_arg), Bindings.new_LDKSignature(array: bitcoin_signature_arg))
1515
super.init(conflictAvoidingVariableName: 0)
16+
1617
}
1718
/* DEFAULT_CONSTRUCTOR_END */
1819

bindings/LDK/structs/BackgroundProcessor.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ BackgroundProcessor_start(persister.cOpaqueStruct!, event_handler.cOpaqueStruct!
2323
}
2424
}
2525
super.init(conflictAvoidingVariableName: 0)
26+
try? self.addAnchor(anchor: persister)
27+
try? self.addAnchor(anchor: event_handler)
28+
try? self.addAnchor(anchor: chain_monitor)
29+
try? self.addAnchor(anchor: channel_manager)
30+
31+
if let handler = net_graph_msg_handler {
32+
try? self.addAnchor(anchor: handler)
33+
}
34+
35+
try? self.addAnchor(anchor: peer_manager)
36+
try? self.addAnchor(anchor: logger)
37+
2638
}
2739
/* DEFAULT_CONSTRUCTOR_END */
2840

bindings/LDK/structs/BestBlock.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class BestBlock: NativeTypeWrapper {
1313

1414
self.cOpaqueStruct = BestBlock_new(Bindings.new_LDKThirtyTwoBytes(array: block_hash), height)
1515
super.init(conflictAvoidingVariableName: 0)
16+
1617
}
1718
/* DEFAULT_CONSTRUCTOR_END */
1819

bindings/LDK/structs/BuiltCommitmentTransaction.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class BuiltCommitmentTransaction: NativeTypeWrapper {
1818

1919
self.cOpaqueStruct = BuiltCommitmentTransaction_new(transaction_argWrapper.dangle().cOpaqueStruct!, Bindings.new_LDKThirtyTwoBytes(array: txid_arg))
2020
super.init(conflictAvoidingVariableName: 0)
21+
2122
}
2223
/* DEFAULT_CONSTRUCTOR_END */
2324

bindings/LDK/structs/ChainMonitor.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ public init(chain_source: Option_FilterZ, broadcaster: BroadcasterInterface, log
1515

1616
self.cOpaqueStruct = ChainMonitor_new(chain_source.cOpaqueStruct!, broadcaster.cOpaqueStruct!, logger.cOpaqueStruct!, feeest.cOpaqueStruct!, persister.cOpaqueStruct!)
1717
super.init(conflictAvoidingVariableName: 0)
18+
try? self.addAnchor(anchor: chain_source)
19+
try? self.addAnchor(anchor: broadcaster)
20+
try? self.addAnchor(anchor: logger)
21+
try? self.addAnchor(anchor: feeest)
22+
try? self.addAnchor(anchor: persister)
23+
1824
}
1925
/* DEFAULT_CONSTRUCTOR_END */
2026

bindings/LDK/structs/ChainParameters.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public init(network_arg: LDKNetwork, best_block_arg: BestBlock) {
1515

1616
self.cOpaqueStruct = ChainParameters_new(network_arg, best_block_arg.danglingClone().cOpaqueStruct!)
1717
super.init(conflictAvoidingVariableName: 0)
18+
1819
}
1920
/* DEFAULT_CONSTRUCTOR_END */
2021

bindings/LDK/structs/ChannelAnnouncement.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ChannelAnnouncement: NativeTypeWrapper {
1313

1414
self.cOpaqueStruct = ChannelAnnouncement_new(Bindings.new_LDKSignature(array: node_signature_1_arg), Bindings.new_LDKSignature(array: node_signature_2_arg), Bindings.new_LDKSignature(array: bitcoin_signature_1_arg), Bindings.new_LDKSignature(array: bitcoin_signature_2_arg), contents_arg.danglingClone().cOpaqueStruct!)
1515
super.init(conflictAvoidingVariableName: 0)
16+
1617
}
1718
/* DEFAULT_CONSTRUCTOR_END */
1819

bindings/LDK/structs/ChannelConfig.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ChannelConfig: NativeTypeWrapper {
1313

1414
self.cOpaqueStruct = ChannelConfig_default()
1515
super.init(conflictAvoidingVariableName: 0)
16+
1617
}
1718
/* DEFAULT_CONSTRUCTOR_END */
1819

0 commit comments

Comments
 (0)