Skip to content
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

backport: merge bitcoin#23065, #23498, #23557, #23736, #23855, #24403, #24968, #24933, #25358, #27823, #28253, #28612 (auxiliary backports: part 22) #6530

Merged
merged 14 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1974,16 +1974,16 @@ echo " boost process = $with_boost_process"
echo " multiprocess = $build_multiprocess"
echo " with libs = $build_bitcoin_libs"
echo " with wallet = $enable_wallet"
echo " with gui / qt = $bitcoin_enable_qt"
if test "x$enable_wallet" != "xno"; then
echo " with sqlite = $use_sqlite"
echo " with bdb = $use_bdb"
echo " with sqlite = $use_sqlite"
echo " with bdb = $use_bdb"
fi
echo " with gui / qt = $bitcoin_enable_qt"
if test x$bitcoin_enable_qt != xno; then
echo " with qr = $use_qr"
fi
echo " with zmq = $use_zmq"
if test x$enable_fuzz == xno; then
if test x$enable_fuzz = xno; then
echo " with test = $use_tests"
else
echo " with test = not building test_dash because fuzzing is enabled"
Expand Down
15 changes: 15 additions & 0 deletions doc/release-notes-6530.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Notable changes
===============

Updated RPCs
------------

- `lockunspent` now optionally takes a third parameter, `persistent`, which
causes the lock to be written persistently to the wallet database. This
allows UTXOs to remain locked even after node restarts or crashes.

GUI changes
-----------

- UTXOs which are locked via the GUI are now stored persistently in the
wallet database, so are not lost on node shutdown or crash.
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ BITCOIN_CORE_H = \
util/sock.h \
util/string.h \
util/spanparsing.h \
util/syserror.h \
util/system.h \
util/time.h \
util/thread.h \
Expand Down Expand Up @@ -825,6 +826,7 @@ libbitcoin_util_a_SOURCES = \
util/hasher.cpp \
util/getuniquepath.cpp \
util/sock.cpp \
util/syserror.cpp \
util/system.cpp \
util/message.cpp \
util/moneystr.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ BITCOIN_TESTS =\
test/net_peer_eviction_tests.cpp \
test/net_tests.cpp \
test/netbase_tests.cpp \
test/orphanage_tests.cpp \
test/pmt_tests.cpp \
test/policyestimator_tests.cpp \
test/pool_tests.cpp \
Expand Down
3 changes: 2 additions & 1 deletion src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <noui.h>
#include <shutdown.h>
#include <util/check.h>
#include <util/syserror.h>
#include <util/system.h>
#include <util/strencodings.h>
#include <util/threadnames.h>
Expand Down Expand Up @@ -212,7 +213,7 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
}
break;
case -1: // Error happened.
return InitError(Untranslated(strprintf("fork_daemon() failed: %s\n", strerror(errno))));
return InitError(Untranslated(strprintf("fork_daemon() failed: %s\n", SysErrorString(errno))));
default: { // Parent: wait and exit.
int token = daemon_ep.TokenRead();
if (token) { // Success
Expand Down
3 changes: 2 additions & 1 deletion src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <fs.h>
#include <util/syserror.h>

#ifndef WIN32
#include <cstring>
Expand Down Expand Up @@ -41,7 +42,7 @@ fs::path AbsPathJoin(const fs::path& base, const fs::path& path)

static std::string GetErrorReason()
{
return std::strerror(errno);
return SysErrorString(errno);
}

FileLock::FileLock(const fs::path& file)
Expand Down
109 changes: 55 additions & 54 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include <util/moneystr.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/syserror.h>
#include <util/system.h>
#include <util/thread.h>
#include <util/threadnames.h>
Expand Down Expand Up @@ -165,7 +166,7 @@ static fs::path GetPidFile(const ArgsManager& args)
#endif
return true;
} else {
return InitError(strprintf(_("Unable to create the PID file '%s': %s"), fs::PathToString(GetPidFile(args)), std::strerror(errno)));
return InitError(strprintf(_("Unable to create the PID file '%s': %s"), fs::PathToString(GetPidFile(args)), SysErrorString(errno)));
}
}

Expand Down Expand Up @@ -1833,48 +1834,48 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)

uiInterface.InitMessage(_("Loading block index…").translated);
const auto load_block_index_start_time{SteadyClock::now()};
std::optional<ChainstateLoadingError> rv;
std::optional<ChainstateLoadingError> maybe_load_error;
try {
rv = LoadChainstate(fReset,
chainman,
*node.govman,
*node.mn_metaman,
*node.mn_sync,
*node.sporkman,
node.mn_activeman,
node.chain_helper,
node.cpoolman,
node.dmnman,
node.evodb,
node.mnhf_manager,
node.llmq_ctx,
Assert(node.mempool.get()),
fPruneMode,
args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
is_governance_enabled,
args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX),
args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
args.GetBoolArg("-txindex", DEFAULT_TXINDEX),
chainparams.GetConsensus(),
chainparams.NetworkIDString(),
fReindexChainState,
cache_sizes.block_tree_db,
cache_sizes.coins_db,
cache_sizes.coins,
/*block_tree_db_in_memory=*/false,
/*coins_db_in_memory=*/false,
ShutdownRequested,
[]() {
uiInterface.ThreadSafeMessageBox(
_("Error reading from database, shutting down."),
"", CClientUIInterface::MSG_ERROR);
});
maybe_load_error = LoadChainstate(fReset,
chainman,
*node.govman,
*node.mn_metaman,
*node.mn_sync,
*node.sporkman,
node.mn_activeman,
node.chain_helper,
node.cpoolman,
node.dmnman,
node.evodb,
node.mnhf_manager,
node.llmq_ctx,
Assert(node.mempool.get()),
fPruneMode,
args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
is_governance_enabled,
args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX),
args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
args.GetBoolArg("-txindex", DEFAULT_TXINDEX),
chainparams.GetConsensus(),
chainparams.NetworkIDString(),
fReindexChainState,
cache_sizes.block_tree_db,
cache_sizes.coins_db,
cache_sizes.coins,
/*block_tree_db_in_memory=*/false,
/*coins_db_in_memory=*/false,
/*shutdown_requested=*/ShutdownRequested,
/*coins_error_cb=*/[]() {
uiInterface.ThreadSafeMessageBox(
_("Error reading from database, shutting down."),
"", CClientUIInterface::MSG_ERROR);
});
} catch (const std::exception& e) {
LogPrintf("%s\n", e.what());
rv = ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
maybe_load_error = ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
}
if (rv.has_value()) {
switch (rv.value()) {
if (maybe_load_error.has_value()) {
switch (maybe_load_error.value()) {
case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:
strLoadError = _("Error loading block database");
break;
Expand Down Expand Up @@ -1930,31 +1931,31 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
LogPrintf("%s: timestamp index %s\n", __func__, fTimestampIndex ? "enabled" : "disabled");
LogPrintf("%s: spent index %s\n", __func__, fSpentIndex ? "enabled" : "disabled");

std::optional<ChainstateLoadVerifyError> rv2;
std::optional<ChainstateLoadVerifyError> maybe_verify_error;
try {
uiInterface.InitMessage(_("Verifying blocks…").translated);
auto check_blocks = args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS);
if (chainman.m_blockman.m_have_pruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n",
MIN_BLOCKS_TO_KEEP);
}
rv2 = VerifyLoadedChainstate(chainman,
*Assert(node.evodb.get()),
fReset,
fReindexChainState,
chainparams.GetConsensus(),
check_blocks,
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
static_cast<int64_t(*)()>(GetTime),
[](bool bls_state) {
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls_state);
});
maybe_verify_error = VerifyLoadedChainstate(chainman,
*Assert(node.evodb.get()),
fReset,
fReindexChainState,
chainparams.GetConsensus(),
check_blocks,
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
/*get_unix_time_seconds=*/static_cast<int64_t(*)()>(GetTime),
[](bool bls_state) {
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls_state);
});
} catch (const std::exception& e) {
LogPrintf("%s\n", e.what());
rv2 = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE;
maybe_verify_error = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE;
}
if (rv2.has_value()) {
switch (rv2.value()) {
if (maybe_verify_error.has_value()) {
switch (maybe_verify_error.value()) {
case ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE:
strLoadError = _("The block database contains a block which appears to be from the future. "
"This may be due to your computer's date and time being set incorrectly. "
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ class Wallet
virtual bool setAddressReceiveRequest(const CTxDestination& dest, const std::string& id, const std::string& value) = 0;

//! Lock coin.
virtual void lockCoin(const COutPoint& output) = 0;
virtual bool lockCoin(const COutPoint& output, const bool write_to_db) = 0;

//! Unlock coin.
virtual void unlockCoin(const COutPoint& output) = 0;
virtual bool unlockCoin(const COutPoint& output) = 0;

//! Return whether coin is locked.
virtual bool isLockedCoin(const COutPoint& output) = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/node/blockstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,13 @@ bool BlockManager::LoadBlockIndex(const Consensus::Params& consensus_params)
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
CBlockIndexHeightOnlyComparator());

CBlockIndex* previous_index{nullptr};
for (CBlockIndex* pindex : vSortedByHeight) {
if (ShutdownRequested()) return false;
if (previous_index && pindex->nHeight > previous_index->nHeight + 1) {
return error("%s: block index is non-contiguous, index of height %d missing", __func__, previous_index->nHeight + 1);
}
previous_index = pindex;
pindex->nChainWork = (pindex->pprev ? pindex->pprev->nChainWork : 0) + GetBlockProof(*pindex);
pindex->nTimeMax = (pindex->pprev ? std::max(pindex->pprev->nTimeMax, pindex->nTime) : pindex->nTime);

Expand Down
6 changes: 3 additions & 3 deletions src/node/chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
bool fReset,
bool fReindexChainState,
const Consensus::Params& consensus_params,
unsigned int check_blocks,
unsigned int check_level,
int check_blocks,
int check_level,
std::function<int64_t()> get_unix_time_seconds,
std::function<void(bool)> notify_bls_state)
{
Expand All @@ -275,7 +275,7 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
for (CChainState* chainstate : chainman.GetAll()) {
if (!is_coinsview_empty(chainstate)) {
const CBlockIndex* tip = chainstate->m_chain.Tip();
if (tip && tip->nTime > get_unix_time_seconds() + 2 * 60 * 60) {
if (tip && tip->nTime > get_unix_time_seconds() + MAX_FUTURE_BLOCK_TIME) {
return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE;
}
const bool v19active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V19)};
Expand Down
6 changes: 3 additions & 3 deletions src/node/chainstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ enum class ChainstateLoadingError {
* this sequence, when we explicitly checked shutdown_requested() at
* arbitrary points, one of those calls returned true". Therefore, a
* return value other than SHUTDOWN_PROBED does not guarantee that
* shutdown_requested() hasn't been called indirectly.
* shutdown hasn't been called indirectly.
* - else
* - Success!
*/
Expand Down Expand Up @@ -143,8 +143,8 @@ std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManage
bool fReset,
bool fReindexChainState,
const Consensus::Params& consensus_params,
unsigned int check_blocks,
unsigned int check_level,
int check_blocks,
int check_level,
std::function<int64_t()> get_unix_time_seconds,
std::function<void(bool)> notify_bls_state = nullptr);

Expand Down
4 changes: 2 additions & 2 deletions src/qt/coincontroldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void CoinControlDialog::buttonToggleLockClicked()
item->setIcon(COLUMN_CHECKBOX, QIcon());
}
else{
model->wallet().lockCoin(outpt);
model->wallet().lockCoin(outpt, /*write_to_db=*/true);
item->setDisabled(true);
item->setIcon(COLUMN_CHECKBOX, GUIUtil::getIcon("lock_closed", GUIUtil::ThemedColor::RED));
}
Expand Down Expand Up @@ -300,7 +300,7 @@ void CoinControlDialog::lockCoin()
contextMenuItem->setCheckState(COLUMN_CHECKBOX, Qt::Unchecked);

COutPoint outpt(uint256S(contextMenuItem->data(COLUMN_ADDRESS, TxHashRole).toString().toStdString()), contextMenuItem->data(COLUMN_ADDRESS, VOutRole).toUInt());
model->wallet().lockCoin(outpt);
model->wallet().lockCoin(outpt, /*write_to_db=*/true);
contextMenuItem->setDisabled(true);
contextMenuItem->setIcon(COLUMN_CHECKBOX, GUIUtil::getIcon("lock_closed", GUIUtil::ThemedColor::RED));
updateLabelLocked();
Expand Down
1 change: 1 addition & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "gettxoutsetinfo", 2, "use_index"},
{ "lockunspent", 0, "unlock" },
{ "lockunspent", 1, "transactions" },
{ "lockunspent", 2, "persistent" },
{ "send", 0, "outputs" },
{ "send", 1, "conf_target" },
{ "send", 3, "fee_rate"},
Expand Down
Loading
Loading