-
Notifications
You must be signed in to change notification settings - Fork 137
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
Updates to ABI handling in preparation for semver #409
Conversation
87802c2
to
bc57fd8
Compare
@whitslack note this change also exposes the transaction accessor functions which were the cause of many build failures with various configure options. I would really appreciate it if you could test the new options, thanks! |
@jgriffiths: Thanks for your work on this. I greatly appreciate it, both stabilizing the ABI w.r.t. build options and moving to semantic versioning. I'll start working on a Gentoo ebuild for 1.0.0 today and will report back with my findings. |
… ABI compliance As wally is now being installed as a global shared library by at least one distro (Gentoo), update how the ABI is handled to ensure that elements and non-elements builds are compatible at the C structure level: 1. By default, Elements support is now enabled. 2. By default, if Elements support is disabled, the C structs defining library types retain the extra Elements members. 3. Allow removing the extra members by configuring with --disable-elements --disable-elements-abi. The caller must define WALLY_ABI_NO_ELEMENTS before including any wally headers. This configuration can be used for Bitcoin-only embedded environments, but must not be used when installing wally as a system shared library. Currently elements specific functions remain undefined in the wally headers unless BUILD_ELEMENTS is defined by the caller. Note that the Python and Javascript wrappers are unaffected as these releases always enabled elements. Callers can determine if the library was compiled with elements support by calling wally_is_elements_build().
…ly_transaction_members.h
Also add missing coin selection header.
Future error handling will support extended error codes via these functions which are user-overridable in order to support thread safety. Make the structure changes now without using them so we can avoid an ABI version bump once implemented.
…s (1) Part 1, header changes. As with the previous c-struct change, by default Elements is enabled and elements functions are exported from the library. Using --disable-elements now leaves the Elements functions available, but calling them will always return WALLY_ERROR. This behaviour allows installing a system-wide wally built without Elements support which applications can gracefully detect at runtime via wally_is_elements_build() and handle by degrading functionality or failing to start. To compile the Elements functions out completely, the user must configure with --disable-elements-abi and define WALLY_ABI_NO_ELEMENTS when including library headers. This allows e.g. embeddeded/static builds to eliminate all Elements code entirely. As before, WALLY_ABI_NO_ELEMENTS builds must not be installed as system-wide shared libraries. Doing so may result in either memory corruption at runtime (if no Elements code is used) or linker errors on startup due to missing Elements calls.
…s (2) Part 2, source changes.
bc57fd8
to
d0d93fd
Compare
Updated and rebased over #410 which has been merged first. |
d0d93fd
to
0a915e9
Compare
@jgriffiths: I'm seeing some test failures (at 0a915e9)…
Interestingly, all tests pass when run on Python 3.11.5. The failures occur on Python 3.12.0rc1(p6). Releases 0.8.8, 0.9.0, 0.9.1, and 0.9.2 all exhibit the same test failures on Python 3.12. (I have not tested other releases.) |
Multiple unit tests are failing with dev-lang/python-3.12_rc1_p6. See: ElementsProject/libwally-core#409 (comment)
@whitslack very strange! I assume this is your first time testing v3.12? what does test map print if run with:
? |
It's possible. On my system my ebuild happens to test libwally-core using Python 3.11 when the
Under Python 3.11, I get:
Under Python 3.12, I get:
|
@whitslack |
Incidentally, I exhaustively tested all allowed combinations of |
Thanks, I should have time tomorrow to review your remaining changes and will look into 3.12 asap after that. |
The POSIX Shell 'test' built-in does not define a '==' operator. It works if /bin/sh happens to be Bash, but that is non-standard.
SWIG generates code with unused parameters that trigger hundreds of warnings.
version-info is what determines the dotted triplet of numbers trailing the shared library filename. Meticulous maintenance of version-info allows multiple ABI versions of the library to be installed on a system concurrently and also makes obvious when library clients need to be recompiled for a newer ABI (and when no recompilation is necessary). See: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
Quoting jgriffiths: > --enable-openssl-tests is no longer supported in secp and should be removed Suggested-by: Jon Griffiths <[email protected]> (@jgriffiths) See: #414 (comment)
libsecp256k1 dropped support for bignum in October 2020. See: bitcoin-core/secp256k1@1f233b3
Starting up a JVM is not a lightweight affair. For this reason, typically all Java source files are compiled by a single invocation of javac. Use GNU Make's "grouped targets" feature to specify that all Java class files are produced by a single execution of the recipe. Further, avoid compiling the test classes if tests are disabled.
476ac41
to
81ccbab
Compare
Fixes a warning about overriding 'all'.
Altering ac_configure_args to configure libsecp256k1 with options differing from those of libwally-core causes issues if the wally Makefile is out of date and needs to call autoreconf etc to regenerate itself. The secp arguments are passed back to the top level configure which changes and possibly breaks the original configuration. Instead, import and use AX_SUBDIRS_CONFIGURE from the autoconf-archive which supports sub-confiration with bespoke arguments. Because autoreconf does not recurse into subdirectories named by AX_SUBDIRS_CONFIGURE, we lose the automagic Autotools (re)generation in src/secp256k1, so add an explicit call to src/secp256k1/autogen.sh in tools/autogen.sh.
Extracted from a patch by Matt Whitlock <[email protected]>. Also reduce the include directories given for python wheel building.
(Modified from the original submission). Libwally-core, in its stock configuration, compiles and statically links against a private copy of libsecp256k1_zkp. However, Gentoo unbundles libsecp256k1_zkp and instead links libwally-core against a system-wide shared libsecp256k1_zkp with headers in /usr/include/secp256k1_zkp and a libsecp256k1_zkp.pc that specifies the relevant CFLAGS and LIBS. Implement a --with-system-secp256k1 configure option to allow compiling and linking against a system-installed libsecp256k1. Pass the user- specified package name (or 'libsecp256k1' or 'libsecp256k1_zkp' by default, depending on --enable-standard-secp) to PKG_CHECK_MODULES to find the CFLAGS and LIBS of a system-installed libsecp256k1. Call AC_CHECK_FUNCS to assert that the required modules are present in the system-installed libsecp256k1. If the user does not specify --with-system-secp256k1 (or specifies --without-system-secp256k1), the build will use the bundled copy of libsecp256k1_zkp as before. Remove the existing libtool hack: When building as a static library, the user will need to link libsecp256k1.a in addition to libwallycore.a.
81ccbab
to
0df2d50
Compare
@jgriffiths: All tests are passing under Python 3.12.0rc2. I guess there must have been a bug in 3.12.0rc1 that affected libwally-core. |
But require >=dev-lang/python-3.12.0_rc2:3.12, as tests fail under rc1. Also: * set DISTUTILS_EXT=1 to suppress a QA warning; * python_check_deps(): only require Sphinx in compile phase. See: ElementsProject/libwally-core#409 (comment)
@whitslack great news. I'm slightly sidetracked working on wallet policies for Jade but will be back to this after. |
Merged elsewhere, closing. |
Motivating issue: #408
Initially wally was intended to always be included in the source tree along with the app that used it, or at least to be statically linked with the using app. Notably, wally can be built with or without Elements support, and whether it is enabled changed the ABI in two ways: (1) the exposed library structures have Elements-specific fields for Elements builds and (2) Elements-specific functions and internal functionality were only defined if the caller defined
BUILD_ELEMENTS
when compiling and including the headers from the library.Note that wally itself is always statically linked with the libsecp256k1 that it uses; by default this is the Blockstream zkp branch which exposes further APIs used by Elements.
For the Python and Javascript packages available through PyPI and npm respectively, wally is always released with Elements support enabled. This allows users to know that all the functionality they may need will be available out of the box.
However, at least one distro (Gentoo) is now installing wally as a global shared library that is re-used by several components. Users may customize the library build and may decide to e.g. disable Elements support when installing. This poses a problem for apps that expect this functionality to run or can optionally run with it present; Because the ABI changes for each build type such apps may either corrupt memory (because expected structure sizes differ between the app and library) or will fail to start (because the linker cannot resolve the Elements calls the app expects).
This PR addresses these issues as follows:
WALLY_MAJOR_VER
/WALLY_MINOR_VER
/WALLY_PATCH_VER
/WALLY_BUILD_VER
and at runtime by callingwally_get_build_version()
.--enable-elements
to configure or defineBUILD_ELEMENTS
when including library headers.--disable-elements
to configure. This configuration is ABI compatible with non-Elements builds; all structures are identical and all Elements APIs are present (they returnWALLY_ERROR
when called, and their actual implementation is compiled out of the library). When built this way, wally can be installed as a global shared library and apps can gracefully fail if the version does not match their expectations or if they expect Elements functionality to be present andwally_is_elements_build()
returns 0.--disable-elements --disable-elements-abi
to configure, and definingWALLY_ABI_NO_ELEMENTS
when including wally headers. Such builds are ABI incompatible with standard builds under (2) or (3) and must not be installed as global shared libraries in the general case except at the users risk (for example, a BTC-only dedicated device, O/S or docker image where all software is pre-installed).cc: @rustyrussell @k-matsuzawa @Sjors @whitslack - Please review and if possible test these changes and report any issues here.
Fixes #408
Fixes #388