mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
Merge 0577b4d9de
into 7530f3d245
This commit is contained in:
commit
d70fba8e22
@ -556,7 +556,7 @@ public:
|
|||||||
peer.is_outbound ? "out" : "in",
|
peer.is_outbound ? "out" : "in",
|
||||||
ConnectionTypeForNetinfo(peer.conn_type),
|
ConnectionTypeForNetinfo(peer.conn_type),
|
||||||
peer.network,
|
peer.network,
|
||||||
peer.transport_protocol_type.rfind('v', 0) == 0 ? peer.transport_protocol_type[1] : ' ',
|
peer.transport_protocol_type.starts_with('v') == 0 ? peer.transport_protocol_type[1] : ' ',
|
||||||
PingTimeToString(peer.min_ping),
|
PingTimeToString(peer.min_ping),
|
||||||
PingTimeToString(peer.ping),
|
PingTimeToString(peer.ping),
|
||||||
peer.last_send ? ToString(time_now - peer.last_send) : "",
|
peer.last_send ? ToString(time_now - peer.last_send) : "",
|
||||||
|
13
src/net.cpp
13
src/net.cpp
@ -1120,16 +1120,9 @@ constexpr std::array<std::string_view, 256> V2ShortIDs() {
|
|||||||
static_assert(std::size(V2_DASH_IDS) <= 128);
|
static_assert(std::size(V2_DASH_IDS) <= 128);
|
||||||
|
|
||||||
std::array<std::string_view, 256> ret{};
|
std::array<std::string_view, 256> ret{};
|
||||||
for (size_t idx{0}; idx < std::size(ret); idx++) {
|
std::fill(ret.begin(), ret.end(), "");
|
||||||
if (idx < 128 && idx < std::size(V2_BITCOIN_IDS)) {
|
std::copy(V2_BITCOIN_IDS.begin(), V2_BITCOIN_IDS.end(), ret.begin());
|
||||||
ret[idx] = V2_BITCOIN_IDS[idx];
|
std::copy(V2_DASH_IDS.begin(), V2_DASH_IDS.end(), ret.begin() + 128);
|
||||||
} else if (idx >= 128 && idx - 128 < std::size(V2_DASH_IDS)) {
|
|
||||||
ret[idx] = V2_DASH_IDS[idx - 128];
|
|
||||||
} else {
|
|
||||||
ret[idx] = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,9 +357,7 @@ FUZZ_TARGET_INIT(rpc, initialize_rpc)
|
|||||||
rpc_testing_setup->CallRPC(rpc_command, arguments);
|
rpc_testing_setup->CallRPC(rpc_command, arguments);
|
||||||
} catch (const UniValue& json_rpc_error) {
|
} catch (const UniValue& json_rpc_error) {
|
||||||
const std::string error_msg{find_value(json_rpc_error, "message").get_str()};
|
const std::string error_msg{find_value(json_rpc_error, "message").get_str()};
|
||||||
// Once c++20 is allowed, starts_with can be used.
|
if (error_msg.starts_with("Internal bug detected")) {
|
||||||
// if (error_msg.starts_with("Internal bug detected")) {
|
|
||||||
if (0 == error_msg.rfind("Internal bug detected", 0)) {
|
|
||||||
// Only allow the intentional internal bug
|
// Only allow the intentional internal bug
|
||||||
assert(error_msg.find("trigger_internal_bug") != std::string::npos);
|
assert(error_msg.find("trigger_internal_bug") != std::string::npos);
|
||||||
}
|
}
|
||||||
|
@ -5,40 +5,20 @@
|
|||||||
#ifndef BITCOIN_UTIL_RANGES_H
|
#ifndef BITCOIN_UTIL_RANGES_H
|
||||||
#define BITCOIN_UTIL_RANGES_H
|
#define BITCOIN_UTIL_RANGES_H
|
||||||
|
|
||||||
#include <algorithm>
|
#include <ranges>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
//#if __cplusplus > 201703L // C++20 compiler
|
|
||||||
//namespace ranges = std::ranges;
|
|
||||||
//#else
|
|
||||||
|
|
||||||
#define MK_RANGE(FUN) \
|
|
||||||
template <typename X, typename Z> \
|
|
||||||
inline auto FUN(const X& ds, const Z& fn) { \
|
|
||||||
return std::FUN(cbegin(ds), cend(ds), fn); \
|
|
||||||
} \
|
|
||||||
template <typename X, typename Z> \
|
|
||||||
inline auto FUN(X& ds, const Z& fn) { \
|
|
||||||
return std::FUN(begin(ds), end(ds), fn); \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace ranges {
|
namespace ranges {
|
||||||
MK_RANGE(all_of)
|
using namespace std::ranges;
|
||||||
MK_RANGE(any_of)
|
|
||||||
MK_RANGE(count_if)
|
|
||||||
MK_RANGE(find_if)
|
|
||||||
|
|
||||||
template <typename X, typename Z>
|
template <typename X, typename Z>
|
||||||
constexpr inline auto find_if_opt(const X& ds, const Z& fn) {
|
constexpr inline auto find_if_opt(const X& ds, const Z& fn) {
|
||||||
const auto it = ranges::find_if(ds, fn);
|
const auto it = std::ranges::find_if(ds, fn);
|
||||||
if (it != end(ds)) {
|
if (it != std::end(ds)) {
|
||||||
return std::make_optional(*it);
|
return std::make_optional(*it);
|
||||||
}
|
}
|
||||||
return std::optional<std::decay_t<decltype(*it)>>{};
|
return std::optional<std::decay_t<decltype(*it)>>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//#endif // C++20 compiler
|
|
||||||
#endif // BITCOIN_UTIL_RANGES_H
|
#endif // BITCOIN_UTIL_RANGES_H
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <policy/settings.h>
|
#include <policy/settings.h>
|
||||||
#include <primitives/block.h>
|
#include <primitives/block.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
|
#include <reverse_iterator.h>
|
||||||
#include <script/descriptor.h>
|
#include <script/descriptor.h>
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
@ -5324,44 +5325,29 @@ bool CWallet::AutoBackupWallet(const fs::path& wallet_path, bilingual_str& error
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Keep only the last 10 backups, including the new one of course
|
// Keep only the last 10 backups, including the new one of course
|
||||||
typedef std::multimap<std::time_t, fs::path> folder_set_t;
|
std::multimap<fs::file_time_type, fs::path> folder_set;
|
||||||
folder_set_t folder_set;
|
|
||||||
fs::directory_iterator end_iter;
|
|
||||||
// Build map of backup files for current(!) wallet sorted by last write time
|
// Build map of backup files for current(!) wallet sorted by last write time
|
||||||
fs::path currentFile;
|
fs::path currentFile;
|
||||||
for (fs::directory_iterator dir_iter(backupsDir); dir_iter != end_iter; ++dir_iter)
|
for (const auto& entry : fs::directory_iterator(backupsDir)) {
|
||||||
{
|
|
||||||
// Only check regular files
|
// Only check regular files
|
||||||
if ( fs::is_regular_file(dir_iter->status()))
|
if (entry.is_regular_file()) {
|
||||||
{
|
currentFile = entry.path().filename();
|
||||||
currentFile = dir_iter->path().filename();
|
|
||||||
// Only add the backups for the current wallet, e.g. wallet.dat.*
|
// Only add the backups for the current wallet, e.g. wallet.dat.*
|
||||||
if (fs::PathToString(dir_iter->path().stem()) == strWalletName) {
|
if (fs::PathToString(entry.path().stem()) == strWalletName) {
|
||||||
folder_set.insert(folder_set_t::value_type(
|
folder_set.insert(decltype(folder_set)::value_type(fs::last_write_time(entry.path()), entry));
|
||||||
// TODO: C++17 compliant time conversion code is abominable, switch to C++20
|
|
||||||
// compliant code when C++17 support is dropped
|
|
||||||
std::chrono::system_clock::to_time_t(
|
|
||||||
std::chrono::time_point_cast<std::chrono::system_clock::duration>(
|
|
||||||
fs::last_write_time(dir_iter->path()) - fs::file_time_type::clock::now() + std::chrono::system_clock::now()
|
|
||||||
)
|
|
||||||
),
|
|
||||||
*dir_iter
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop backward through backup files and keep the N newest ones (1 <= N <= 10)
|
// Loop backward through backup files and keep the N newest ones (1 <= N <= 10)
|
||||||
int counter = 0;
|
int counter{0};
|
||||||
for(auto it = folder_set.rbegin(); it != folder_set.rend(); ++it) {
|
for (const auto& [entry_time, entry] : reverse_iterate(folder_set)) {
|
||||||
std::pair<const std::time_t, fs::path> file = *it;
|
|
||||||
counter++;
|
counter++;
|
||||||
if (counter > nWalletBackups)
|
if (counter > nWalletBackups) {
|
||||||
{
|
|
||||||
// More than nWalletBackups backups: delete oldest one(s)
|
// More than nWalletBackups backups: delete oldest one(s)
|
||||||
try {
|
try {
|
||||||
fs::remove(file.second);
|
fs::remove(entry);
|
||||||
WalletLogPrintf("Old backup deleted: %s\n", fs::PathToString(file.second));
|
WalletLogPrintf("Old backup deleted: %s\n", fs::PathToString(entry));
|
||||||
} catch(fs::filesystem_error &error) {
|
} catch(fs::filesystem_error &error) {
|
||||||
warnings.push_back(strprintf(_("Failed to delete backup, error: %s"), fsbridge::get_filesystem_error_message(error)));
|
warnings.push_back(strprintf(_("Failed to delete backup, error: %s"), fsbridge::get_filesystem_error_message(error)));
|
||||||
WalletLogPrintf("%s\n", Join(warnings, Untranslated("\n")).original);
|
WalletLogPrintf("%s\n", Join(warnings, Untranslated("\n")).original);
|
||||||
|
Loading…
Reference in New Issue
Block a user