Skip to content

Commit

Permalink
bootstrap feature big refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-at-decenomy committed May 10, 2024
1 parent b73edd8 commit 693abdd
Show file tree
Hide file tree
Showing 33 changed files with 620 additions and 1,851 deletions.
129 changes: 129 additions & 0 deletions build-aux/m4/ax_boost_json.m4
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# ===========================================================================
# https://www.gnu.org/software/autoconf-archive/ax_boost_json.html
# ===========================================================================
#
# SYNOPSIS
#
# AX_BOOST_JSON
#
# DESCRIPTION
#
# Test for the JSON library from the Boost C++ libraries. The macro
# requires a preceding call to AX_BOOST_BASE. Further documentation is
# available at <http://randspringer.de/boost/index.html>.
#
# This macro calls:
#
# AC_SUBST(BOOST_JSON_LIB)
#
# And sets:
#
# HAVE_BOOST_JSON
#
# LICENSE
#
# Copyright (c) 2008 Thomas Porschberg <[email protected]>
# Copyright (c) 2008 Michael Tindal
# Copyright (c) 2013 Daniel Casimiro <[email protected]>
# Copyright (c) 2021 Richard Winters <[email protected]>
# Copyright (c) 2022 Luke Mewburn <[email protected]>
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 2

AC_DEFUN([AX_BOOST_JSON], [
AC_ARG_WITH([boost-json],
AS_HELP_STRING([--with-boost-json@<:@=special-lib@:>@],
[use the JSON library from boost - it is possible to specify a certain library for the linker
e.g. --with-boost-json=boost_json-gcc-mt ]
), [
if test "$withval" = "no"; then
want_boost="no"
elif test "$withval" = "yes"; then
want_boost="yes"
ax_boost_user_json_lib=""
else
want_boost="yes"
ax_boost_user_json_lib="$withval"
fi
], [want_boost="yes"]
)
if test "x$want_boost" = "xyes"; then
AC_REQUIRE([AC_PROG_CC])
AC_REQUIRE([AC_CANONICAL_BUILD])
CPPFLAGS_SAVED="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
export CPPFLAGS
LDFLAGS_SAVED="$LDFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"
export LDFLAGS
AC_CACHE_CHECK(whether the Boost::JSON library is available,
ax_cv_boost_json, [
AC_LANG_PUSH([C++])
CXXFLAGS_SAVE=$CXXFLAGS
AC_COMPILE_IFELSE([
AC_LANG_PROGRAM([[@%:@include <boost/json.hpp>]],
dnl XXXLUKEM
[[boost::json::object obj; obj["ax"] = 1; std::string s = boost::json::serialize(obj);]])
],
ax_cv_boost_json=yes,
ax_cv_boost_json=no
)
CXXFLAGS=$CXXFLAGS_SAVE
AC_LANG_POP([C++])
])
if test "x$ax_cv_boost_json" = "xyes"; then
AC_SUBST(BOOST_CPPFLAGS)
AC_DEFINE(HAVE_BOOST_JSON,,[define if the Boost::JSON library is available])
BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'`
LDFLAGS_SAVE=$LDFLAGS
if test "x$ax_boost_user_json_lib" = "x"; then
for libextension in `ls $BOOSTLIBDIR/libboost_json*.so* $BOOSTLIBDIR/libboost_json*.dylib* $BOOSTLIBDIR/libboost_json*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_json.*\)\.so.*$;\1;' -e 's;^lib\(boost_json.*\)\.dylib.*$;\1;' -e 's;^lib\(boost_json.*\)\.a.*$;\1;'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_JSON_LIB="-l$ax_lib"; AC_SUBST(BOOST_JSON_LIB) link_json="yes"; break],
[link_json="no"]
)
done
if test "x$link_json" != "xyes"; then
for libextension in `ls $BOOSTLIBDIR/boost_json*.dll* $BOOSTLIBDIR/boost_json*.a* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_json.*\)\.dll.*$;\1;' -e 's;^\(boost_json.*\)\.a.*$;\1;'` ; do
ax_lib=${libextension}
AC_CHECK_LIB($ax_lib, exit,
[BOOST_JSON_LIB="-l$ax_lib"; AC_SUBST(BOOST_JSON_LIB) link_json="yes"; break],
[link_json="no"]
)
done
fi
else
for ax_lib in $ax_boost_user_json_lib boost_json-$ax_boost_user_json_lib; do
AC_CHECK_LIB($ax_lib, exit,
[BOOST_JSON_LIB="-l$ax_lib"; AC_SUBST(BOOST_JSON_LIB) link_json="yes"; break],
[link_json="no"]
)
done
fi
if test "x$ax_lib" = "x"; then
AC_MSG_ERROR(Could not find a version of the Boost::JSON library!)
fi
if test "x$link_json" = "xno"; then
AC_MSG_ERROR(Could not link against $ax_lib !)
fi
fi
CPPFLAGS="$CPPFLAGS_SAVED"
LDFLAGS="$LDFLAGS_SAVED"
fi
])
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,7 @@ AX_BOOST_FILESYSTEM
AX_BOOST_PROGRAM_OPTIONS
AX_BOOST_THREAD
AX_BOOST_CHRONO
AX_BOOST_JSON

dnl Boost 1.56 through 1.62 allow using std::atomic instead of its own atomic
dnl counter implementations. In 1.63 and later the std::atomic approach is default.
Expand Down Expand Up @@ -1067,7 +1068,7 @@ if test x$use_tests = xyes; then
fi

if test x$use_boost = xyes; then
BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB $BOOST_PROGRAM_OPTIONS_LIB $BOOST_THREAD_LIB $BOOST_CHRONO_LIB"
BOOST_LIBS="$BOOST_LDFLAGS $BOOST_SYSTEM_LIB $BOOST_FILESYSTEM_LIB $BOOST_PROGRAM_OPTIONS_LIB $BOOST_THREAD_LIB $BOOST_CHRONO_LIB $BOOST_JSON_LIB"
fi

if test x$use_pkgconfig = xyes; then
Expand Down
4 changes: 3 additions & 1 deletion contrib/pivx-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ HEADERS += src/activemasternode.h \
src/keepass.h \
src/key.h \
src/keystore.h \
src/curl.h \
src/leveldbwrapper.h \
src/limitedmap.h \
src/main.h \
Expand Down Expand Up @@ -129,6 +130,7 @@ HEADERS += src/activemasternode.h \
src/utilstrencodings.h \
src/utiltime.h \
src/version.h \
src/zip.h \
src/wallet.h \
src/wallet_ismine.h \
src/walletdb.h \
Expand Down Expand Up @@ -340,7 +342,7 @@ HEADERS += src/activemasternode.h \
src/qt/intro.moc \
src/qt/overviewpage.moc \
src/qt/rpcconsole.moc \
src/secp256k1/src/secp256k1.c
src/secp256k1/src/secp256k1.c
FORMS += src/qt/forms/addressbookpage.ui \
src/qt/forms/askpassphrasedialog.ui \
src/qt/forms/coincontroldialog.ui \
Expand Down
18 changes: 11 additions & 7 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ BITCOIN_CORE_H = \
bip38.h \
bloom.h \
blocksignature.h \
bootstrap/bootstrap.h \
bootstrap/minizip/ioapi.h \
bootstrap/minizip/unzip.h \
bootstrap.h \
minizip/ioapi.h \
minizip/unzip.h \
chain.h \
chainparams.h \
chainparamsbase.h \
Expand Down Expand Up @@ -129,6 +129,7 @@ BITCOIN_CORE_H = \
key.h \
key_io.h \
keystore.h \
curl.h \
dbwrapper.h \
limitedmap.h \
logging.h \
Expand Down Expand Up @@ -201,6 +202,7 @@ BITCOIN_CORE_H = \
utiltime.h \
validationinterface.h \
version.h \
zip.h \
wallet/hdchain.h \
wallet/rpcwallet.h \
wallet/scriptpubkeyman.h \
Expand Down Expand Up @@ -232,6 +234,7 @@ libbitcoin_server_a_SOURCES = \
httprpc.cpp \
httpserver.cpp \
init.cpp \
curl.cpp \
dbwrapper.cpp \
main.cpp \
merkleblock.cpp \
Expand All @@ -258,6 +261,11 @@ libbitcoin_server_a_SOURCES = \
txdb.cpp \
txmempool.cpp \
validationinterface.cpp \
zip.cpp \
bootstrap.cpp \
minizip/ioapi.c \
minizip/unzip.c \
sqlite3/sqlite3.c \
$(BITCOIN_CORE_H)

if ENABLE_ZMQ
Expand All @@ -278,9 +286,6 @@ libbitcoin_wallet_a_SOURCES = \
activemasternodeconfig.cpp \
activemasternodeman.cpp \
bip38.cpp \
bootstrap/bootstrap.cpp \
bootstrap/minizip/ioapi.c \
bootstrap/minizip/unzip.c \
interface/wallet.cpp \
addressbook.cpp \
crypter.cpp \
Expand All @@ -301,7 +306,6 @@ libbitcoin_wallet_a_SOURCES = \
wallet/wallet.cpp \
wallet/walletdb.cpp \
stakeinput.cpp \
sqlite3/sqlite3.c \
$(BITCOIN_CORE_H)

# crypto primitives library
Expand Down
121 changes: 121 additions & 0 deletions src/bootstrap.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (c) 2024 The DECENOMY Core Developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "bootstrap.h"

#ifdef HAVE_CONFIG_H
#include "config/pivx-config.h"
#endif

#include "amount.h"
#include "chainparams.h"
#include "curl.h"
#include "guiinterface.h"
#include "util.h"
#include "zip.h"

#include <iostream>

namespace fs = boost::filesystem;

std::string extractFilenameFromURL(const std::string& url)
{
// Find the last '/' in the URL, which is expected to precede the filename
size_t last_slash_pos = url.find_last_of("/");

// Check if the last slash position is valid and there are characters after the '/'
if (last_slash_pos != std::string::npos && last_slash_pos + 1 < url.size()) {
return url.substr(last_slash_pos + 1);
}

// If no '/' found, or there is nothing after the last '/', return an empty string
return "";
}

int progressCallback(
void* clientp,
curl_off_t dltotal,
curl_off_t dlnow,
curl_off_t ultotal,
curl_off_t ulnow)
{
static int progress = 0;
const auto currentProgress = dltotal > 0 ? (int)((dlnow * 100) / dltotal) : 0;

if (currentProgress > progress) {
progress = currentProgress;
LogPrintf("CBootstrap::%s: Download: %d%%\n", __func__, progress);
uiInterface.ShowProgress(_("Download: "), progress);
}

return 0;
}

bool CBootstrap::DownloadAndApply()
{
const auto url =
std::string(BOOTSTRAP_URL) +
(Params().IsTestNet() ? "T" : "") + std::string(CURRENCY_UNIT) +
"/bootstrap.zip";
const auto datadir = GetDataDir();
const auto fileName = datadir / extractFilenameFromURL(url);
const auto blocks = datadir / "blocks";
const auto chainstate = datadir / "chainstate";
const auto sporks = datadir / "sporks";
const auto banlist = datadir / "banlist.dat";

try {
// Step 1: Download the bootstrap file
if (!CCurlWrapper::DownloadFile(url, fileName.string(), progressCallback)) {
LogPrintf(
"CBootstrap::%s: Failed to download the bootstrap file: %s\n",
__func__,
fileName.string());
return false;
}

// Step 2: Cleanup the existing folders and files
try {
fs::remove_all(blocks);
fs::remove_all(chainstate);
fs::remove_all(sporks);
fs::remove_all(banlist);
} catch (const boost::filesystem::filesystem_error& e) {
LogPrintf("CBootstrap::%s: Error removing: %s\n", __func__, e.what());
return false;
}

// Step 3: Unzip the downloaded file
if (!CZipWrapper::ExtractZip(fileName.string(), datadir.string())) {
LogPrintf(
"CBootstrap::%s: Failed to unzip the bootstrap file: %s into: %s\n",
__func__, fileName.string(), datadir.string());
fs::remove_all(fileName);
fs::remove_all(blocks);
fs::remove_all(chainstate);
fs::remove_all(sporks);
fs::remove_all(banlist);

return false;
}

// Step 4: Cleanup the bootstrap file
fs::remove_all(fileName);

} catch (const std::exception& e) {
LogPrintf(
"CBootstrap::%s: Error downloading bootstrap file: %s\n",
__func__, e.what());

fs::remove_all(fileName);
fs::remove_all(blocks);
fs::remove_all(chainstate);
fs::remove_all(sporks);
fs::remove_all(banlist);

return false;
}

return true;
}
16 changes: 16 additions & 0 deletions src/bootstrap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024 The DECENOMY Core Developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BOOTSTRAP_H
#define BOOTSTRAP_H

#define APPLE_CA_PATH "/etc/ssl/cert.pem"

class CBootstrap
{
public:
static bool DownloadAndApply();
};

#endif
10 changes: 0 additions & 10 deletions src/bootstrap/Dockerfile.linux-x64

This file was deleted.

Loading

0 comments on commit 693abdd

Please sign in to comment.