diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 03b27649155d..d7e081079eb1 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -431,7 +431,7 @@ jobs: if [ "${{ matrix.config.unit_tests }}" = "true" ] || [ "${{ matrix.config.functional_tests }}" = "true" ]; then echo ::group::Params - util/fetch-params.sh $PARAMS_DIR + ./params/install-params.sh $PARAMS_DIR echo ::endgroup:: fi diff --git a/Makefile.am b/Makefile.am index b6fc01a2e3cc..f816decb9595 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,6 +7,7 @@ SUBDIRS = src if ENABLE_MAN SUBDIRS += doc/man endif +SUBDIRS += params .PHONY: deploy FORCE export PYTHONPATH @@ -53,7 +54,7 @@ DIST_CARGO = \ $(top_srcdir)/Cargo.lock \ $(top_srcdir)/Cargo.toml \ $(top_srcdir)/rust-toolchain \ - $(top_srcdir)/util/fetch-params.sh + $(top_srcdir)/params/install-params.sh BIN_CHECKS=$(top_srcdir)/contrib/devtools/symbol-check.py \ $(top_srcdir)/contrib/devtools/security-check.py @@ -73,6 +74,9 @@ OSX_PACKAGING = $(OSX_DEPLOY_SCRIPT) $(OSX_FANCY_PLIST) $(OSX_INSTALLER_ICONS) \ $(top_srcdir)/contrib/macdeploy/detached-sig-apply.sh \ $(top_srcdir)/contrib/macdeploy/detached-sig-create.sh +SPEND_PARAMS = $(top_srcdir)/params/sapling-spend.params +OUTPUT_PARAMS = $(top_srcdir)/params/sapling-output.params + COVERAGE_INFO = baseline.info \ test_pivx_filtered.info total_coverage.info \ baseline_filtered.info functional_test.info functional_test_filtered.info \ @@ -114,9 +118,18 @@ $(OSX_APP)/Contents/Resources/Base.lproj/InfoPlist.strings: $(MKDIR_P) $(@D) echo '{ CFBundleDisplayName = "$(PACKAGE_NAME)"; CFBundleName = "$(PACKAGE_NAME)"; }' > $@ +$(OSX_APP)/Contents/Resources/sapling-spend.params: $(SPEND_PARAMS) + $(MKDIR_P) $(@D) + $(INSTALL_DATA) $< $@ + +$(OSX_APP)/Contents/Resources/sapling-output.params: $(OUTPUT_PARAMS) + $(MKDIR_P) $(@D) + $(INSTALL_DATA) $< $@ + OSX_APP_BUILT=$(OSX_APP)/Contents/PkgInfo $(OSX_APP)/Contents/Resources/empty.lproj \ $(OSX_APP)/Contents/Resources/bitcoin.icns $(OSX_APP)/Contents/Info.plist \ - $(OSX_APP)/Contents/MacOS/PIVX-Qt $(OSX_APP)/Contents/Resources/Base.lproj/InfoPlist.strings + $(OSX_APP)/Contents/MacOS/PIVX-Qt $(OSX_APP)/Contents/Resources/Base.lproj/InfoPlist.strings \ + $(OSX_APP)/Contents/Resources/sapling-spend.params $(OSX_APP)/Contents/Resources/sapling-output.params osx_volname: echo $(OSX_VOLNAME) >$@ diff --git a/build-aux/snap/snapcraft.yaml b/build-aux/snap/snapcraft.yaml index 9a9e8ecf1962..70fe8e356c9f 100644 --- a/build-aux/snap/snapcraft.yaml +++ b/build-aux/snap/snapcraft.yaml @@ -175,9 +175,9 @@ parts: fi ./autogen.sh if [ $DEPENDS = 1 ]; then - ./configure --prefix=`pwd`/depends/${HOST} --with-params-dir=${SNAP_USER_COMMON}/${PARAMSDIR} + ./configure --prefix=`pwd`/depends/${HOST} else - ./configure --with-incompatible-bdb --with-params-dir=${SNAP_USER_COMMON}/${PARAMSDIR} + ./configure --with-incompatible-bdb fi echo "-----------------------------------------------" echo "+++++++++++++++++++++++++++++++++++++++++++++++" @@ -231,11 +231,13 @@ parts: echo "CONFIG FILE" # create .pivx folder and copy example config - !!!warning!!!: do not copy as pivx.conf echo "+++++++++++++++++++++++++++++++++++++++++++++++" mkdir -p ${SNAP_USER_COMMON}/.${DATADIR} + mkdir -p ${SNAP_USER_COMMON}/${PARAMSDIR} if [ $COPYCONF = 1 ]; then cp ${SNAPCRAFT_PART_BUILD}/contrib/debian/manpages/${CONF}.conf.5 ${SNAP_USER_COMMON}/.${DATADIR}/${CONF}-example.conf else echo "COPY CONFIG FILE disabled, skipping" fi + cp ${SNAPCRAFT_PART_BUILD}/params/*.params ${SNAP_USER_COMMON}/${PARAMSDIR}/ echo "-----------------------------------------------" echo "+++++++++++++++++++++++++++++++++++++++++++++++" echo "RUN TESTS" # if tests fail to pass, build and release will fail @@ -243,7 +245,6 @@ parts: cd ${SNAPCRAFT_PART_BUILD} if [ ! $SNAPCRAFT_ARCH_TRIPLET = "s390x-linux-gnu" ]; then if [ $RUNTESTS = 1 ]; then - ${SNAPCRAFT_PROJECT_DIR}/util/fetch-params.sh ${SNAP_USER_COMMON}/${PARAMSDIR} make check else echo "RUN TESTS disabled, skipping" @@ -300,6 +301,7 @@ parts: - libdb++-dev stage-packages: - libxkbcommon0 + - libxcb-xinerama0 - ttf-ubuntu-font-family - dmz-cursor-theme - light-themes @@ -324,6 +326,8 @@ parts: - libpgm-5.2-0 - libprotobuf10 - libqrencode3 + - libqt5core5a + - libqt5dbus5 - libqt5charts5 - libqt5test5 - libsodium23 diff --git a/configure.ac b/configure.ac index f735a24cd635..443e2be973de 100644 --- a/configure.ac +++ b/configure.ac @@ -599,6 +599,7 @@ case $host in fi AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"]) + AX_CHECK_LINK_FLAG([[-framework CoreFoundation]], [LDFLAGS="$LDFLAGS -framework CoreFoundation"], [AC_MSG_ERROR([could not find CoreFoundation framework])]) CPPFLAGS="$CPPFLAGS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0" OBJCXXFLAGS="$CXXFLAGS" ;; @@ -1485,7 +1486,7 @@ AC_SUBST(HAVE_BUILTIN_PREFETCH) AC_SUBST(HAVE_MM_PREFETCH) AC_SUBST(HAVE_STRONG_GETAUXVAL) AC_SUBST(HAVE_WEAK_GETAUXVAL) -AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini]) +AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile params/Makefile share/setup.nsi share/qt/Info.plist test/config.ini]) AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh]) AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])]) AC_CONFIG_LINKS([contrib/filter-lcov.py:contrib/filter-lcov.py]) diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml index 9a13b7c71247..9c90674e0dc9 100644 --- a/contrib/gitian-descriptors/gitian-linux.yml +++ b/contrib/gitian-descriptors/gitian-linux.yml @@ -184,6 +184,7 @@ script: | find ${DISTNAME}/bin -type f -executable -print0 | xargs -0 -n1 -I{} ../contrib/devtools/split-debug.sh {} {} {}.dbg #find ${DISTNAME}/lib -type f -print0 | xargs -0 -n1 -I{} ../contrib/devtools/split-debug.sh {} {} {}.dbg cp ../doc/README.md ${DISTNAME}/ + cp ../params/install-params.sh ${DISTNAME}/ find ${DISTNAME} -not -name "*.dbg" | sort | tar --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}.tar.gz find ${DISTNAME} -name "*.dbg" | sort | tar --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}-debug.tar.gz cd ../../ diff --git a/contrib/gitian-descriptors/gitian-osx.yml b/contrib/gitian-descriptors/gitian-osx.yml index 96115a094ae5..0f87e9891dca 100644 --- a/contrib/gitian-descriptors/gitian-osx.yml +++ b/contrib/gitian-descriptors/gitian-osx.yml @@ -162,6 +162,7 @@ script: | find . -name "lib*.la" -delete find . -name "lib*.a" -delete rm -rf ${DISTNAME}/lib/pkgconfig + cp ../params/install-params.sh ${DISTNAME}/ find ${DISTNAME} | sort | tar --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}.tar.gz cd ../../ done diff --git a/doc/README.md b/doc/README.md index 092e65d187a7..9d607ca762b4 100644 --- a/doc/README.md +++ b/doc/README.md @@ -16,6 +16,8 @@ Unpack the files into a directory and run: - `bin/pivx-qt` (GUI) or - `bin/pivxd` (headless) +If this is the first time running PIVX Core (since v5.0.0), you'll need to install the sapling params by running the included `install-params.sh` script, which copies the two params files to `$HOME/.pivx-params` + ### Windows Unpack the files into a directory, and then run pivx-qt.exe. diff --git a/params/Makefile.am b/params/Makefile.am new file mode 100644 index 000000000000..02f1a142d17e --- /dev/null +++ b/params/Makefile.am @@ -0,0 +1,3 @@ +dist_data_DATA = + +dist_data_DATA+=sapling-output.params sapling-spend.params diff --git a/params/install-params.sh b/params/install-params.sh new file mode 100755 index 000000000000..1d7a47375da0 --- /dev/null +++ b/params/install-params.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +# +# Copyright (c) 2015-2020 The Zcash developers +# Copyright (c) 2020 The PIVX developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +export LC_ALL=C.UTF-8 + +set -eu + +if [ -n "${1:-}" ]; then + PARAMS_DIR="$1" +else + if [[ "$OSTYPE" == "darwin"* ]]; then + PARAMS_DIR="$HOME/Library/Application Support/PIVXParams" + else + PARAMS_DIR="$HOME/.pivx-params" + fi +fi + +SAPLING_SPEND_NAME='sapling-spend.params' +SAPLING_OUTPUT_NAME='sapling-output.params' + +SHA256CMD="$(command -v sha256sum || echo shasum)" +SHA256ARGS="$(command -v sha256sum >/dev/null || echo '-a 256')" + +pushd () { + command pushd "$@" > /dev/null +} + +popd () { + command popd > /dev/null +} + +function install_params { + local filename="$1" + local output="$2" + local expectedhash="$3" + + # if the params don't exist in the current directory, assume we're running from release tarballs + if ! [ -f "$filename" ] + then + filename="share/$filename" + fi + + if ! [ -f "$output" ] + then + "$SHA256CMD" $SHA256ARGS -c <&2 + exit 1 + fi + fi +} + +# Use flock to prevent parallel execution. +function lock() { + local lockfile=/tmp/install_params.lock + if [[ "$OSTYPE" == "darwin"* ]]; then + if shlock -f ${lockfile} -p $$; then + return 0 + else + return 1 + fi + else + # create lock file + eval "exec 200>$lockfile" + # acquire the lock + flock -n 200 \ + && return 0 \ + || return 1 + fi +} + +function exit_locked_error { + echo "Only one instance of install-params.sh can be run at a time." >&2 + exit 1 +} + +function main() { + + lock install-params.sh \ + || exit_locked_error + + cat <> "$README_PATH" < #endif +#ifdef MAC_OSX +#include +#endif + #include #include #include @@ -441,11 +445,41 @@ void initZKSNARKS() fs::path sapling_spend = path / "sapling-spend.params"; fs::path sapling_output = path / "sapling-output.params"; - if (!(fs::exists(sapling_spend) && - fs::exists(sapling_output) - )) { - throw std::runtime_error("Sapling params don't exist"); + bool fParamsFound = false; + if (fs::exists(sapling_spend) && fs::exists(sapling_output)) { + fParamsFound = true; + } else { +#ifdef MAC_OSX + // macOS fallback path for params located within the app bundle + // This is a somewhat convoluted series of CoreFoundation calls + // that will result in the full path to the app bundle's "Resources" + // directory, which will contain the sapling params. + LogPrintf("Attempting to find params in app bundle...\n"); + CFBundleRef mainBundle = CFBundleGetMainBundle(); + CFURLRef bundleURL = CFBundleCopyBundleURL(mainBundle); + + CFStringRef strBundlePath = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); + const char* pathBundle = CFStringGetCStringPtr(strBundlePath, CFStringGetSystemEncoding()); + + fs::path bundle_path = fs::path(pathBundle); + LogPrintf("App bundle Resources path: %s\n", bundle_path); + sapling_spend = bundle_path / "Contents/Resources/sapling-spend.params"; + sapling_output = bundle_path / "Contents/Resources/sapling-output.params"; + + // Release the CF objects + CFRelease(strBundlePath); + CFRelease(bundleURL); + CFRelease(mainBundle); +#else + // Linux fallback path for debuild/ppa based installs + sapling_spend = "/usr/local/share/sapling-spend.params"; + sapling_output = "/usr/local/share/sapling-output.params"; +#endif + if (fs::exists(sapling_spend) && fs::exists(sapling_output)) + fParamsFound = true; } + if (!fParamsFound) + throw std::runtime_error("Sapling params don't exist"); static_assert( sizeof(fs::path::value_type) == sizeof(codeunit),