Skip to content

Commit f3727fd

Browse files
committed
Merge #20156: build: Make sqlite support optional (compile-time)
bbb42a6 RPC: createwallet: Nicer error message if descriptor wallet requested and sqlite support not compiled in (Luke Dashjr) 6608fec GUI: Create Wallet: Nicely disable descriptor wallet checkbox if sqlite support not compiled in (Luke Dashjr) 7b54d76 Make sqlite support optional (compile-time) (Luke Dashjr) Pull request description: As a new requirement, sqlite support should be optional. This PR aims to be only minimum/blocker changes for 0.21. Potential follow-up PRs after this: * Make BDB support optional * Nicer error messages when user tries to load an unsupported wallet * Don't compile descriptor wallet code if sqlite disabled ACKs for top commit: jonasschnelli: Tested ACK bbb42a6 achow101: ACK bbb42a6 Sjors: re-utACK bbb42a6 hebasto: ACK bbb42a6, tested on Linux Mint 20 (x86_64, Qt 5.12.8). Tree-SHA512: 500209dd1971310fab8ae51543343ce0ba91f088ccccff6109b4cc27547cd5532289dca6cb7dac2a7d7c59cdf3c8f5aacc31e9b0f912e38cea52ec26b97100bd
2 parents 924a4ff + bbb42a6 commit f3727fd

File tree

8 files changed

+57
-5
lines changed

8 files changed

+57
-5
lines changed

configure.ac

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ AC_ARG_ENABLE([wallet],
128128
[enable_wallet=$enableval],
129129
[enable_wallet=yes])
130130

131+
AC_ARG_WITH([sqlite],
132+
[AS_HELP_STRING([--with-sqlite=yes|no|auto],
133+
[enable sqlite wallet support (default: auto, i.e., enabled if wallet is enabled and sqlite is found)])],
134+
[use_sqlite=$withval],
135+
[use_sqlite=auto])
136+
131137
AC_ARG_WITH([miniupnpc],
132138
[AS_HELP_STRING([--with-miniupnpc],
133139
[enable UPNP (default is yes if libminiupnpc is found)])],
@@ -1224,7 +1230,24 @@ if test x$enable_wallet != xno; then
12241230
fi
12251231

12261232
dnl Check for sqlite3
1227-
PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.7.17], , [AC_MSG_ERROR([sqlite3 not found.])])
1233+
if test "x$use_sqlite" != "xno"; then
1234+
PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.7.17], [have_sqlite=yes], [have_sqlite=no])
1235+
fi
1236+
AC_MSG_CHECKING([whether to build wallet with support for sqlite])
1237+
if test "x$use_sqlite" = "xno"; then
1238+
use_sqlite=no
1239+
elif test "x$have_sqlite" = "xno"; then
1240+
if test "x$use_sqlite" = "xyes"; then
1241+
AC_MSG_ERROR([sqlite support requested but cannot be built. Use --without-sqlite])
1242+
fi
1243+
use_sqlite=no
1244+
else
1245+
if test x$use_sqlite != xno; then
1246+
AC_DEFINE([USE_SQLITE],[1],[Define if sqlite support should be compiled in])
1247+
use_sqlite=yes
1248+
fi
1249+
fi
1250+
AC_MSG_RESULT([$use_sqlite])
12281251
fi
12291252

12301253
dnl Check for libminiupnpc (optional)
@@ -1578,6 +1601,7 @@ AM_CONDITIONAL([BUILD_DARWIN], [test x$BUILD_OS = xdarwin])
15781601
AM_CONDITIONAL([TARGET_LINUX], [test x$TARGET_OS = xlinux])
15791602
AM_CONDITIONAL([TARGET_WINDOWS], [test x$TARGET_OS = xwindows])
15801603
AM_CONDITIONAL([ENABLE_WALLET],[test x$enable_wallet = xyes])
1604+
AM_CONDITIONAL([USE_SQLITE], [test "x$use_sqlite" = "xyes"])
15811605
AM_CONDITIONAL([ENABLE_TESTS],[test x$BUILD_TEST = xyes])
15821606
AM_CONDITIONAL([ENABLE_FUZZ],[test x$enable_fuzz = xyes])
15831607
AM_CONDITIONAL([ENABLE_QT],[test x$bitcoin_enable_qt = xyes])
@@ -1643,6 +1667,7 @@ AC_SUBST(AVX2_CXXFLAGS)
16431667
AC_SUBST(SHANI_CXXFLAGS)
16441668
AC_SUBST(ARM_CRC_CXXFLAGS)
16451669
AC_SUBST(LIBTOOL_APP_LDFLAGS)
1670+
AC_SUBST(USE_SQLITE)
16461671
AC_SUBST(USE_UPNP)
16471672
AC_SUBST(USE_QRCODE)
16481673
AC_SUBST(BOOST_LIBS)
@@ -1718,6 +1743,9 @@ echo "Options used to compile and link:"
17181743
echo " boost process = $ax_cv_boost_process"
17191744
echo " multiprocess = $build_multiprocess"
17201745
echo " with wallet = $enable_wallet"
1746+
if test "x$enable_wallet" != "xno"; then
1747+
echo " with sqlite = $use_sqlite"
1748+
fi
17211749
echo " with gui / qt = $bitcoin_enable_qt"
17221750
if test x$bitcoin_enable_qt != xno; then
17231751
echo " with qr = $use_qr"

doc/build-unix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Optional dependencies:
4646
libqrencode | QR codes in GUI | Optional for generating QR codes (only needed when GUI enabled)
4747
univalue | Utility | JSON parsing and encoding (bundled version will be used unless --with-system-univalue passed to configure)
4848
libzmq3 | ZMQ notification | Optional, allows generating ZMQ notifications (requires ZMQ version >= 4.0.0)
49-
sqlite3 | SQLite DB | Wallet storage (only needed when wallet enabled)
49+
sqlite3 | SQLite DB | Optional, wallet storage (only needed when wallet enabled)
5050

5151
For the versions used, see [dependencies.md](dependencies.md)
5252

doc/dependencies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Some dependencies are not needed in all configurations. The following are some f
3434
#### Options passed to `./configure`
3535
* MiniUPnPc is not needed with `--with-miniupnpc=no`.
3636
* Berkeley DB is not needed with `--disable-wallet`.
37-
* SQLite is not needed with `--disable-wallet`.
37+
* SQLite is not needed with `--disable-wallet` or `--without-sqlite`.
3838
* Qt is not needed with `--without-gui`.
3939
* If the qrencode dependency is absent, QR support won't be added. To force an error when that happens, pass `--with-qrencode`.
4040
* ZeroMQ is needed only with the `--with-zmq` option.

src/Makefile.am

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ endif
356356

357357
# wallet: shared between bitcoind and bitcoin-qt, but only linked
358358
# when wallet enabled
359-
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
359+
libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(SQLITE_CFLAGS)
360360
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
361361
libbitcoin_wallet_a_SOURCES = \
362362
interfaces/wallet.cpp \
@@ -372,13 +372,16 @@ libbitcoin_wallet_a_SOURCES = \
372372
wallet/rpcwallet.cpp \
373373
wallet/salvage.cpp \
374374
wallet/scriptpubkeyman.cpp \
375-
wallet/sqlite.cpp \
376375
wallet/wallet.cpp \
377376
wallet/walletdb.cpp \
378377
wallet/walletutil.cpp \
379378
wallet/coinselection.cpp \
380379
$(BITCOIN_CORE_H)
381380

381+
if USE_SQLITE
382+
libbitcoin_wallet_a_SOURCES += wallet/sqlite.cpp
383+
endif
384+
382385
libbitcoin_wallet_tool_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
383386
libbitcoin_wallet_tool_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
384387
libbitcoin_wallet_tool_a_SOURCES = \

src/qt/createwalletdialog.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ CreateWalletDialog::CreateWalletDialog(QWidget* parent) :
3434
ui->disable_privkeys_checkbox->setChecked(false);
3535
}
3636
});
37+
38+
#ifndef USE_SQLITE
39+
ui->descriptor_checkbox->setToolTip(tr("Compiled without sqlite support (required for descriptor wallets)"));
40+
ui->descriptor_checkbox->setEnabled(false);
41+
ui->descriptor_checkbox->setChecked(false);
42+
#endif
3743
}
3844

3945
CreateWalletDialog::~CreateWalletDialog()

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,6 +2742,9 @@ static RPCHelpMan createwallet()
27422742
flags |= WALLET_FLAG_AVOID_REUSE;
27432743
}
27442744
if (!request.params[5].isNull() && request.params[5].get_bool()) {
2745+
#ifndef USE_SQLITE
2746+
throw JSONRPCError(RPC_WALLET_ERROR, "Compiled without sqlite support (required for descriptor wallets)");
2747+
#endif
27452748
flags |= WALLET_FLAG_DESCRIPTORS;
27462749
warnings.emplace_back(Untranslated("Wallet is an experimental descriptor wallet"));
27472750
}

src/wallet/walletdb.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
#include <util/time.h>
1616
#include <util/translation.h>
1717
#include <wallet/bdb.h>
18+
#ifdef USE_SQLITE
1819
#include <wallet/sqlite.h>
20+
#endif
1921
#include <wallet/wallet.h>
2022

2123
#include <atomic>
@@ -1012,6 +1014,7 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
10121014
if (ExistsBerkeleyDatabase(path)) {
10131015
format = DatabaseFormat::BERKELEY;
10141016
}
1017+
#ifdef USE_SQLITE
10151018
if (ExistsSQLiteDatabase(path)) {
10161019
if (format) {
10171020
error = Untranslated(strprintf("Failed to load database path '%s'. Data is in ambiguous format.", path.string()));
@@ -1020,6 +1023,7 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
10201023
}
10211024
format = DatabaseFormat::SQLITE;
10221025
}
1026+
#endif
10231027
} else if (options.require_existing) {
10241028
error = Untranslated(strprintf("Failed to load database path '%s'. Path does not exist.", path.string()));
10251029
status = DatabaseStatus::FAILED_NOT_FOUND;
@@ -1048,9 +1052,13 @@ std::unique_ptr<WalletDatabase> MakeDatabase(const fs::path& path, const Databas
10481052
// Format is not set when a db doesn't already exist, so use the format specified by the options if it is set.
10491053
if (!format && options.require_format) format = options.require_format;
10501054

1055+
#ifdef USE_SQLITE
10511056
if (format && format == DatabaseFormat::SQLITE) {
10521057
return MakeSQLiteDatabase(path, options, status, error);
10531058
}
1059+
#else
1060+
assert(format != DatabaseFormat::SQLITE);
1061+
#endif
10541062

10551063
return MakeBerkeleyDatabase(path, options, status, error);
10561064
}

src/wallet/walletutil.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#include <util/system.h>
99

1010
bool ExistsBerkeleyDatabase(const fs::path& path);
11+
#ifdef USE_SQLITE
1112
bool ExistsSQLiteDatabase(const fs::path& path);
13+
#else
14+
# define ExistsSQLiteDatabase(path) (false)
15+
#endif
1216

1317
fs::path GetWalletDir()
1418
{

0 commit comments

Comments
 (0)