mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 11:32:46 +01:00
Compare commits
44 Commits
c164096a55
...
12d2eb5b6d
Author | SHA1 | Date | |
---|---|---|---|
|
12d2eb5b6d | ||
|
dd96032e12 | ||
|
a5d54006b3 | ||
|
3bbe16c390 | ||
|
43043e623f | ||
|
efd5c566da | ||
|
257fd5ef9e | ||
|
19746513b1 | ||
|
04dbaa8bd8 | ||
|
872158d248 | ||
|
09ab62948f | ||
|
459f33983b | ||
|
c06e07461e | ||
|
52bb35d9c8 | ||
|
4ab182751e | ||
|
d7f1e234c5 | ||
|
c405492874 | ||
|
fdf803d013 | ||
|
f7aef8d331 | ||
|
94c0ceb29c | ||
|
d3345eeccc | ||
|
a141f5d9a7 | ||
|
913411ed73 | ||
|
53231ca29d | ||
|
2ea1bbc7aa | ||
|
29c736280d | ||
|
7071282a2d | ||
|
ee9d3dd5fc | ||
|
d7419e42d6 | ||
|
9ab08c42e4 | ||
|
2455c06464 | ||
|
620146bcb8 | ||
|
86c88977ba | ||
|
a34937df51 | ||
|
d00f8a1316 | ||
|
3910a7547f | ||
|
67b0621edf | ||
|
d85003a7af | ||
|
a1becc2ef3 | ||
|
d2a2713ceb | ||
|
b112911d6c | ||
|
8283396d4c | ||
|
9d8fa38965 | ||
|
1a630ba785 |
14
configure.ac
14
configure.ac
@ -1053,7 +1053,7 @@ if test x$TARGET_OS = xdarwin; then
|
||||
AX_CHECK_LINK_FLAG([[-Wl,-fixup_chains]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,-fixup_chains"], [], [[$LDFLAG_WERROR]])
|
||||
fi
|
||||
|
||||
AC_CHECK_HEADERS([endian.h sys/endian.h byteswap.h stdio.h stdlib.h unistd.h strings.h sys/types.h sys/stat.h sys/select.h sys/prctl.h sys/sysctl.h vm/vm_param.h sys/vmmeter.h sys/resources.h])
|
||||
AC_CHECK_HEADERS([sys/select.h sys/prctl.h sys/sysctl.h vm/vm_param.h sys/vmmeter.h sys/resources.h])
|
||||
|
||||
AC_CHECK_DECLS([getifaddrs, freeifaddrs],[CHECK_SOCKET],,
|
||||
[#include <sys/types.h>
|
||||
@ -1068,18 +1068,6 @@ AC_CHECK_DECLS([pipe2])
|
||||
|
||||
AC_CHECK_FUNCS([timingsafe_bcmp])
|
||||
|
||||
AC_CHECK_DECLS([le16toh, le32toh, le64toh, htole16, htole32, htole64, be16toh, be32toh, be64toh, htobe16, htobe32, htobe64],,,
|
||||
[#if HAVE_ENDIAN_H
|
||||
#include <endian.h>
|
||||
#elif HAVE_SYS_ENDIAN_H
|
||||
#include <sys/endian.h>
|
||||
#endif])
|
||||
|
||||
AC_CHECK_DECLS([bswap_16, bswap_32, bswap_64],,,
|
||||
[#if HAVE_BYTESWAP_H
|
||||
#include <byteswap.h>
|
||||
#endif])
|
||||
|
||||
dnl Check for mallopt(M_ARENA_MAX) (to set glibc arenas)
|
||||
AC_MSG_CHECKING(for mallopt M_ARENA_MAX)
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <malloc.h>]],
|
||||
|
@ -270,6 +270,8 @@ BITCOIN_CORE_H = \
|
||||
netgroup.h \
|
||||
netmessagemaker.h \
|
||||
node/blockstorage.h \
|
||||
node/caches.h \
|
||||
node/chainstate.h \
|
||||
node/coin.h \
|
||||
node/coinstats.h \
|
||||
node/connection_types.h \
|
||||
@ -502,6 +504,8 @@ libbitcoin_server_a_SOURCES = \
|
||||
netgroup.cpp \
|
||||
net_processing.cpp \
|
||||
node/blockstorage.cpp \
|
||||
node/caches.cpp \
|
||||
node/chainstate.cpp \
|
||||
node/coin.cpp \
|
||||
node/coinstats.cpp \
|
||||
node/connection_types.cpp \
|
||||
|
@ -73,6 +73,7 @@ endif
|
||||
|
||||
# test_dash binary #
|
||||
BITCOIN_TESTS =\
|
||||
test/argsman_tests.cpp \
|
||||
test/arith_uint256_tests.cpp \
|
||||
test/scriptnum10.h \
|
||||
test/addrman_tests.cpp \
|
||||
|
@ -17,12 +17,12 @@ static void EllSwiftCreate(benchmark::Bench& bench)
|
||||
uint256 entropy = GetRandHash();
|
||||
|
||||
bench.batch(1).unit("pubkey").run([&] {
|
||||
auto ret = key.EllSwiftCreate(AsBytes(Span{entropy}));
|
||||
auto ret = key.EllSwiftCreate(MakeByteSpan(entropy));
|
||||
/* Use the first 32 bytes of the ellswift encoded public key as next private key. */
|
||||
key.Set(UCharCast(ret.data()), UCharCast(ret.data()) + 32, true);
|
||||
assert(key.IsValid());
|
||||
/* Use the last 32 bytes of the ellswift encoded public key as next entropy. */
|
||||
std::copy(ret.begin() + 32, ret.begin() + 64, BytePtr(entropy.data()));
|
||||
std::copy(ret.begin() + 32, ret.begin() + 64, MakeWritableByteSpan(entropy).begin());
|
||||
});
|
||||
|
||||
ECC_Stop();
|
||||
|
@ -26,10 +26,10 @@
|
||||
#include <util/system.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stacktraces.h>
|
||||
|
||||
|
@ -27,8 +27,8 @@
|
||||
#include <stacktraces.h>
|
||||
#include <util/url.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <functional>
|
||||
#include <stdio.h>
|
||||
|
||||
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
|
||||
UrlDecodeFn* const URL_DECODE = urlDecode;
|
||||
|
@ -5,44 +5,66 @@
|
||||
#ifndef BITCOIN_COMPAT_BYTESWAP_H
|
||||
#define BITCOIN_COMPAT_BYTESWAP_H
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config/bitcoin-config.h>
|
||||
#include <cstdint>
|
||||
#ifdef _MSC_VER
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(HAVE_BYTESWAP_H)
|
||||
#include <byteswap.h>
|
||||
// All internal_bswap_* functions can be replaced with std::byteswap once we
|
||||
// require c++23. Both libstdc++ and libc++ implement std::byteswap via these
|
||||
// builtins.
|
||||
|
||||
#ifndef DISABLE_BUILTIN_BSWAPS
|
||||
# if defined __has_builtin
|
||||
# if __has_builtin(__builtin_bswap16)
|
||||
# define bitcoin_builtin_bswap16(x) __builtin_bswap16(x)
|
||||
# endif
|
||||
# if __has_builtin(__builtin_bswap32)
|
||||
# define bitcoin_builtin_bswap32(x) __builtin_bswap32(x)
|
||||
# endif
|
||||
# if __has_builtin(__builtin_bswap64)
|
||||
# define bitcoin_builtin_bswap64(x) __builtin_bswap64(x)
|
||||
# endif
|
||||
# elif defined(_MSC_VER)
|
||||
# define bitcoin_builtin_bswap16(x) _byteswap_ushort(x)
|
||||
# define bitcoin_builtin_bswap32(x) _byteswap_ulong(x)
|
||||
# define bitcoin_builtin_bswap64(x) _byteswap_uint64(x)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(MAC_OSX)
|
||||
|
||||
#include <libkern/OSByteOrder.h>
|
||||
#define bswap_16(x) OSSwapInt16(x)
|
||||
#define bswap_32(x) OSSwapInt32(x)
|
||||
#define bswap_64(x) OSSwapInt64(x)
|
||||
// MSVC's _byteswap_* functions are not constexpr
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#define BSWAP_CONSTEXPR constexpr
|
||||
#else
|
||||
// Non-MacOS / non-Darwin
|
||||
#define BSWAP_CONSTEXPR
|
||||
#endif
|
||||
|
||||
#if HAVE_DECL_BSWAP_16 == 0
|
||||
inline uint16_t bswap_16(uint16_t x)
|
||||
inline BSWAP_CONSTEXPR uint16_t internal_bswap_16(uint16_t x)
|
||||
{
|
||||
#ifdef bitcoin_builtin_bswap16
|
||||
return bitcoin_builtin_bswap16(x);
|
||||
#else
|
||||
return (x >> 8) | (x << 8);
|
||||
#endif
|
||||
}
|
||||
#endif // HAVE_DECL_BSWAP16 == 0
|
||||
|
||||
#if HAVE_DECL_BSWAP_32 == 0
|
||||
inline uint32_t bswap_32(uint32_t x)
|
||||
inline BSWAP_CONSTEXPR uint32_t internal_bswap_32(uint32_t x)
|
||||
{
|
||||
#ifdef bitcoin_builtin_bswap32
|
||||
return bitcoin_builtin_bswap32(x);
|
||||
#else
|
||||
return (((x & 0xff000000U) >> 24) | ((x & 0x00ff0000U) >> 8) |
|
||||
((x & 0x0000ff00U) << 8) | ((x & 0x000000ffU) << 24));
|
||||
#endif
|
||||
}
|
||||
#endif // HAVE_DECL_BSWAP32 == 0
|
||||
|
||||
#if HAVE_DECL_BSWAP_64 == 0
|
||||
inline uint64_t bswap_64(uint64_t x)
|
||||
inline BSWAP_CONSTEXPR uint64_t internal_bswap_64(uint64_t x)
|
||||
{
|
||||
#ifdef bitcoin_builtin_bswap64
|
||||
return bitcoin_builtin_bswap64(x);
|
||||
#else
|
||||
return (((x & 0xff00000000000000ull) >> 56)
|
||||
| ((x & 0x00ff000000000000ull) >> 40)
|
||||
| ((x & 0x0000ff0000000000ull) >> 24)
|
||||
@ -51,9 +73,7 @@ inline uint64_t bswap_64(uint64_t x)
|
||||
| ((x & 0x0000000000ff0000ull) << 24)
|
||||
| ((x & 0x000000000000ff00ull) << 40)
|
||||
| ((x & 0x00000000000000ffull) << 56));
|
||||
#endif
|
||||
}
|
||||
#endif // HAVE_DECL_BSWAP64 == 0
|
||||
|
||||
#endif // defined(MAC_OSX)
|
||||
|
||||
#endif // BITCOIN_COMPAT_BYTESWAP_H
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include <cpuid.h>
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
// We can't use cpuid.h's __get_cpuid as it does not support subleafs.
|
||||
void static inline GetCPUID(uint32_t leaf, uint32_t subleaf, uint32_t& a, uint32_t& b, uint32_t& c, uint32_t& d)
|
||||
{
|
||||
|
@ -5,237 +5,70 @@
|
||||
#ifndef BITCOIN_COMPAT_ENDIAN_H
|
||||
#define BITCOIN_COMPAT_ENDIAN_H
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config/bitcoin-config.h>
|
||||
#endif
|
||||
|
||||
#include <compat/byteswap.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <bit>
|
||||
#include <cstdint>
|
||||
|
||||
#if defined(HAVE_ENDIAN_H)
|
||||
#include <endian.h>
|
||||
#elif defined(HAVE_SYS_ENDIAN_H)
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CONFIG_H
|
||||
// While not technically a supported configuration, defaulting to defining these
|
||||
// DECLs when we were compiled without autotools makes it easier for other build
|
||||
// systems to build things like libdashconsensus for strange targets.
|
||||
#ifdef htobe16
|
||||
#define HAVE_DECL_HTOBE16 1
|
||||
#endif
|
||||
#ifdef htole16
|
||||
#define HAVE_DECL_HTOLE16 1
|
||||
#endif
|
||||
#ifdef be16toh
|
||||
#define HAVE_DECL_BE16TOH 1
|
||||
#endif
|
||||
#ifdef le16toh
|
||||
#define HAVE_DECL_LE16TOH 1
|
||||
#endif
|
||||
|
||||
#ifdef htobe32
|
||||
#define HAVE_DECL_HTOBE32 1
|
||||
#endif
|
||||
#ifdef htole32
|
||||
#define HAVE_DECL_HTOLE32 1
|
||||
#endif
|
||||
#ifdef be32toh
|
||||
#define HAVE_DECL_BE32TOH 1
|
||||
#endif
|
||||
#ifdef le32toh
|
||||
#define HAVE_DECL_LE32TOH 1
|
||||
#endif
|
||||
|
||||
#ifdef htobe64
|
||||
#define HAVE_DECL_HTOBE64 1
|
||||
#endif
|
||||
#ifdef htole64
|
||||
#define HAVE_DECL_HTOLE64 1
|
||||
#endif
|
||||
#ifdef be64toh
|
||||
#define HAVE_DECL_BE64TOH 1
|
||||
#endif
|
||||
#ifdef le64toh
|
||||
#define HAVE_DECL_LE64TOH 1
|
||||
#endif
|
||||
|
||||
#endif // HAVE_CONFIG_H
|
||||
|
||||
#if defined(WORDS_BIGENDIAN)
|
||||
|
||||
#if HAVE_DECL_HTOBE16 == 0
|
||||
inline uint16_t htobe16(uint16_t host_16bits)
|
||||
inline BSWAP_CONSTEXPR uint16_t htobe16_internal(uint16_t host_16bits)
|
||||
{
|
||||
return host_16bits;
|
||||
if constexpr (std::endian::native == std::endian::little) return internal_bswap_16(host_16bits);
|
||||
else return host_16bits;
|
||||
}
|
||||
#endif // HAVE_DECL_HTOBE16
|
||||
|
||||
#if HAVE_DECL_HTOLE16 == 0
|
||||
inline uint16_t htole16(uint16_t host_16bits)
|
||||
inline BSWAP_CONSTEXPR uint16_t htole16_internal(uint16_t host_16bits)
|
||||
{
|
||||
return bswap_16(host_16bits);
|
||||
if constexpr (std::endian::native == std::endian::big) return internal_bswap_16(host_16bits);
|
||||
else return host_16bits;
|
||||
}
|
||||
#endif // HAVE_DECL_HTOLE16
|
||||
|
||||
#if HAVE_DECL_BE16TOH == 0
|
||||
inline uint16_t be16toh(uint16_t big_endian_16bits)
|
||||
inline BSWAP_CONSTEXPR uint16_t be16toh_internal(uint16_t big_endian_16bits)
|
||||
{
|
||||
return big_endian_16bits;
|
||||
if constexpr (std::endian::native == std::endian::little) return internal_bswap_16(big_endian_16bits);
|
||||
else return big_endian_16bits;
|
||||
}
|
||||
#endif // HAVE_DECL_BE16TOH
|
||||
|
||||
#if HAVE_DECL_LE16TOH == 0
|
||||
inline uint16_t le16toh(uint16_t little_endian_16bits)
|
||||
inline BSWAP_CONSTEXPR uint16_t le16toh_internal(uint16_t little_endian_16bits)
|
||||
{
|
||||
return bswap_16(little_endian_16bits);
|
||||
if constexpr (std::endian::native == std::endian::big) return internal_bswap_16(little_endian_16bits);
|
||||
else return little_endian_16bits;
|
||||
}
|
||||
#endif // HAVE_DECL_LE16TOH
|
||||
|
||||
#if HAVE_DECL_HTOBE32 == 0
|
||||
inline uint32_t htobe32(uint32_t host_32bits)
|
||||
inline BSWAP_CONSTEXPR uint32_t htobe32_internal(uint32_t host_32bits)
|
||||
{
|
||||
return host_32bits;
|
||||
if constexpr (std::endian::native == std::endian::little) return internal_bswap_32(host_32bits);
|
||||
else return host_32bits;
|
||||
}
|
||||
#endif // HAVE_DECL_HTOBE32
|
||||
|
||||
#if HAVE_DECL_HTOLE32 == 0
|
||||
inline uint32_t htole32(uint32_t host_32bits)
|
||||
inline BSWAP_CONSTEXPR uint32_t htole32_internal(uint32_t host_32bits)
|
||||
{
|
||||
return bswap_32(host_32bits);
|
||||
if constexpr (std::endian::native == std::endian::big) return internal_bswap_32(host_32bits);
|
||||
else return host_32bits;
|
||||
}
|
||||
#endif // HAVE_DECL_HTOLE32
|
||||
|
||||
#if HAVE_DECL_BE32TOH == 0
|
||||
inline uint32_t be32toh(uint32_t big_endian_32bits)
|
||||
inline BSWAP_CONSTEXPR uint32_t be32toh_internal(uint32_t big_endian_32bits)
|
||||
{
|
||||
return big_endian_32bits;
|
||||
if constexpr (std::endian::native == std::endian::little) return internal_bswap_32(big_endian_32bits);
|
||||
else return big_endian_32bits;
|
||||
}
|
||||
#endif // HAVE_DECL_BE32TOH
|
||||
|
||||
#if HAVE_DECL_LE32TOH == 0
|
||||
inline uint32_t le32toh(uint32_t little_endian_32bits)
|
||||
inline BSWAP_CONSTEXPR uint32_t le32toh_internal(uint32_t little_endian_32bits)
|
||||
{
|
||||
return bswap_32(little_endian_32bits);
|
||||
if constexpr (std::endian::native == std::endian::big) return internal_bswap_32(little_endian_32bits);
|
||||
else return little_endian_32bits;
|
||||
}
|
||||
#endif // HAVE_DECL_LE32TOH
|
||||
|
||||
#if HAVE_DECL_HTOBE64 == 0
|
||||
inline uint64_t htobe64(uint64_t host_64bits)
|
||||
inline BSWAP_CONSTEXPR uint64_t htobe64_internal(uint64_t host_64bits)
|
||||
{
|
||||
return host_64bits;
|
||||
if constexpr (std::endian::native == std::endian::little) return internal_bswap_64(host_64bits);
|
||||
else return host_64bits;
|
||||
}
|
||||
#endif // HAVE_DECL_HTOBE64
|
||||
|
||||
#if HAVE_DECL_HTOLE64 == 0
|
||||
inline uint64_t htole64(uint64_t host_64bits)
|
||||
inline BSWAP_CONSTEXPR uint64_t htole64_internal(uint64_t host_64bits)
|
||||
{
|
||||
return bswap_64(host_64bits);
|
||||
if constexpr (std::endian::native == std::endian::big) return internal_bswap_64(host_64bits);
|
||||
else return host_64bits;
|
||||
}
|
||||
#endif // HAVE_DECL_HTOLE64
|
||||
|
||||
#if HAVE_DECL_BE64TOH == 0
|
||||
inline uint64_t be64toh(uint64_t big_endian_64bits)
|
||||
inline BSWAP_CONSTEXPR uint64_t be64toh_internal(uint64_t big_endian_64bits)
|
||||
{
|
||||
return big_endian_64bits;
|
||||
if constexpr (std::endian::native == std::endian::little) return internal_bswap_64(big_endian_64bits);
|
||||
else return big_endian_64bits;
|
||||
}
|
||||
#endif // HAVE_DECL_BE64TOH
|
||||
|
||||
#if HAVE_DECL_LE64TOH == 0
|
||||
inline uint64_t le64toh(uint64_t little_endian_64bits)
|
||||
inline BSWAP_CONSTEXPR uint64_t le64toh_internal(uint64_t little_endian_64bits)
|
||||
{
|
||||
return bswap_64(little_endian_64bits);
|
||||
if constexpr (std::endian::native == std::endian::big) return internal_bswap_64(little_endian_64bits);
|
||||
else return little_endian_64bits;
|
||||
}
|
||||
#endif // HAVE_DECL_LE64TOH
|
||||
|
||||
#else // WORDS_BIGENDIAN
|
||||
|
||||
#if HAVE_DECL_HTOBE16 == 0
|
||||
inline uint16_t htobe16(uint16_t host_16bits)
|
||||
{
|
||||
return bswap_16(host_16bits);
|
||||
}
|
||||
#endif // HAVE_DECL_HTOBE16
|
||||
|
||||
#if HAVE_DECL_HTOLE16 == 0
|
||||
inline uint16_t htole16(uint16_t host_16bits)
|
||||
{
|
||||
return host_16bits;
|
||||
}
|
||||
#endif // HAVE_DECL_HTOLE16
|
||||
|
||||
#if HAVE_DECL_BE16TOH == 0
|
||||
inline uint16_t be16toh(uint16_t big_endian_16bits)
|
||||
{
|
||||
return bswap_16(big_endian_16bits);
|
||||
}
|
||||
#endif // HAVE_DECL_BE16TOH
|
||||
|
||||
#if HAVE_DECL_LE16TOH == 0
|
||||
inline uint16_t le16toh(uint16_t little_endian_16bits)
|
||||
{
|
||||
return little_endian_16bits;
|
||||
}
|
||||
#endif // HAVE_DECL_LE16TOH
|
||||
|
||||
#if HAVE_DECL_HTOBE32 == 0
|
||||
inline uint32_t htobe32(uint32_t host_32bits)
|
||||
{
|
||||
return bswap_32(host_32bits);
|
||||
}
|
||||
#endif // HAVE_DECL_HTOBE32
|
||||
|
||||
#if HAVE_DECL_HTOLE32 == 0
|
||||
inline uint32_t htole32(uint32_t host_32bits)
|
||||
{
|
||||
return host_32bits;
|
||||
}
|
||||
#endif // HAVE_DECL_HTOLE32
|
||||
|
||||
#if HAVE_DECL_BE32TOH == 0
|
||||
inline uint32_t be32toh(uint32_t big_endian_32bits)
|
||||
{
|
||||
return bswap_32(big_endian_32bits);
|
||||
}
|
||||
#endif // HAVE_DECL_BE32TOH
|
||||
|
||||
#if HAVE_DECL_LE32TOH == 0
|
||||
inline uint32_t le32toh(uint32_t little_endian_32bits)
|
||||
{
|
||||
return little_endian_32bits;
|
||||
}
|
||||
#endif // HAVE_DECL_LE32TOH
|
||||
|
||||
#if HAVE_DECL_HTOBE64 == 0
|
||||
inline uint64_t htobe64(uint64_t host_64bits)
|
||||
{
|
||||
return bswap_64(host_64bits);
|
||||
}
|
||||
#endif // HAVE_DECL_HTOBE64
|
||||
|
||||
#if HAVE_DECL_HTOLE64 == 0
|
||||
inline uint64_t htole64(uint64_t host_64bits)
|
||||
{
|
||||
return host_64bits;
|
||||
}
|
||||
#endif // HAVE_DECL_HTOLE64
|
||||
|
||||
#if HAVE_DECL_BE64TOH == 0
|
||||
inline uint64_t be64toh(uint64_t big_endian_64bits)
|
||||
{
|
||||
return bswap_64(big_endian_64bits);
|
||||
}
|
||||
#endif // HAVE_DECL_BE64TOH
|
||||
|
||||
#if HAVE_DECL_LE64TOH == 0
|
||||
inline uint64_t le64toh(uint64_t little_endian_64bits)
|
||||
{
|
||||
return little_endian_64bits;
|
||||
}
|
||||
#endif // HAVE_DECL_LE64TOH
|
||||
|
||||
#endif // WORDS_BIGENDIAN
|
||||
|
||||
#endif // BITCOIN_COMPAT_ENDIAN_H
|
||||
|
@ -2,23 +2,19 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config/bitcoin-config.h>
|
||||
#endif
|
||||
#include <compat/stdin.h>
|
||||
|
||||
#include <cstdio> // for fileno(), stdin
|
||||
#include <cstdio>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h> // for SetStdinEcho()
|
||||
#include <io.h> // for isatty()
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <termios.h> // for SetStdinEcho()
|
||||
#include <unistd.h> // for SetStdinEcho(), isatty()
|
||||
#include <poll.h> // for StdinReady()
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#include <compat/stdin.h>
|
||||
|
||||
// https://stackoverflow.com/questions/1413445/reading-a-password-from-stdcin
|
||||
void SetStdinEcho(bool enable)
|
||||
{
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <utility>
|
||||
|
||||
// classes for ChaCha20 256-bit stream cipher developed by Daniel J. Bernstein
|
||||
|
@ -5,106 +5,81 @@
|
||||
#ifndef BITCOIN_CRYPTO_COMMON_H
|
||||
#define BITCOIN_CRYPTO_COMMON_H
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
#include <config/bitcoin-config.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <compat/endian.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
uint16_t static inline ReadLE16(const unsigned char* ptr)
|
||||
{
|
||||
uint16_t x;
|
||||
memcpy((char*)&x, ptr, 2);
|
||||
return le16toh(x);
|
||||
memcpy(&x, ptr, 2);
|
||||
return le16toh_internal(x);
|
||||
}
|
||||
|
||||
uint32_t static inline ReadLE32(const unsigned char* ptr)
|
||||
{
|
||||
uint32_t x;
|
||||
memcpy((char*)&x, ptr, 4);
|
||||
return le32toh(x);
|
||||
memcpy(&x, ptr, 4);
|
||||
return le32toh_internal(x);
|
||||
}
|
||||
|
||||
uint64_t static inline ReadLE64(const unsigned char* ptr)
|
||||
{
|
||||
uint64_t x;
|
||||
memcpy((char*)&x, ptr, 8);
|
||||
return le64toh(x);
|
||||
memcpy(&x, ptr, 8);
|
||||
return le64toh_internal(x);
|
||||
}
|
||||
|
||||
void static inline WriteLE16(unsigned char* ptr, uint16_t x)
|
||||
{
|
||||
uint16_t v = htole16(x);
|
||||
memcpy(ptr, (char*)&v, 2);
|
||||
uint16_t v = htole16_internal(x);
|
||||
memcpy(ptr, &v, 2);
|
||||
}
|
||||
|
||||
void static inline WriteLE32(unsigned char* ptr, uint32_t x)
|
||||
{
|
||||
uint32_t v = htole32(x);
|
||||
memcpy(ptr, (char*)&v, 4);
|
||||
uint32_t v = htole32_internal(x);
|
||||
memcpy(ptr, &v, 4);
|
||||
}
|
||||
|
||||
void static inline WriteLE64(unsigned char* ptr, uint64_t x)
|
||||
{
|
||||
uint64_t v = htole64(x);
|
||||
memcpy(ptr, (char*)&v, 8);
|
||||
uint64_t v = htole64_internal(x);
|
||||
memcpy(ptr, &v, 8);
|
||||
}
|
||||
|
||||
uint16_t static inline ReadBE16(const unsigned char* ptr)
|
||||
{
|
||||
uint16_t x;
|
||||
memcpy((char*)&x, ptr, 2);
|
||||
return be16toh(x);
|
||||
memcpy(&x, ptr, 2);
|
||||
return be16toh_internal(x);
|
||||
}
|
||||
|
||||
uint32_t static inline ReadBE32(const unsigned char* ptr)
|
||||
{
|
||||
uint32_t x;
|
||||
memcpy((char*)&x, ptr, 4);
|
||||
return be32toh(x);
|
||||
memcpy(&x, ptr, 4);
|
||||
return be32toh_internal(x);
|
||||
}
|
||||
|
||||
uint64_t static inline ReadBE64(const unsigned char* ptr)
|
||||
{
|
||||
uint64_t x;
|
||||
memcpy((char*)&x, ptr, 8);
|
||||
return be64toh(x);
|
||||
memcpy(&x, ptr, 8);
|
||||
return be64toh_internal(x);
|
||||
}
|
||||
|
||||
void static inline WriteBE32(unsigned char* ptr, uint32_t x)
|
||||
{
|
||||
uint32_t v = htobe32(x);
|
||||
memcpy(ptr, (char*)&v, 4);
|
||||
uint32_t v = htobe32_internal(x);
|
||||
memcpy(ptr, &v, 4);
|
||||
}
|
||||
|
||||
void static inline WriteBE64(unsigned char* ptr, uint64_t x)
|
||||
{
|
||||
uint64_t v = htobe64(x);
|
||||
memcpy(ptr, (char*)&v, 8);
|
||||
}
|
||||
|
||||
/** Return the smallest number n such that (x >> n) == 0 (or 64 if the highest bit in x is set. */
|
||||
uint64_t static inline CountBits(uint64_t x)
|
||||
{
|
||||
#if HAVE_BUILTIN_CLZL
|
||||
if (sizeof(unsigned long) >= sizeof(uint64_t)) {
|
||||
return x ? 8 * sizeof(unsigned long) - __builtin_clzl(x) : 0;
|
||||
}
|
||||
#endif
|
||||
#if HAVE_BUILTIN_CLZLL
|
||||
if (sizeof(unsigned long long) >= sizeof(uint64_t)) {
|
||||
return x ? 8 * sizeof(unsigned long long) - __builtin_clzll(x) : 0;
|
||||
}
|
||||
#endif
|
||||
int ret = 0;
|
||||
while (x) {
|
||||
x >>= 1;
|
||||
++ret;
|
||||
}
|
||||
return ret;
|
||||
uint64_t v = htobe64_internal(x);
|
||||
memcpy(ptr, &v, 8);
|
||||
}
|
||||
|
||||
#endif // BITCOIN_CRYPTO_COMMON_H
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
#include <crypto/hmac_sha256.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** A rfc5869 HKDF implementation with HMAC_SHA256 and fixed key output length of 32 bytes (L=32) */
|
||||
class CHKDF_HMAC_SHA256_L32
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
#include <crypto/sha256.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** A hasher class for HMAC-SHA-256. */
|
||||
class CHMAC_SHA256
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
#include <crypto/sha512.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** A hasher class for HMAC-SHA-512. */
|
||||
class CHMAC_SHA512
|
||||
|
@ -5,8 +5,8 @@
|
||||
#ifndef BITCOIN_CRYPTO_PKCS5_PBKDF2_HMAC_SHA512_H
|
||||
#define BITCOIN_CRYPTO_PKCS5_PBKDF2_HMAC_SHA512_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** A rfc2898 implementation of PKCS#5 v2.0 password based encryption key
|
||||
* derivation function PBKDF2 with HMAC_SHA512. This implementation is
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include <span.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define POLY1305_BLOCK_SIZE 16
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
#ifndef BITCOIN_CRYPTO_RIPEMD160_H
|
||||
#define BITCOIN_CRYPTO_RIPEMD160_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** A hasher class for RIPEMD-160. */
|
||||
class CRIPEMD160
|
||||
|
@ -5,8 +5,8 @@
|
||||
#ifndef BITCOIN_CRYPTO_SHA1_H
|
||||
#define BITCOIN_CRYPTO_SHA1_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** A hasher class for SHA1. */
|
||||
class CSHA1
|
||||
|
@ -5,8 +5,8 @@
|
||||
#ifndef BITCOIN_CRYPTO_SHA256_H
|
||||
#define BITCOIN_CRYPTO_SHA256_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
/** A hasher class for SHA-256. */
|
||||
|
@ -5,8 +5,8 @@
|
||||
// This is a translation to GCC extended asm syntax from YASM code by Intel
|
||||
// (available at the bottom of this file).
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if defined(__x86_64__) || defined(__amd64__)
|
||||
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
#include <span.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
//! The Keccak-f[1600] transform.
|
||||
void KeccakF(uint64_t (&st)[25]);
|
||||
|
@ -5,8 +5,8 @@
|
||||
#ifndef BITCOIN_CRYPTO_SHA512_H
|
||||
#define BITCOIN_CRYPTO_SHA512_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/** A hasher class for SHA-512. */
|
||||
class CSHA512
|
||||
|
@ -1,5 +1,5 @@
|
||||
AC_PREREQ([2.60])
|
||||
AC_INIT([libdashbls],[1.3.4])
|
||||
AC_INIT([libdashbls],[1.3.5])
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AC_CONFIG_MACRO_DIR([build-aux/m4])
|
||||
|
||||
|
@ -59,6 +59,7 @@ public:
|
||||
GTElement Pair(const G2Element &b) const;
|
||||
uint32_t GetFingerprint(bool fLegacy = false) const;
|
||||
std::vector<uint8_t> Serialize(bool fLegacy = false) const;
|
||||
std::array<uint8_t, SIZE> SerializeToArray(bool fLegacy = false) const;
|
||||
G1Element Copy();
|
||||
|
||||
friend bool operator==(const G1Element &a, const G1Element &b);
|
||||
@ -102,6 +103,7 @@ public:
|
||||
G2Element Negate() const;
|
||||
GTElement Pair(const G1Element &a) const;
|
||||
std::vector<uint8_t> Serialize(bool fLegacy = false) const;
|
||||
std::array<uint8_t, G2Element::SIZE> SerializeToArray(bool fLegacy = false) const;
|
||||
G2Element Copy();
|
||||
|
||||
friend bool operator==(G2Element const &a, G2Element const &b);
|
||||
@ -127,6 +129,7 @@ public:
|
||||
|
||||
void Serialize(uint8_t *buffer) const;
|
||||
std::vector<uint8_t> Serialize() const;
|
||||
std::array<uint8_t, SIZE> SerializeToArray() const;
|
||||
|
||||
friend bool operator==(GTElement const &a, GTElement const &b);
|
||||
friend bool operator!=(GTElement const &a, GTElement const &b);
|
||||
|
@ -82,6 +82,7 @@ class PrivateKey {
|
||||
// Serialize the key into bytes
|
||||
void Serialize(uint8_t *buffer) const;
|
||||
std::vector<uint8_t> Serialize(bool fLegacy = false) const;
|
||||
std::array<uint8_t, PrivateKey::PRIVATE_KEY_SIZE> SerializeToArray(bool fLegacy = false) const;
|
||||
|
||||
G2Element SignG2(
|
||||
const uint8_t *msg,
|
||||
|
@ -171,11 +171,16 @@ uint32_t G1Element::GetFingerprint(const bool fLegacy) const
|
||||
}
|
||||
|
||||
std::vector<uint8_t> G1Element::Serialize(const bool fLegacy) const {
|
||||
const auto arr = G1Element::SerializeToArray(fLegacy);
|
||||
return std::vector<uint8_t>{arr.begin(), arr.end()};
|
||||
}
|
||||
|
||||
std::array<uint8_t, G1Element::SIZE> G1Element::SerializeToArray(const bool fLegacy) const {
|
||||
uint8_t buffer[G1Element::SIZE + 1];
|
||||
g1_write_bin(buffer, G1Element::SIZE + 1, p, 1);
|
||||
|
||||
std::array<uint8_t, G1Element::SIZE> result{};
|
||||
if (buffer[0] == 0x00) { // infinity
|
||||
std::vector<uint8_t> result(G1Element::SIZE, 0);
|
||||
result[0] = 0xc0;
|
||||
return result;
|
||||
}
|
||||
@ -187,7 +192,9 @@ std::vector<uint8_t> G1Element::Serialize(const bool fLegacy) const {
|
||||
if (!fLegacy) {
|
||||
buffer[1] |= 0x80; // indicate compression
|
||||
}
|
||||
return std::vector<uint8_t>(buffer + 1, buffer + 1 + G1Element::SIZE);
|
||||
|
||||
std::copy_n(buffer + 1, G1Element::SIZE, result.begin());
|
||||
return result;
|
||||
}
|
||||
|
||||
bool operator==(const G1Element & a, const G1Element &b)
|
||||
@ -386,11 +393,18 @@ G2Element G2Element::Negate() const
|
||||
GTElement G2Element::Pair(const G1Element& a) const { return a & (*this); }
|
||||
|
||||
std::vector<uint8_t> G2Element::Serialize(const bool fLegacy) const {
|
||||
const auto arr = G2Element::SerializeToArray(fLegacy);
|
||||
return std::vector<uint8_t>{arr.begin(), arr.end()};
|
||||
}
|
||||
|
||||
std::array<uint8_t, G2Element::SIZE> G2Element::SerializeToArray(const bool fLegacy) const {
|
||||
uint8_t buffer[G2Element::SIZE + 1];
|
||||
g2_write_bin(buffer, G2Element::SIZE + 1, (g2_st*)q, 1);
|
||||
|
||||
std::array<uint8_t, G2Element::SIZE> result{};
|
||||
|
||||
if (buffer[0] == 0x00) { // infinity
|
||||
std::vector<uint8_t> result(G2Element::SIZE, 0);
|
||||
result.fill(0);
|
||||
result[0] = 0xc0;
|
||||
return result;
|
||||
}
|
||||
@ -410,7 +424,6 @@ std::vector<uint8_t> G2Element::Serialize(const bool fLegacy) const {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<uint8_t> result(G2Element::SIZE, 0);
|
||||
if (fLegacy) {
|
||||
std::memcpy(result.data(), buffer + 1, G2Element::SIZE);
|
||||
} else {
|
||||
@ -551,4 +564,11 @@ std::vector<uint8_t> GTElement::Serialize() const
|
||||
return data;
|
||||
}
|
||||
|
||||
std::array<uint8_t, GTElement::SIZE> GTElement::SerializeToArray() const
|
||||
{
|
||||
std::array<uint8_t, GTElement::SIZE> data{};
|
||||
Serialize(data.data());
|
||||
return data;
|
||||
}
|
||||
|
||||
} // end namespace bls
|
||||
|
@ -284,6 +284,13 @@ std::vector<uint8_t> PrivateKey::Serialize(const bool fLegacy) const
|
||||
return data;
|
||||
}
|
||||
|
||||
std::array<uint8_t, PrivateKey::PRIVATE_KEY_SIZE> PrivateKey::SerializeToArray(bool fLegacy) const
|
||||
{
|
||||
std::array<uint8_t, PRIVATE_KEY_SIZE> data{};
|
||||
Serialize(data.data());
|
||||
return data;
|
||||
}
|
||||
|
||||
G2Element PrivateKey::SignG2(
|
||||
const uint8_t *msg,
|
||||
size_t len,
|
||||
|
@ -31,21 +31,21 @@ using namespace bls;
|
||||
void benchSigs() {
|
||||
string testName = "Signing";
|
||||
const int numIters = 5000;
|
||||
PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed());
|
||||
PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed());
|
||||
vector<uint8_t> message1 = sk.GetG1Element().Serialize();
|
||||
|
||||
auto start = startStopwatch();
|
||||
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
AugSchemeMPL().Sign(sk, message1);
|
||||
BasicSchemeMPL().Sign(sk, message1);
|
||||
}
|
||||
endStopwatch(testName, start, numIters);
|
||||
}
|
||||
|
||||
void benchVerification() {
|
||||
string testName = "Verification";
|
||||
const int numIters = 10000;
|
||||
PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed());
|
||||
const int numIters = 1000;
|
||||
PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed());
|
||||
G1Element pk = sk.GetG1Element();
|
||||
|
||||
std::vector<G2Element> sigs;
|
||||
@ -54,7 +54,7 @@ void benchVerification() {
|
||||
uint8_t message[4];
|
||||
Util::IntToFourBytes(message, i);
|
||||
vector<uint8_t> messageBytes(message, message + 4);
|
||||
sigs.push_back(AugSchemeMPL().Sign(sk, messageBytes));
|
||||
sigs.push_back(BasicSchemeMPL().Sign(sk, messageBytes));
|
||||
}
|
||||
|
||||
auto start = startStopwatch();
|
||||
@ -62,34 +62,36 @@ void benchVerification() {
|
||||
uint8_t message[4];
|
||||
Util::IntToFourBytes(message, i);
|
||||
vector<uint8_t> messageBytes(message, message + 4);
|
||||
bool ok = AugSchemeMPL().Verify(pk, messageBytes, sigs[i]);
|
||||
bool ok = BasicSchemeMPL().Verify(pk, messageBytes, sigs[i]);
|
||||
ASSERT(ok);
|
||||
}
|
||||
endStopwatch(testName, start, numIters);
|
||||
}
|
||||
|
||||
void benchBatchVerification() {
|
||||
const int numIters = 100000;
|
||||
const int numIters = 10000;
|
||||
|
||||
vector<vector<uint8_t>> sig_bytes;
|
||||
vector<vector<uint8_t>> pk_bytes;
|
||||
vector<vector<uint8_t>> ms;
|
||||
|
||||
auto start = startStopwatch();
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
uint8_t message[4];
|
||||
Util::IntToFourBytes(message, i);
|
||||
vector<uint8_t> messageBytes(message, message + 4);
|
||||
PrivateKey sk = AugSchemeMPL().KeyGen(getRandomSeed());
|
||||
PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed());
|
||||
G1Element pk = sk.GetG1Element();
|
||||
sig_bytes.push_back(AugSchemeMPL().Sign(sk, messageBytes).Serialize());
|
||||
sig_bytes.push_back(BasicSchemeMPL().Sign(sk, messageBytes).Serialize());
|
||||
pk_bytes.push_back(pk.Serialize());
|
||||
ms.push_back(messageBytes);
|
||||
}
|
||||
endStopwatch("Batch verification preparation", start, numIters);
|
||||
|
||||
vector<G1Element> pks;
|
||||
pks.reserve(numIters);
|
||||
|
||||
auto start = startStopwatch();
|
||||
start = startStopwatch();
|
||||
for (auto const& pk : pk_bytes) {
|
||||
pks.emplace_back(G1Element::FromBytes(Bytes(pk)));
|
||||
}
|
||||
@ -105,52 +107,71 @@ void benchBatchVerification() {
|
||||
endStopwatch("Signature validation", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
G2Element aggSig = AugSchemeMPL().Aggregate(sigs);
|
||||
G2Element aggSig = BasicSchemeMPL().Aggregate(sigs);
|
||||
endStopwatch("Aggregation", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
bool ok = AugSchemeMPL().AggregateVerify(pks, ms, aggSig);
|
||||
bool ok = BasicSchemeMPL().AggregateVerify(pks, ms, aggSig);
|
||||
ASSERT(ok);
|
||||
endStopwatch("Batch verification", start, numIters);
|
||||
}
|
||||
|
||||
void benchFastAggregateVerification() {
|
||||
const int numIters = 5000;
|
||||
|
||||
vector<G2Element> sigs;
|
||||
vector<G1Element> pks;
|
||||
vector<uint8_t> message = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
vector<G2Element> pops;
|
||||
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
PrivateKey sk = PopSchemeMPL().KeyGen(getRandomSeed());
|
||||
G1Element pk = sk.GetG1Element();
|
||||
sigs.push_back(PopSchemeMPL().Sign(sk, message));
|
||||
pops.push_back(PopSchemeMPL().PopProve(sk));
|
||||
pks.push_back(pk);
|
||||
}
|
||||
void benchSerialize() {
|
||||
const int numIters = 5000000;
|
||||
PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed());
|
||||
G1Element pk = sk.GetG1Element();
|
||||
vector<uint8_t> message = sk.GetG1Element().Serialize();
|
||||
G2Element sig = BasicSchemeMPL().Sign(sk, message);
|
||||
|
||||
auto start = startStopwatch();
|
||||
G2Element aggSig = PopSchemeMPL().Aggregate(sigs);
|
||||
endStopwatch("PopScheme Aggregation", start, numIters);
|
||||
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
sk.Serialize();
|
||||
}
|
||||
endStopwatch("Serialize PrivateKey", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
bool ok = PopSchemeMPL().PopVerify(pks[i], pops[i]);
|
||||
ASSERT(ok);
|
||||
pk.Serialize();
|
||||
}
|
||||
endStopwatch("PopScheme Proofs verification", start, numIters);
|
||||
endStopwatch("Serialize G1Element", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
bool ok = PopSchemeMPL().FastAggregateVerify(pks, message, aggSig);
|
||||
ASSERT(ok);
|
||||
endStopwatch("PopScheme verification", start, numIters);
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
sig.Serialize();
|
||||
}
|
||||
endStopwatch("Serialize G2Element", start, numIters);
|
||||
}
|
||||
|
||||
void benchSerializeToArray() {
|
||||
const int numIters = 5000000;
|
||||
PrivateKey sk = BasicSchemeMPL().KeyGen(getRandomSeed());
|
||||
G1Element pk = sk.GetG1Element();
|
||||
vector<uint8_t> message = sk.GetG1Element().Serialize();
|
||||
G2Element sig = BasicSchemeMPL().Sign(sk, message);
|
||||
|
||||
auto start = startStopwatch();
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
sk.SerializeToArray();
|
||||
}
|
||||
endStopwatch("SerializeToArray PrivateKey", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
pk.SerializeToArray();
|
||||
}
|
||||
endStopwatch("SerializeToArray G1Element", start, numIters);
|
||||
|
||||
start = startStopwatch();
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
sig.SerializeToArray();
|
||||
}
|
||||
endStopwatch("SerializeToArray G2Element", start, numIters);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
benchSigs();
|
||||
benchVerification();
|
||||
benchBatchVerification();
|
||||
benchFastAggregateVerification();
|
||||
benchSerialize();
|
||||
benchSerializeToArray();
|
||||
}
|
||||
|
@ -21,6 +21,8 @@
|
||||
static const size_t DBWRAPPER_PREALLOC_KEY_SIZE = 64;
|
||||
static const size_t DBWRAPPER_PREALLOC_VALUE_SIZE = 1024;
|
||||
|
||||
inline auto CharCast(const std::byte* data) { return reinterpret_cast<const char*>(data); }
|
||||
|
||||
class dbwrapper_error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
@ -83,12 +85,12 @@ public:
|
||||
template <typename V>
|
||||
void Write(const CDataStream& _ssKey, const V& value)
|
||||
{
|
||||
leveldb::Slice slKey((const char*)_ssKey.data(), _ssKey.size());
|
||||
leveldb::Slice slKey(CharCast(_ssKey.data()), _ssKey.size());
|
||||
|
||||
ssValue.reserve(DBWRAPPER_PREALLOC_VALUE_SIZE);
|
||||
ssValue << value;
|
||||
ssValue.Xor(dbwrapper_private::GetObfuscateKey(parent));
|
||||
leveldb::Slice slValue((const char*)ssValue.data(), ssValue.size());
|
||||
leveldb::Slice slValue(CharCast(ssValue.data()), ssValue.size());
|
||||
|
||||
batch.Put(slKey, slValue);
|
||||
// - varint: key length (1 byte up to 127B, 2 bytes up to 16383B, ...)
|
||||
@ -110,7 +112,7 @@ public:
|
||||
}
|
||||
|
||||
void Erase(const CDataStream& _ssKey) {
|
||||
leveldb::Slice slKey((const char*)_ssKey.data(), _ssKey.size());
|
||||
leveldb::Slice slKey(CharCast(_ssKey.data()), _ssKey.size());
|
||||
|
||||
batch.Delete(slKey);
|
||||
// - byte: header
|
||||
@ -151,7 +153,7 @@ public:
|
||||
}
|
||||
|
||||
void Seek(const CDataStream& ssKey) {
|
||||
leveldb::Slice slKey((const char*)ssKey.data(), ssKey.size());
|
||||
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
|
||||
piter->Seek(slKey);
|
||||
}
|
||||
|
||||
@ -259,7 +261,7 @@ public:
|
||||
|
||||
bool ReadDataStream(const CDataStream& ssKey, CDataStream& ssValue) const
|
||||
{
|
||||
leveldb::Slice slKey((const char*)ssKey.data(), ssKey.size());
|
||||
leveldb::Slice slKey(CharCast(ssKey.data()), ssKey.size());
|
||||
|
||||
std::string strValue;
|
||||
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
|
||||
@ -319,7 +321,7 @@ public:
|
||||
|
||||
bool Exists(const CDataStream& key) const
|
||||
{
|
||||
leveldb::Slice slKey((const char*)key.data(), key.size());
|
||||
leveldb::Slice slKey(CharCast(key.data()), key.size());
|
||||
|
||||
std::string strValue;
|
||||
leveldb::Status status = pdb->Get(readoptions, slKey, &strValue);
|
||||
@ -363,8 +365,8 @@ public:
|
||||
ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
|
||||
ssKey1 << key_begin;
|
||||
ssKey2 << key_end;
|
||||
leveldb::Slice slKey1((const char*)ssKey1.data(), ssKey1.size());
|
||||
leveldb::Slice slKey2((const char*)ssKey2.data(), ssKey2.size());
|
||||
leveldb::Slice slKey1(CharCast(ssKey1.data()), ssKey1.size());
|
||||
leveldb::Slice slKey2(CharCast(ssKey2.data()), ssKey2.size());
|
||||
uint64_t size = 0;
|
||||
leveldb::Range range(slKey1, slKey2);
|
||||
pdb->GetApproximateSizes(&range, 1, &size);
|
||||
@ -382,8 +384,8 @@ public:
|
||||
ssKey2.reserve(DBWRAPPER_PREALLOC_KEY_SIZE);
|
||||
ssKey1 << key_begin;
|
||||
ssKey2 << key_end;
|
||||
leveldb::Slice slKey1((const char*)ssKey1.data(), ssKey1.size());
|
||||
leveldb::Slice slKey2((const char*)ssKey2.data(), ssKey2.size());
|
||||
leveldb::Slice slKey1(CharCast(ssKey1.data()), ssKey1.size());
|
||||
leveldb::Slice slKey2(CharCast(ssKey2.data()), ssKey2.size());
|
||||
pdb->CompactRange(&slKey1, &slKey2);
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@
|
||||
#include <util/threadnames.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <deque>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -355,7 +355,7 @@ Binary Session::MyDestination() const
|
||||
|
||||
uint16_t cert_len;
|
||||
memcpy(&cert_len, &m_private_key.at(CERT_LEN_POS), sizeof(cert_len));
|
||||
cert_len = be16toh(cert_len);
|
||||
cert_len = be16toh_internal(cert_len);
|
||||
|
||||
const size_t dest_len = DEST_LEN_BASE + cert_len;
|
||||
|
||||
|
456
src/init.cpp
456
src/init.cpp
@ -38,6 +38,8 @@
|
||||
#include <netbase.h>
|
||||
#include <netgroup.h>
|
||||
#include <node/blockstorage.h>
|
||||
#include <node/caches.h>
|
||||
#include <node/chainstate.h>
|
||||
#include <node/context.h>
|
||||
#include <node/interface_ui.h>
|
||||
#include <node/txreconciliation.h>
|
||||
@ -333,15 +335,8 @@ void PrepareShutdown(NodeContext& node)
|
||||
chainstate->ResetCoinsViews();
|
||||
}
|
||||
}
|
||||
node.chain_helper.reset();
|
||||
if (node.mnhf_manager) {
|
||||
node.mnhf_manager->DisconnectManagers();
|
||||
}
|
||||
node.llmq_ctx.reset();
|
||||
llmq::quorumSnapshotManager.reset();
|
||||
node.mempool->DisconnectManagers();
|
||||
node.dmnman.reset();
|
||||
node.cpoolman.reset();
|
||||
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager,
|
||||
llmq::quorumSnapshotManager, node.llmq_ctx, Assert(node.mempool.get()));
|
||||
node.mnhf_manager.reset();
|
||||
node.evodb.reset();
|
||||
}
|
||||
@ -1805,37 +1800,20 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
bool fReindexChainState = args.GetBoolArg("-reindex-chainstate", false);
|
||||
|
||||
// cache size calculations
|
||||
int64_t nTotalCache = (args.GetArg("-dbcache", nDefaultDbCache) << 20);
|
||||
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
|
||||
nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); // total cache cannot be greater than nMaxDbcache
|
||||
int64_t nBlockTreeDBCache = std::min(nTotalCache / 8, nMaxBlockDBCache << 20);
|
||||
nTotalCache -= nBlockTreeDBCache;
|
||||
int64_t nTxIndexCache = std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxTxIndexCache << 20 : 0);
|
||||
nTotalCache -= nTxIndexCache;
|
||||
int64_t filter_index_cache = 0;
|
||||
if (!g_enabled_filter_types.empty()) {
|
||||
size_t n_indexes = g_enabled_filter_types.size();
|
||||
int64_t max_cache = std::min(nTotalCache / 8, max_filter_index_cache << 20);
|
||||
filter_index_cache = max_cache / n_indexes;
|
||||
nTotalCache -= filter_index_cache * n_indexes;
|
||||
}
|
||||
int64_t nCoinDBCache = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); // use 25%-50% of the remainder for disk cache
|
||||
nCoinDBCache = std::min(nCoinDBCache, nMaxCoinsDBCache << 20); // cap total coins db cache
|
||||
nTotalCache -= nCoinDBCache;
|
||||
int64_t nCoinCacheUsage = nTotalCache; // the rest goes to in-memory cache
|
||||
CacheSizes cache_sizes = CalculateCacheSizes(args, g_enabled_filter_types.size());
|
||||
|
||||
int64_t nMempoolSizeMax = args.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
|
||||
int64_t nEvoDbCache = 1024 * 1024 * 64; // TODO
|
||||
LogPrintf("Cache configuration:\n");
|
||||
LogPrintf("* Using %.1f MiB for block index database\n", nBlockTreeDBCache * (1.0 / 1024 / 1024));
|
||||
LogPrintf("* Using %.1f MiB for block index database\n", cache_sizes.block_tree_db * (1.0 / 1024 / 1024));
|
||||
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
|
||||
LogPrintf("* Using %.1f MiB for transaction index database\n", nTxIndexCache * (1.0 / 1024 / 1024));
|
||||
LogPrintf("* Using %.1f MiB for transaction index database\n", cache_sizes.tx_index * (1.0 / 1024 / 1024));
|
||||
}
|
||||
for (BlockFilterType filter_type : g_enabled_filter_types) {
|
||||
LogPrintf("* Using %.1f MiB for %s block filter index database\n",
|
||||
filter_index_cache * (1.0 / 1024 / 1024), BlockFilterTypeName(filter_type));
|
||||
cache_sizes.filter_index * (1.0 / 1024 / 1024), BlockFilterTypeName(filter_type));
|
||||
}
|
||||
LogPrintf("* Using %.1f MiB for chain state database\n", nCoinDBCache * (1.0 / 1024 / 1024));
|
||||
LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)\n", nCoinCacheUsage * (1.0 / 1024 / 1024), nMempoolSizeMax * (1.0 / 1024 / 1024));
|
||||
LogPrintf("* Using %.1f MiB for chain state database\n", cache_sizes.coins_db * (1.0 / 1024 / 1024));
|
||||
LogPrintf("* Using %.1f MiB for in-memory UTXO set (plus up to %.1f MiB of unused mempool space)\n", cache_sizes.coins * (1.0 / 1024 / 1024), nMempoolSizeMax * (1.0 / 1024 / 1024));
|
||||
|
||||
assert(!node.mempool);
|
||||
assert(!node.chainman);
|
||||
@ -1862,279 +1840,155 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
node.govman = std::make_unique<CGovernanceManager>(*node.mn_metaman, *node.netfulfilledman, *node.chainman, node.dmnman, *node.mn_sync);
|
||||
|
||||
const bool fReset = fReindex;
|
||||
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
||||
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
|
||||
};
|
||||
bilingual_str strLoadError;
|
||||
|
||||
uiInterface.InitMessage(_("Loading block index…").translated);
|
||||
|
||||
do {
|
||||
bool failed_verification = false;
|
||||
const auto load_block_index_start_time{SteadyClock::now()};
|
||||
|
||||
try {
|
||||
LOCK(cs_main);
|
||||
|
||||
node.evodb.reset();
|
||||
node.evodb = std::make_unique<CEvoDB>(nEvoDbCache, false, fReset || fReindexChainState);
|
||||
|
||||
node.mnhf_manager.reset();
|
||||
node.mnhf_manager = std::make_unique<CMNHFManager>(*node.evodb);
|
||||
|
||||
chainman.InitializeChainstate(Assert(node.mempool.get()), *node.evodb, node.chain_helper, llmq::chainLocksHandler, llmq::quorumInstantSendManager);
|
||||
chainman.m_total_coinstip_cache = nCoinCacheUsage;
|
||||
chainman.m_total_coinsdb_cache = nCoinDBCache;
|
||||
|
||||
auto& pblocktree{chainman.m_blockman.m_block_tree_db};
|
||||
// new CBlockTreeDB tries to delete the existing file, which
|
||||
// fails if it's still open from the previous loop. Close it first:
|
||||
pblocktree.reset();
|
||||
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReset));
|
||||
|
||||
// Same logic as above with pblocktree
|
||||
node.dmnman.reset();
|
||||
node.dmnman = std::make_unique<CDeterministicMNManager>(chainman.ActiveChainstate(), *node.evodb);
|
||||
node.mempool->ConnectManagers(node.dmnman.get());
|
||||
|
||||
node.cpoolman.reset();
|
||||
node.cpoolman = std::make_unique<CCreditPoolManager>(*node.evodb);
|
||||
|
||||
llmq::quorumSnapshotManager.reset();
|
||||
llmq::quorumSnapshotManager.reset(new llmq::CQuorumSnapshotManager(*node.evodb));
|
||||
|
||||
if (node.llmq_ctx) {
|
||||
node.llmq_ctx->Interrupt();
|
||||
node.llmq_ctx->Stop();
|
||||
}
|
||||
node.llmq_ctx.reset();
|
||||
node.llmq_ctx = std::make_unique<LLMQContext>(chainman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman,
|
||||
*node.mempool, node.mn_activeman.get(), *node.mn_sync, /*unit_tests=*/false, /*wipe=*/fReset || fReindexChainState);
|
||||
// Enable CMNHFManager::{Process, Undo}Block
|
||||
node.mnhf_manager->ConnectManagers(node.chainman.get(), node.llmq_ctx->qman.get());
|
||||
|
||||
node.chain_helper.reset();
|
||||
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor), *node.chainman,
|
||||
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
|
||||
|
||||
if (fReset) {
|
||||
pblocktree->WriteReindexing(true);
|
||||
//If we're reindexing in prune mode, wipe away unusable block files and all undo data files
|
||||
if (fPruneMode)
|
||||
CleanupBlockRevFiles();
|
||||
}
|
||||
|
||||
if (ShutdownRequested()) break;
|
||||
|
||||
// LoadBlockIndex will load m_have_pruned if we've ever removed a
|
||||
// block file from disk.
|
||||
// Note that it also sets fReindex based on the disk flag!
|
||||
// From here on out fReindex and fReset mean something different!
|
||||
if (!chainman.LoadBlockIndex()) {
|
||||
if (ShutdownRequested()) break;
|
||||
strLoadError = _("Error loading block database");
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_governance_enabled && !args.GetBoolArg("-txindex", DEFAULT_TXINDEX) && chainparams.NetworkIDString() != CBaseChainParams::REGTEST) { // TODO remove this when pruning is fixed. See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743
|
||||
return InitError(_("Transaction index can't be disabled with governance validation enabled. Either start with -disablegovernance command line switch or enable transaction index."));
|
||||
}
|
||||
|
||||
const auto load_block_index_start_time{SteadyClock::now()};
|
||||
std::optional<ChainstateLoadingError> rv;
|
||||
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,
|
||||
llmq::chainLocksHandler,
|
||||
llmq::quorumInstantSendManager,
|
||||
llmq::quorumSnapshotManager,
|
||||
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);
|
||||
});
|
||||
} catch (const std::exception& e) {
|
||||
LogPrintf("%s\n", e.what());
|
||||
rv = ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED;
|
||||
}
|
||||
if (rv.has_value()) {
|
||||
switch (rv.value()) {
|
||||
case ChainstateLoadingError::ERROR_LOADING_BLOCK_DB:
|
||||
strLoadError = _("Error loading block database");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK:
|
||||
// If the loaded chain has a wrong genesis, bail out immediately
|
||||
// (we're likely using a testnet datadir, or the other way around).
|
||||
if (!chainman.BlockIndex().empty() &&
|
||||
!chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
|
||||
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
|
||||
}
|
||||
|
||||
if (!chainparams.GetConsensus().hashDevnetGenesisBlock.IsNull() && !chainman.BlockIndex().empty() &&
|
||||
!chainman.m_blockman.LookupBlockIndex(chainparams.GetConsensus().hashDevnetGenesisBlock)) {
|
||||
return InitError(_("Incorrect or no devnet genesis block found. Wrong datadir for devnet specified?"));
|
||||
}
|
||||
|
||||
if (!fReset && !fReindexChainState) {
|
||||
// Check for changed -addressindex state
|
||||
if (!fAddressIndex && fAddressIndex != args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX)) {
|
||||
strLoadError = _("You need to rebuild the database using -reindex to enable -addressindex");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for changed -timestampindex state
|
||||
if (!fTimestampIndex && fTimestampIndex != args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX)) {
|
||||
strLoadError = _("You need to rebuild the database using -reindex to enable -timestampindex");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for changed -spentindex state
|
||||
if (!fSpentIndex && fSpentIndex != args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX)) {
|
||||
strLoadError = _("You need to rebuild the database using -reindex to enable -spentindex");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
chainman.InitAdditionalIndexes();
|
||||
|
||||
LogPrintf("%s: address index %s\n", __func__, fAddressIndex ? "enabled" : "disabled");
|
||||
LogPrintf("%s: timestamp index %s\n", __func__, fTimestampIndex ? "enabled" : "disabled");
|
||||
LogPrintf("%s: spent index %s\n", __func__, fSpentIndex ? "enabled" : "disabled");
|
||||
|
||||
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
|
||||
// in the past, but is now trying to run unpruned.
|
||||
if (chainman.m_blockman.m_have_pruned && !fPruneMode) {
|
||||
strLoadError = _("You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain");
|
||||
break;
|
||||
}
|
||||
|
||||
// At this point blocktree args are consistent with what's on disk.
|
||||
// If we're not mid-reindex (based on disk + args), add a genesis block on disk
|
||||
// (otherwise we use the one already on disk).
|
||||
// This is called again in ThreadImport after the reindex completes.
|
||||
if (!fReindex && !chainman.ActiveChainstate().LoadGenesisBlock()) {
|
||||
strLoadError = _("Error initializing block database");
|
||||
break;
|
||||
}
|
||||
|
||||
// At this point we're either in reindex or we've loaded a useful
|
||||
// block tree into BlockIndex()!
|
||||
|
||||
bool failed_chainstate_init = false;
|
||||
for (CChainState* chainstate : chainman.GetAll()) {
|
||||
chainstate->InitCoinsDB(
|
||||
/* cache_size_bytes */ nCoinDBCache,
|
||||
/* in_memory */ false,
|
||||
/* should_wipe */ fReset || fReindexChainState);
|
||||
|
||||
chainstate->CoinsErrorCatcher().AddReadErrCallback([]() {
|
||||
uiInterface.ThreadSafeMessageBox(
|
||||
_("Error reading from database, shutting down."),
|
||||
"", CClientUIInterface::MSG_ERROR);
|
||||
});
|
||||
|
||||
// If necessary, upgrade from older database format.
|
||||
// This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
|
||||
if (!chainstate->CoinsDB().Upgrade()) {
|
||||
strLoadError = _("Error upgrading chainstate database");
|
||||
failed_chainstate_init = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
|
||||
if (!chainstate->ReplayBlocks()) {
|
||||
strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.");
|
||||
failed_chainstate_init = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// The on-disk coinsdb is now in a good state, create the cache
|
||||
chainstate->InitCoinsCache(nCoinCacheUsage);
|
||||
assert(chainstate->CanFlushToDisk());
|
||||
|
||||
// flush evodb
|
||||
// TODO: CEvoDB instance should probably be a part of CChainState
|
||||
// (for multiple chainstates to actually work in parallel)
|
||||
// and not a global
|
||||
if (&chainman.ActiveChainstate() == chainstate && !node.evodb->CommitRootTransaction()) {
|
||||
strLoadError = _("Failed to commit EvoDB");
|
||||
failed_chainstate_init = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!is_coinsview_empty(chainstate)) {
|
||||
// LoadChainTip initializes the chain based on CoinsTip()'s best block
|
||||
if (!chainstate->LoadChainTip()) {
|
||||
strLoadError = _("Error initializing block database");
|
||||
failed_chainstate_init = true;
|
||||
break; // out of the per-chainstate loop
|
||||
}
|
||||
assert(chainstate->m_chain.Tip() != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (failed_chainstate_init) {
|
||||
break; // out of the chainstate activation do-while
|
||||
}
|
||||
|
||||
if (!node.dmnman->MigrateDBIfNeeded()) {
|
||||
strLoadError = _("Error upgrading evo database");
|
||||
break;
|
||||
}
|
||||
if (!node.dmnman->MigrateDBIfNeeded2()) {
|
||||
strLoadError = _("Error upgrading evo database");
|
||||
break;
|
||||
}
|
||||
if (!node.mnhf_manager->ForceSignalDBUpdate()) {
|
||||
strLoadError = _("Error upgrading evo database for EHF");
|
||||
break;
|
||||
}
|
||||
|
||||
for (CChainState* chainstate : chainman.GetAll()) {
|
||||
if (!is_coinsview_empty(chainstate)) {
|
||||
uiInterface.InitMessage(_("Verifying blocks…").translated);
|
||||
if (chainman.m_blockman.m_have_pruned && args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS) > MIN_BLOCKS_TO_KEEP) {
|
||||
LogPrintf("Prune: pruned datadir may not have more than %d blocks; only checking available blocks\n",
|
||||
MIN_BLOCKS_TO_KEEP);
|
||||
}
|
||||
|
||||
const CBlockIndex* tip = chainstate->m_chain.Tip();
|
||||
RPCNotifyBlockChange(tip);
|
||||
if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) {
|
||||
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. "
|
||||
"Only rebuild the block database if you are sure that your computer's date and time are correct");
|
||||
failed_verification = true;
|
||||
break;
|
||||
}
|
||||
const bool v19active{DeploymentActiveAfter(tip, chainparams.GetConsensus(), Consensus::DEPLOYMENT_V19)};
|
||||
if (v19active) {
|
||||
bls::bls_legacy_scheme.store(false);
|
||||
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load());
|
||||
}
|
||||
|
||||
if (!CVerifyDB().VerifyDB(
|
||||
*chainstate, chainparams, chainstate->CoinsDB(),
|
||||
*node.evodb,
|
||||
args.GetArg("-checklevel", DEFAULT_CHECKLEVEL),
|
||||
args.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS))) {
|
||||
strLoadError = _("Corrupted block database detected");
|
||||
failed_verification = true;
|
||||
break;
|
||||
}
|
||||
|
||||
// VerifyDB() disconnects blocks which might result in us switching back to legacy.
|
||||
// Make sure we use the right scheme.
|
||||
if (v19active && bls::bls_legacy_scheme.load()) {
|
||||
bls::bls_legacy_scheme.store(false);
|
||||
LogPrintf("%s: bls_legacy_scheme=%d\n", __func__, bls::bls_legacy_scheme.load());
|
||||
}
|
||||
|
||||
if (args.GetArg("-checklevel", DEFAULT_CHECKLEVEL) >= 3) {
|
||||
chainstate->ResetBlockFailureFlags(nullptr);
|
||||
}
|
||||
|
||||
} else {
|
||||
// TODO: CEvoDB instance should probably be a part of CChainState
|
||||
// (for multiple chainstates to actually work in parallel)
|
||||
// and not a global
|
||||
if (&chainman.ActiveChainstate() == chainstate && !node.evodb->IsEmpty()) {
|
||||
// EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong
|
||||
strLoadError = _("Error initializing block database");
|
||||
failed_verification = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
LogPrintf("%s\n", e.what());
|
||||
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
|
||||
case ChainstateLoadingError::ERROR_BAD_DEVNET_GENESIS_BLOCK:
|
||||
return InitError(_("Incorrect or no devnet genesis block found. Wrong datadir for devnet specified?"));
|
||||
case ChainstateLoadingError::ERROR_TXINDEX_DISABLED_WHEN_GOV_ENABLED:
|
||||
return InitError(_("Transaction index can't be disabled with governance validation enabled. Either start with -disablegovernance command line switch or enable transaction index."));
|
||||
case ChainstateLoadingError::ERROR_ADDRIDX_NEEDS_REINDEX:
|
||||
strLoadError = _("You need to rebuild the database using -reindex to enable -addressindex");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_SPENTIDX_NEEDS_REINDEX:
|
||||
strLoadError = _("You need to rebuild the database using -reindex to enable -spentindex");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_TIMEIDX_NEEDS_REINDEX:
|
||||
strLoadError = _("You need to rebuild the database using -reindex to enable -timestampindex");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_PRUNED_NEEDS_REINDEX:
|
||||
strLoadError = _("You need to rebuild the database using -reindex to go back to unpruned mode. This will redownload the entire blockchain");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_LOAD_GENESIS_BLOCK_FAILED:
|
||||
strLoadError = _("Error initializing block database");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_CHAINSTATE_UPGRADE_FAILED:
|
||||
strLoadError = _("Error upgrading chainstate database");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_REPLAYBLOCKS_FAILED:
|
||||
strLoadError = _("Unable to replay blocks. You will need to rebuild the database using -reindex-chainstate.");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_LOADCHAINTIP_FAILED:
|
||||
strLoadError = _("Error initializing block database");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_GENERIC_BLOCKDB_OPEN_FAILED:
|
||||
strLoadError = _("Error opening block database");
|
||||
failed_verification = true;
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_COMMITING_EVO_DB:
|
||||
strLoadError = _("Failed to commit Evo database");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_UPGRADING_EVO_DB:
|
||||
strLoadError = _("Error upgrading Evo database");
|
||||
break;
|
||||
case ChainstateLoadingError::ERROR_UPGRADING_SIGNALS_DB:
|
||||
strLoadError = _("Error upgrading evo database for EHF");
|
||||
break;
|
||||
case ChainstateLoadingError::SHUTDOWN_PROBED:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
LogPrintf("%s: address index %s\n", __func__, fAddressIndex ? "enabled" : "disabled");
|
||||
LogPrintf("%s: timestamp index %s\n", __func__, fTimestampIndex ? "enabled" : "disabled");
|
||||
LogPrintf("%s: spent index %s\n", __func__, fSpentIndex ? "enabled" : "disabled");
|
||||
|
||||
if (!failed_verification) {
|
||||
std::optional<ChainstateLoadVerifyError> rv2;
|
||||
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);
|
||||
});
|
||||
} catch (const std::exception& e) {
|
||||
LogPrintf("%s\n", e.what());
|
||||
rv2 = ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE;
|
||||
}
|
||||
if (rv2.has_value()) {
|
||||
switch (rv2.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. "
|
||||
"Only rebuild the block database if you are sure that your computer's date and time are correct");
|
||||
break;
|
||||
case ChainstateLoadVerifyError::ERROR_CORRUPTED_BLOCK_DB:
|
||||
strLoadError = _("Corrupted block database detected");
|
||||
break;
|
||||
case ChainstateLoadVerifyError::ERROR_EVO_DB_SANITY_FAILED:
|
||||
strLoadError = _("Error initializing block database");
|
||||
break;
|
||||
case ChainstateLoadVerifyError::ERROR_GENERIC_FAILURE:
|
||||
strLoadError = _("Error opening block database");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
fLoaded = true;
|
||||
LogPrintf(" block index %15dms\n", Ticks<std::chrono::milliseconds>(SteadyClock::now() - load_block_index_start_time));
|
||||
}
|
||||
} while(false);
|
||||
}
|
||||
|
||||
if (!fLoaded && !ShutdownRequested()) {
|
||||
// first suggest a reindex
|
||||
@ -2225,14 +2079,14 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
return InitError(*error);
|
||||
}
|
||||
|
||||
g_txindex = std::make_unique<TxIndex>(nTxIndexCache, false, fReindex);
|
||||
g_txindex = std::make_unique<TxIndex>(cache_sizes.tx_index, false, fReindex);
|
||||
if (!g_txindex->Start(chainman.ActiveChainstate())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& filter_type : g_enabled_filter_types) {
|
||||
InitBlockFilterIndex(filter_type, filter_index_cache, false, fReindex);
|
||||
InitBlockFilterIndex(filter_type, cache_sizes.filter_index, false, fReindex);
|
||||
if (!GetBlockFilterIndex(filter_type)->Start(chainman.ActiveChainstate())) {
|
||||
return false;
|
||||
}
|
||||
@ -2537,7 +2391,17 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
|
||||
// ********************************************************* Step 13: finished
|
||||
|
||||
// At this point, the RPC is "started", but still in warmup, which means it
|
||||
// cannot yet be called. Before we make it callable, we need to make sure
|
||||
// that the RPC's view of the best block is valid and consistent with
|
||||
// ChainstateManager's ActiveTip.
|
||||
//
|
||||
// If we do not do this, RPC's view of the best block will be height=0 and
|
||||
// hash=0x0. This will lead to erroroneous responses for things like
|
||||
// waitforblockheight.
|
||||
RPCNotifyBlockChange(chainman.ActiveTip());
|
||||
SetRPCWarmupFinished();
|
||||
|
||||
uiInterface.InitMessage(_("Done loading").translated);
|
||||
|
||||
for (const auto& client : node.chain_clients) {
|
||||
|
@ -12,11 +12,11 @@
|
||||
#include <tinyformat.h>
|
||||
#include <util/system.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
|
@ -10,10 +10,10 @@
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <system_error>
|
||||
#include <unistd.h>
|
||||
|
@ -9,9 +9,8 @@
|
||||
#include <prevector.h>
|
||||
#include <support/allocators/pool.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
32
src/node/caches.cpp
Normal file
32
src/node/caches.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2021 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <node/caches.h>
|
||||
|
||||
#include <txdb.h>
|
||||
#include <util/system.h>
|
||||
#include <validation.h>
|
||||
|
||||
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
|
||||
{
|
||||
int64_t nTotalCache = (args.GetArg("-dbcache", nDefaultDbCache) << 20);
|
||||
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
|
||||
nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); // total cache cannot be greater than nMaxDbcache
|
||||
CacheSizes sizes;
|
||||
sizes.block_tree_db = std::min(nTotalCache / 8, nMaxBlockDBCache << 20);
|
||||
nTotalCache -= sizes.block_tree_db;
|
||||
sizes.tx_index = std::min(nTotalCache / 8, args.GetBoolArg("-txindex", DEFAULT_TXINDEX) ? nMaxTxIndexCache << 20 : 0);
|
||||
nTotalCache -= sizes.tx_index;
|
||||
sizes.filter_index = 0;
|
||||
if (n_indexes > 0) {
|
||||
int64_t max_cache = std::min(nTotalCache / 8, max_filter_index_cache << 20);
|
||||
sizes.filter_index = max_cache / n_indexes;
|
||||
nTotalCache -= sizes.filter_index * n_indexes;
|
||||
}
|
||||
sizes.coins_db = std::min(nTotalCache / 2, (nTotalCache / 4) + (1 << 23)); // use 25%-50% of the remainder for disk cache
|
||||
sizes.coins_db = std::min(sizes.coins_db, nMaxCoinsDBCache << 20); // cap total coins db cache
|
||||
nTotalCache -= sizes.coins_db;
|
||||
sizes.coins = nTotalCache; // the rest goes to in-memory cache
|
||||
return sizes;
|
||||
}
|
22
src/node/caches.h
Normal file
22
src/node/caches.h
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright (c) 2021 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_NODE_CACHES_H
|
||||
#define BITCOIN_NODE_CACHES_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
class ArgsManager;
|
||||
|
||||
struct CacheSizes {
|
||||
int64_t block_tree_db;
|
||||
int64_t coins_db;
|
||||
int64_t coins;
|
||||
int64_t tx_index;
|
||||
int64_t filter_index;
|
||||
};
|
||||
CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes = 0);
|
||||
|
||||
#endif // BITCOIN_NODE_CACHES_H
|
328
src/node/chainstate.cpp
Normal file
328
src/node/chainstate.cpp
Normal file
@ -0,0 +1,328 @@
|
||||
// Copyright (c) 2021 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <node/chainstate.h>
|
||||
|
||||
#include <consensus/params.h>
|
||||
#include <deploymentstatus.h>
|
||||
#include <node/blockstorage.h>
|
||||
#include <validation.h>
|
||||
|
||||
#include <evo/chainhelper.h>
|
||||
#include <evo/creditpool.h>
|
||||
#include <evo/deterministicmns.h>
|
||||
#include <evo/evodb.h>
|
||||
#include <evo/mnhftx.h>
|
||||
#include <llmq/chainlocks.h>
|
||||
#include <llmq/context.h>
|
||||
#include <llmq/instantsend.h>
|
||||
#include <llmq/snapshot.h>
|
||||
|
||||
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
||||
ChainstateManager& chainman,
|
||||
CGovernanceManager& govman,
|
||||
CMasternodeMetaMan& mn_metaman,
|
||||
CMasternodeSync& mn_sync,
|
||||
CSporkManager& sporkman,
|
||||
std::unique_ptr<CActiveMasternodeManager>& mn_activeman,
|
||||
std::unique_ptr<CChainstateHelper>& chain_helper,
|
||||
std::unique_ptr<CCreditPoolManager>& cpoolman,
|
||||
std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||
std::unique_ptr<CEvoDB>& evodb,
|
||||
std::unique_ptr<CMNHFManager>& mnhf_manager,
|
||||
std::unique_ptr<llmq::CChainLocksHandler>& clhandler,
|
||||
std::unique_ptr<llmq::CInstantSendManager>& isman,
|
||||
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||
CTxMemPool* mempool,
|
||||
bool fPruneMode,
|
||||
bool is_addrindex_enabled,
|
||||
bool is_governance_enabled,
|
||||
bool is_spentindex_enabled,
|
||||
bool is_timeindex_enabled,
|
||||
bool is_txindex_enabled,
|
||||
const Consensus::Params& consensus_params,
|
||||
const std::string& network_id,
|
||||
bool fReindexChainState,
|
||||
int64_t nBlockTreeDBCache,
|
||||
int64_t nCoinDBCache,
|
||||
int64_t nCoinCacheUsage,
|
||||
bool block_tree_db_in_memory,
|
||||
bool coins_db_in_memory,
|
||||
std::function<bool()> shutdown_requested,
|
||||
std::function<void()> coins_error_cb)
|
||||
{
|
||||
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
||||
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
|
||||
};
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
int64_t nEvoDbCache{64 * 1024 * 1024}; // TODO
|
||||
evodb.reset();
|
||||
evodb = std::make_unique<CEvoDB>(nEvoDbCache, false, fReset || fReindexChainState);
|
||||
|
||||
mnhf_manager.reset();
|
||||
mnhf_manager = std::make_unique<CMNHFManager>(*evodb);
|
||||
|
||||
chainman.InitializeChainstate(mempool, *evodb, chain_helper, clhandler, isman);
|
||||
chainman.m_total_coinstip_cache = nCoinCacheUsage;
|
||||
chainman.m_total_coinsdb_cache = nCoinDBCache;
|
||||
|
||||
auto& pblocktree{chainman.m_blockman.m_block_tree_db};
|
||||
// new CBlockTreeDB tries to delete the existing file, which
|
||||
// fails if it's still open from the previous loop. Close it first:
|
||||
pblocktree.reset();
|
||||
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, block_tree_db_in_memory, fReset));
|
||||
|
||||
DashChainstateSetup(chainman, govman, mn_metaman, mn_sync, sporkman, mn_activeman, chain_helper, cpoolman,
|
||||
dmnman, evodb, mnhf_manager, qsnapman, llmq_ctx, mempool, fReset, fReindexChainState,
|
||||
consensus_params);
|
||||
|
||||
if (fReset) {
|
||||
pblocktree->WriteReindexing(true);
|
||||
//If we're reindexing in prune mode, wipe away unusable block files and all undo data files
|
||||
if (fPruneMode)
|
||||
CleanupBlockRevFiles();
|
||||
}
|
||||
|
||||
if (shutdown_requested && shutdown_requested()) return ChainstateLoadingError::SHUTDOWN_PROBED;
|
||||
|
||||
// LoadBlockIndex will load m_have_pruned if we've ever removed a
|
||||
// block file from disk.
|
||||
// Note that it also sets fReindex based on the disk flag!
|
||||
// From here on out fReindex and fReset mean something different!
|
||||
if (!chainman.LoadBlockIndex()) {
|
||||
if (shutdown_requested && shutdown_requested()) return ChainstateLoadingError::SHUTDOWN_PROBED;
|
||||
return ChainstateLoadingError::ERROR_LOADING_BLOCK_DB;
|
||||
}
|
||||
|
||||
// TODO: Remove this when pruning is fixed.
|
||||
// See https://github.com/dashpay/dash/pull/1817 and https://github.com/dashpay/dash/pull/1743
|
||||
if (is_governance_enabled && !is_txindex_enabled && network_id != CBaseChainParams::REGTEST) {
|
||||
return ChainstateLoadingError::ERROR_TXINDEX_DISABLED_WHEN_GOV_ENABLED;
|
||||
}
|
||||
|
||||
if (!chainman.BlockIndex().empty() &&
|
||||
!chainman.m_blockman.LookupBlockIndex(consensus_params.hashGenesisBlock)) {
|
||||
return ChainstateLoadingError::ERROR_BAD_GENESIS_BLOCK;
|
||||
}
|
||||
|
||||
if (!consensus_params.hashDevnetGenesisBlock.IsNull() && !chainman.BlockIndex().empty() &&
|
||||
!chainman.m_blockman.LookupBlockIndex(consensus_params.hashDevnetGenesisBlock)) {
|
||||
return ChainstateLoadingError::ERROR_BAD_DEVNET_GENESIS_BLOCK;
|
||||
}
|
||||
|
||||
if (!fReset && !fReindexChainState) {
|
||||
// Check for changed -addressindex state
|
||||
if (!fAddressIndex && fAddressIndex != is_addrindex_enabled) {
|
||||
return ChainstateLoadingError::ERROR_ADDRIDX_NEEDS_REINDEX;
|
||||
}
|
||||
|
||||
// Check for changed -timestampindex state
|
||||
if (!fTimestampIndex && fTimestampIndex != is_timeindex_enabled) {
|
||||
return ChainstateLoadingError::ERROR_TIMEIDX_NEEDS_REINDEX;
|
||||
}
|
||||
|
||||
// Check for changed -spentindex state
|
||||
if (!fSpentIndex && fSpentIndex != is_spentindex_enabled) {
|
||||
return ChainstateLoadingError::ERROR_SPENTIDX_NEEDS_REINDEX;
|
||||
}
|
||||
}
|
||||
|
||||
chainman.InitAdditionalIndexes();
|
||||
|
||||
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
|
||||
// in the past, but is now trying to run unpruned.
|
||||
if (chainman.m_blockman.m_have_pruned && !fPruneMode) {
|
||||
return ChainstateLoadingError::ERROR_PRUNED_NEEDS_REINDEX;
|
||||
}
|
||||
|
||||
// At this point blocktree args are consistent with what's on disk.
|
||||
// If we're not mid-reindex (based on disk + args), add a genesis block on disk
|
||||
// (otherwise we use the one already on disk).
|
||||
// This is called again in ThreadImport after the reindex completes.
|
||||
if (!fReindex && !chainman.ActiveChainstate().LoadGenesisBlock()) {
|
||||
return ChainstateLoadingError::ERROR_LOAD_GENESIS_BLOCK_FAILED;
|
||||
}
|
||||
|
||||
// At this point we're either in reindex or we've loaded a useful
|
||||
// block tree into BlockIndex()!
|
||||
|
||||
for (CChainState* chainstate : chainman.GetAll()) {
|
||||
chainstate->InitCoinsDB(
|
||||
/* cache_size_bytes */ nCoinDBCache,
|
||||
/* in_memory */ coins_db_in_memory,
|
||||
/* should_wipe */ fReset || fReindexChainState);
|
||||
|
||||
if (coins_error_cb) {
|
||||
chainstate->CoinsErrorCatcher().AddReadErrCallback(coins_error_cb);
|
||||
}
|
||||
|
||||
// If necessary, upgrade from older database format.
|
||||
// This is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
|
||||
if (!chainstate->CoinsDB().Upgrade()) {
|
||||
return ChainstateLoadingError::ERROR_CHAINSTATE_UPGRADE_FAILED;
|
||||
}
|
||||
|
||||
// ReplayBlocks is a no-op if we cleared the coinsviewdb with -reindex or -reindex-chainstate
|
||||
if (!chainstate->ReplayBlocks()) {
|
||||
return ChainstateLoadingError::ERROR_REPLAYBLOCKS_FAILED;
|
||||
}
|
||||
|
||||
// The on-disk coinsdb is now in a good state, create the cache
|
||||
chainstate->InitCoinsCache(nCoinCacheUsage);
|
||||
assert(chainstate->CanFlushToDisk());
|
||||
|
||||
// flush evodb
|
||||
// TODO: CEvoDB instance should probably be a part of CChainState
|
||||
// (for multiple chainstates to actually work in parallel)
|
||||
// and not a global
|
||||
if (&chainman.ActiveChainstate() == chainstate && !evodb->CommitRootTransaction()) {
|
||||
return ChainstateLoadingError::ERROR_COMMITING_EVO_DB;
|
||||
}
|
||||
|
||||
if (!is_coinsview_empty(chainstate)) {
|
||||
// LoadChainTip initializes the chain based on CoinsTip()'s best block
|
||||
if (!chainstate->LoadChainTip()) {
|
||||
return ChainstateLoadingError::ERROR_LOADCHAINTIP_FAILED;
|
||||
}
|
||||
assert(chainstate->m_chain.Tip() != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (!dmnman->MigrateDBIfNeeded() || !dmnman->MigrateDBIfNeeded2()) {
|
||||
return ChainstateLoadingError::ERROR_UPGRADING_EVO_DB;
|
||||
}
|
||||
if (!mnhf_manager->ForceSignalDBUpdate()) {
|
||||
return ChainstateLoadingError::ERROR_UPGRADING_SIGNALS_DB;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void DashChainstateSetup(ChainstateManager& chainman,
|
||||
CGovernanceManager& govman,
|
||||
CMasternodeMetaMan& mn_metaman,
|
||||
CMasternodeSync& mn_sync,
|
||||
CSporkManager& sporkman,
|
||||
std::unique_ptr<CActiveMasternodeManager>& mn_activeman,
|
||||
std::unique_ptr<CChainstateHelper>& chain_helper,
|
||||
std::unique_ptr<CCreditPoolManager>& cpoolman,
|
||||
std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||
std::unique_ptr<CEvoDB>& evodb,
|
||||
std::unique_ptr<CMNHFManager>& mnhf_manager,
|
||||
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||
CTxMemPool* mempool,
|
||||
bool fReset,
|
||||
bool fReindexChainState,
|
||||
const Consensus::Params& consensus_params)
|
||||
{
|
||||
// Same logic as pblocktree
|
||||
dmnman.reset();
|
||||
dmnman = std::make_unique<CDeterministicMNManager>(chainman.ActiveChainstate(), *evodb);
|
||||
mempool->ConnectManagers(dmnman.get());
|
||||
|
||||
cpoolman.reset();
|
||||
cpoolman = std::make_unique<CCreditPoolManager>(*evodb);
|
||||
|
||||
qsnapman.reset();
|
||||
qsnapman.reset(new llmq::CQuorumSnapshotManager(*evodb));
|
||||
|
||||
if (llmq_ctx) {
|
||||
llmq_ctx->Interrupt();
|
||||
llmq_ctx->Stop();
|
||||
}
|
||||
llmq_ctx.reset();
|
||||
llmq_ctx = std::make_unique<LLMQContext>(chainman, *dmnman, *evodb, mn_metaman, *mnhf_manager, sporkman,
|
||||
*mempool, mn_activeman.get(), mn_sync, /*unit_tests=*/false, /*wipe=*/fReset || fReindexChainState);
|
||||
// Enable CMNHFManager::{Process, Undo}Block
|
||||
mnhf_manager->ConnectManagers(&chainman, llmq_ctx->qman.get());
|
||||
|
||||
chain_helper.reset();
|
||||
chain_helper = std::make_unique<CChainstateHelper>(*cpoolman, *dmnman, *mnhf_manager, govman, *(llmq_ctx->quorum_block_processor), chainman,
|
||||
consensus_params, mn_sync, sporkman, *(llmq_ctx->clhandler), *(llmq_ctx->qman));
|
||||
}
|
||||
|
||||
void DashChainstateSetupClose(std::unique_ptr<CChainstateHelper>& chain_helper,
|
||||
std::unique_ptr<CCreditPoolManager>& cpoolman,
|
||||
std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||
std::unique_ptr<CMNHFManager>& mnhf_manager,
|
||||
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||
CTxMemPool* mempool)
|
||||
|
||||
{
|
||||
chain_helper.reset();
|
||||
if (mnhf_manager) {
|
||||
mnhf_manager->DisconnectManagers();
|
||||
}
|
||||
llmq_ctx.reset();
|
||||
qsnapman.reset();
|
||||
cpoolman.reset();
|
||||
mempool->DisconnectManagers();
|
||||
dmnman.reset();
|
||||
}
|
||||
|
||||
std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManager& chainman,
|
||||
CEvoDB& evodb,
|
||||
bool fReset,
|
||||
bool fReindexChainState,
|
||||
const Consensus::Params& consensus_params,
|
||||
unsigned int check_blocks,
|
||||
unsigned int check_level,
|
||||
std::function<int64_t()> get_unix_time_seconds,
|
||||
std::function<void(bool)> notify_bls_state)
|
||||
{
|
||||
auto is_coinsview_empty = [&](CChainState* chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
|
||||
return fReset || fReindexChainState || chainstate->CoinsTip().GetBestBlock().IsNull();
|
||||
};
|
||||
|
||||
LOCK(cs_main);
|
||||
|
||||
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) {
|
||||
return ChainstateLoadVerifyError::ERROR_BLOCK_FROM_FUTURE;
|
||||
}
|
||||
const bool v19active{DeploymentActiveAfter(tip, consensus_params, Consensus::DEPLOYMENT_V19)};
|
||||
if (v19active) {
|
||||
bls::bls_legacy_scheme.store(false);
|
||||
if (notify_bls_state) notify_bls_state(bls::bls_legacy_scheme.load());
|
||||
}
|
||||
|
||||
if (!CVerifyDB().VerifyDB(
|
||||
*chainstate, consensus_params, chainstate->CoinsDB(),
|
||||
evodb,
|
||||
check_level,
|
||||
check_blocks)) {
|
||||
return ChainstateLoadVerifyError::ERROR_CORRUPTED_BLOCK_DB;
|
||||
}
|
||||
|
||||
// VerifyDB() disconnects blocks which might result in us switching back to legacy.
|
||||
// Make sure we use the right scheme.
|
||||
if (v19active && bls::bls_legacy_scheme.load()) {
|
||||
bls::bls_legacy_scheme.store(false);
|
||||
if (notify_bls_state) notify_bls_state(bls::bls_legacy_scheme.load());
|
||||
}
|
||||
|
||||
if (check_level >= 3) {
|
||||
chainstate->ResetBlockFailureFlags(nullptr);
|
||||
}
|
||||
|
||||
} else {
|
||||
// TODO: CEvoDB instance should probably be a part of CChainState
|
||||
// (for multiple chainstates to actually work in parallel)
|
||||
// and not a global
|
||||
if (&chainman.ActiveChainstate() == chainstate && !evodb.IsEmpty()) {
|
||||
// EvoDB processed some blocks earlier but we have no blocks anymore, something is wrong
|
||||
return ChainstateLoadVerifyError::ERROR_EVO_DB_SANITY_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
162
src/node/chainstate.h
Normal file
162
src/node/chainstate.h
Normal file
@ -0,0 +1,162 @@
|
||||
// Copyright (c) 2021 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_NODE_CHAINSTATE_H
|
||||
#define BITCOIN_NODE_CHAINSTATE_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
class CActiveMasternodeManager;
|
||||
class CChainstateHelper;
|
||||
class CCreditPoolManager;
|
||||
class CDeterministicMNManager;
|
||||
class CEvoDB;
|
||||
class CGovernanceManager;
|
||||
class ChainstateManager;
|
||||
class CMasternodeMetaMan;
|
||||
class CMasternodeSync;
|
||||
class CMNHFManager;
|
||||
class CSporkManager;
|
||||
class CTxMemPool;
|
||||
struct LLMQContext;
|
||||
|
||||
namespace llmq {
|
||||
class CChainLocksHandler;
|
||||
class CInstantSendManager;
|
||||
class CQuorumSnapshotManager;
|
||||
}
|
||||
|
||||
namespace Consensus {
|
||||
struct Params;
|
||||
}
|
||||
|
||||
enum class ChainstateLoadingError {
|
||||
ERROR_LOADING_BLOCK_DB,
|
||||
ERROR_BAD_GENESIS_BLOCK,
|
||||
ERROR_BAD_DEVNET_GENESIS_BLOCK,
|
||||
ERROR_TXINDEX_DISABLED_WHEN_GOV_ENABLED,
|
||||
ERROR_ADDRIDX_NEEDS_REINDEX,
|
||||
ERROR_SPENTIDX_NEEDS_REINDEX,
|
||||
ERROR_TIMEIDX_NEEDS_REINDEX,
|
||||
ERROR_PRUNED_NEEDS_REINDEX,
|
||||
ERROR_LOAD_GENESIS_BLOCK_FAILED,
|
||||
ERROR_CHAINSTATE_UPGRADE_FAILED,
|
||||
ERROR_REPLAYBLOCKS_FAILED,
|
||||
ERROR_LOADCHAINTIP_FAILED,
|
||||
ERROR_GENERIC_BLOCKDB_OPEN_FAILED,
|
||||
ERROR_COMMITING_EVO_DB,
|
||||
ERROR_UPGRADING_EVO_DB,
|
||||
ERROR_UPGRADING_SIGNALS_DB,
|
||||
SHUTDOWN_PROBED,
|
||||
};
|
||||
|
||||
/** This sequence can have 4 types of outcomes:
|
||||
*
|
||||
* 1. Success
|
||||
* 2. Shutdown requested
|
||||
* - nothing failed but a shutdown was triggered in the middle of the
|
||||
* sequence
|
||||
* 3. Soft failure
|
||||
* - a failure that might be recovered from with a reindex
|
||||
* 4. Hard failure
|
||||
* - a failure that definitively cannot be recovered from with a reindex
|
||||
*
|
||||
* Currently, LoadChainstate returns a std::optional<ChainstateLoadingError>
|
||||
* which:
|
||||
*
|
||||
* - if has_value()
|
||||
* - Either "Soft failure", "Hard failure", or "Shutdown requested",
|
||||
* differentiable by the specific enumerator.
|
||||
*
|
||||
* Note that a return value of SHUTDOWN_PROBED means ONLY that "during
|
||||
* 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.
|
||||
* - else
|
||||
* - Success!
|
||||
*/
|
||||
std::optional<ChainstateLoadingError> LoadChainstate(bool fReset,
|
||||
ChainstateManager& chainman,
|
||||
CGovernanceManager& govman,
|
||||
CMasternodeMetaMan& mn_metaman,
|
||||
CMasternodeSync& mn_sync,
|
||||
CSporkManager& sporkman,
|
||||
std::unique_ptr<CActiveMasternodeManager>& mn_activeman,
|
||||
std::unique_ptr<CChainstateHelper>& chain_helper,
|
||||
std::unique_ptr<CCreditPoolManager>& cpoolman,
|
||||
std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||
std::unique_ptr<CEvoDB>& evodb,
|
||||
std::unique_ptr<CMNHFManager>& mnhf_manager,
|
||||
std::unique_ptr<llmq::CChainLocksHandler>& clhandler,
|
||||
std::unique_ptr<llmq::CInstantSendManager>& isman,
|
||||
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||
CTxMemPool* mempool,
|
||||
bool fPruneMode,
|
||||
bool is_addrindex_enabled,
|
||||
bool is_governance_enabled,
|
||||
bool is_spentindex_enabled,
|
||||
bool is_timeindex_enabled,
|
||||
bool is_txindex_enabled,
|
||||
const Consensus::Params& consensus_params,
|
||||
const std::string& network_id,
|
||||
bool fReindexChainState,
|
||||
int64_t nBlockTreeDBCache,
|
||||
int64_t nCoinDBCache,
|
||||
int64_t nCoinCacheUsage,
|
||||
bool block_tree_db_in_memory,
|
||||
bool coins_db_in_memory,
|
||||
std::function<bool()> shutdown_requested = nullptr,
|
||||
std::function<void()> coins_error_cb = nullptr);
|
||||
|
||||
/** Initialize Dash-specific components during chainstate initialization */
|
||||
void DashChainstateSetup(ChainstateManager& chainman,
|
||||
CGovernanceManager& govman,
|
||||
CMasternodeMetaMan& mn_metaman,
|
||||
CMasternodeSync& mn_sync,
|
||||
CSporkManager& sporkman,
|
||||
std::unique_ptr<CActiveMasternodeManager>& mn_activeman,
|
||||
std::unique_ptr<CChainstateHelper>& chain_helper,
|
||||
std::unique_ptr<CCreditPoolManager>& cpoolman,
|
||||
std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||
std::unique_ptr<CEvoDB>& evodb,
|
||||
std::unique_ptr<CMNHFManager>& mnhf_manager,
|
||||
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||
CTxMemPool* mempool,
|
||||
bool fReset,
|
||||
bool fReindexChainState,
|
||||
const Consensus::Params& consensus_params);
|
||||
|
||||
void DashChainstateSetupClose(std::unique_ptr<CChainstateHelper>& chain_helper,
|
||||
std::unique_ptr<CCreditPoolManager>& cpoolman,
|
||||
std::unique_ptr<CDeterministicMNManager>& dmnman,
|
||||
std::unique_ptr<CMNHFManager>& mnhf_manager,
|
||||
std::unique_ptr<llmq::CQuorumSnapshotManager>& qsnapman,
|
||||
std::unique_ptr<LLMQContext>& llmq_ctx,
|
||||
CTxMemPool* mempool);
|
||||
|
||||
enum class ChainstateLoadVerifyError {
|
||||
ERROR_BLOCK_FROM_FUTURE,
|
||||
ERROR_CORRUPTED_BLOCK_DB,
|
||||
ERROR_EVO_DB_SANITY_FAILED,
|
||||
ERROR_GENERIC_FAILURE,
|
||||
};
|
||||
|
||||
std::optional<ChainstateLoadVerifyError> VerifyLoadedChainstate(ChainstateManager& chainman,
|
||||
CEvoDB& evodb,
|
||||
bool fReset,
|
||||
bool fReindexChainState,
|
||||
const Consensus::Params& consensus_params,
|
||||
unsigned int check_blocks,
|
||||
unsigned int check_level,
|
||||
std::function<int64_t()> get_unix_time_seconds,
|
||||
std::function<void(bool)> notify_bls_state = nullptr);
|
||||
|
||||
#endif // BITCOIN_NODE_CHAINSTATE_H
|
@ -6,12 +6,12 @@
|
||||
#define BITCOIN_PREVECTOR_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
@ -47,26 +47,28 @@ public:
|
||||
typedef const value_type* const_pointer;
|
||||
|
||||
class iterator {
|
||||
T* ptr;
|
||||
T* ptr{};
|
||||
public:
|
||||
typedef Diff difference_type;
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef T& reference;
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
using element_type = T;
|
||||
using iterator_category = std::contiguous_iterator_tag;
|
||||
iterator() = default;
|
||||
iterator(T* ptr_) : ptr(ptr_) {}
|
||||
T& operator*() const { return *ptr; }
|
||||
T* operator->() const { return ptr; }
|
||||
T& operator[](size_type pos) { return ptr[pos]; }
|
||||
const T& operator[](size_type pos) const { return ptr[pos]; }
|
||||
T& operator[](size_type pos) const { return ptr[pos]; }
|
||||
iterator& operator++() { ptr++; return *this; }
|
||||
iterator& operator--() { ptr--; return *this; }
|
||||
iterator operator++(int) { iterator copy(*this); ++(*this); return copy; }
|
||||
iterator operator--(int) { iterator copy(*this); --(*this); return copy; }
|
||||
difference_type friend operator-(iterator a, iterator b) { return (&(*a) - &(*b)); }
|
||||
iterator operator+(size_type n) { return iterator(ptr + n); }
|
||||
iterator operator+(size_type n) const { return iterator(ptr + n); }
|
||||
iterator friend operator+(size_type n, iterator x) { return x + n; }
|
||||
iterator& operator+=(size_type n) { ptr += n; return *this; }
|
||||
iterator operator-(size_type n) { return iterator(ptr - n); }
|
||||
iterator operator-(size_type n) const { return iterator(ptr - n); }
|
||||
iterator& operator-=(size_type n) { ptr -= n; return *this; }
|
||||
bool operator==(iterator x) const { return ptr == x.ptr; }
|
||||
bool operator!=(iterator x) const { return ptr != x.ptr; }
|
||||
@ -77,18 +79,17 @@ public:
|
||||
};
|
||||
|
||||
class reverse_iterator {
|
||||
T* ptr;
|
||||
T* ptr{};
|
||||
public:
|
||||
typedef Diff difference_type;
|
||||
typedef T value_type;
|
||||
typedef T* pointer;
|
||||
typedef T& reference;
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
reverse_iterator() = default;
|
||||
reverse_iterator(T* ptr_) : ptr(ptr_) {}
|
||||
T& operator*() { return *ptr; }
|
||||
const T& operator*() const { return *ptr; }
|
||||
T* operator->() { return ptr; }
|
||||
const T* operator->() const { return ptr; }
|
||||
T& operator*() const { return *ptr; }
|
||||
T* operator->() const { return ptr; }
|
||||
reverse_iterator& operator--() { ptr++; return *this; }
|
||||
reverse_iterator& operator++() { ptr--; return *this; }
|
||||
reverse_iterator operator++(int) { reverse_iterator copy(*this); ++(*this); return copy; }
|
||||
@ -98,13 +99,15 @@ public:
|
||||
};
|
||||
|
||||
class const_iterator {
|
||||
const T* ptr;
|
||||
const T* ptr{};
|
||||
public:
|
||||
typedef Diff difference_type;
|
||||
typedef const T value_type;
|
||||
typedef const T* pointer;
|
||||
typedef const T& reference;
|
||||
typedef std::random_access_iterator_tag iterator_category;
|
||||
using element_type = const T;
|
||||
using iterator_category = std::contiguous_iterator_tag;
|
||||
const_iterator() = default;
|
||||
const_iterator(const T* ptr_) : ptr(ptr_) {}
|
||||
const_iterator(iterator x) : ptr(&(*x)) {}
|
||||
const T& operator*() const { return *ptr; }
|
||||
@ -115,9 +118,10 @@ public:
|
||||
const_iterator operator++(int) { const_iterator copy(*this); ++(*this); return copy; }
|
||||
const_iterator operator--(int) { const_iterator copy(*this); --(*this); return copy; }
|
||||
difference_type friend operator-(const_iterator a, const_iterator b) { return (&(*a) - &(*b)); }
|
||||
const_iterator operator+(size_type n) { return const_iterator(ptr + n); }
|
||||
const_iterator operator+(size_type n) const { return const_iterator(ptr + n); }
|
||||
const_iterator friend operator+(size_type n, const_iterator x) { return x + n; }
|
||||
const_iterator& operator+=(size_type n) { ptr += n; return *this; }
|
||||
const_iterator operator-(size_type n) { return const_iterator(ptr - n); }
|
||||
const_iterator operator-(size_type n) const { return const_iterator(ptr - n); }
|
||||
const_iterator& operator-=(size_type n) { ptr -= n; return *this; }
|
||||
bool operator==(const_iterator x) const { return ptr == x.ptr; }
|
||||
bool operator!=(const_iterator x) const { return ptr != x.ptr; }
|
||||
@ -128,13 +132,14 @@ public:
|
||||
};
|
||||
|
||||
class const_reverse_iterator {
|
||||
const T* ptr;
|
||||
const T* ptr{};
|
||||
public:
|
||||
typedef Diff difference_type;
|
||||
typedef const T value_type;
|
||||
typedef const T* pointer;
|
||||
typedef const T& reference;
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
const_reverse_iterator() = default;
|
||||
const_reverse_iterator(const T* ptr_) : ptr(ptr_) {}
|
||||
const_reverse_iterator(reverse_iterator x) : ptr(&(*x)) {}
|
||||
const T& operator*() const { return *ptr; }
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <util/system.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstdio>
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QLabel>
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include <thread>
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <span.h>
|
||||
#include <uint256.h>
|
||||
|
||||
#include <bit>
|
||||
#include <cassert>
|
||||
#include <chrono> // For std::chrono::microseconds
|
||||
#include <cstdint>
|
||||
@ -196,7 +197,7 @@ public:
|
||||
{
|
||||
assert(range);
|
||||
--range;
|
||||
int bits = CountBits(range);
|
||||
int bits = std::bit_width(range);
|
||||
while (true) {
|
||||
uint64_t ret = randbits(bits);
|
||||
if (ret <= range) return ret;
|
||||
|
@ -1642,7 +1642,7 @@ static RPCHelpMan verifychain()
|
||||
|
||||
CChainState& active_chainstate = chainman.ActiveChainstate();
|
||||
return CVerifyDB().VerifyDB(
|
||||
active_chainstate, Params(), active_chainstate.CoinsTip(), *CHECK_NONFATAL(node.evodb), check_level, check_depth);
|
||||
active_chainstate, Params().GetConsensus(), active_chainstate.CoinsTip(), *CHECK_NONFATAL(node.evodb), check_level, check_depth);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -60,27 +60,27 @@ template<typename Stream> inline void ser_writedata8(Stream &s, uint8_t obj)
|
||||
}
|
||||
template<typename Stream> inline void ser_writedata16(Stream &s, uint16_t obj)
|
||||
{
|
||||
obj = htole16(obj);
|
||||
obj = htole16_internal(obj);
|
||||
s.write(AsBytes(Span{&obj, 1}));
|
||||
}
|
||||
template<typename Stream> inline void ser_writedata16be(Stream &s, uint16_t obj)
|
||||
{
|
||||
obj = htobe16(obj);
|
||||
obj = htobe16_internal(obj);
|
||||
s.write(AsBytes(Span{&obj, 1}));
|
||||
}
|
||||
template<typename Stream> inline void ser_writedata32(Stream &s, uint32_t obj)
|
||||
{
|
||||
obj = htole32(obj);
|
||||
obj = htole32_internal(obj);
|
||||
s.write(AsBytes(Span{&obj, 1}));
|
||||
}
|
||||
template<typename Stream> inline void ser_writedata32be(Stream &s, uint32_t obj)
|
||||
{
|
||||
obj = htobe32(obj);
|
||||
obj = htobe32_internal(obj);
|
||||
s.write(AsBytes(Span{&obj, 1}));
|
||||
}
|
||||
template<typename Stream> inline void ser_writedata64(Stream &s, uint64_t obj)
|
||||
{
|
||||
obj = htole64(obj);
|
||||
obj = htole64_internal(obj);
|
||||
s.write(AsBytes(Span{&obj, 1}));
|
||||
}
|
||||
template<typename Stream> inline uint8_t ser_readdata8(Stream &s)
|
||||
@ -93,31 +93,31 @@ template<typename Stream> inline uint16_t ser_readdata16(Stream &s)
|
||||
{
|
||||
uint16_t obj;
|
||||
s.read(AsWritableBytes(Span{&obj, 1}));
|
||||
return le16toh(obj);
|
||||
return le16toh_internal(obj);
|
||||
}
|
||||
template<typename Stream> inline uint16_t ser_readdata16be(Stream &s)
|
||||
{
|
||||
uint16_t obj;
|
||||
s.read(AsWritableBytes(Span{&obj, 1}));
|
||||
return be16toh(obj);
|
||||
return be16toh_internal(obj);
|
||||
}
|
||||
template<typename Stream> inline uint32_t ser_readdata32(Stream &s)
|
||||
{
|
||||
uint32_t obj;
|
||||
s.read(AsWritableBytes(Span{&obj, 1}));
|
||||
return le32toh(obj);
|
||||
return le32toh_internal(obj);
|
||||
}
|
||||
template<typename Stream> inline uint32_t ser_readdata32be(Stream &s)
|
||||
{
|
||||
uint32_t obj;
|
||||
s.read(AsWritableBytes(Span{&obj, 1}));
|
||||
return be32toh(obj);
|
||||
return be32toh_internal(obj);
|
||||
}
|
||||
template<typename Stream> inline uint64_t ser_readdata64(Stream &s)
|
||||
{
|
||||
uint64_t obj;
|
||||
s.read(AsWritableBytes(Span{&obj, 1}));
|
||||
return le64toh(obj);
|
||||
return le64toh_internal(obj);
|
||||
}
|
||||
|
||||
|
||||
@ -655,11 +655,11 @@ struct CustomUintFormatter
|
||||
{
|
||||
if (v < 0 || v > MAX) throw std::ios_base::failure("CustomUintFormatter value out of range");
|
||||
if (BigEndian) {
|
||||
uint64_t raw = htobe64(v);
|
||||
s.write({BytePtr(&raw) + 8 - Bytes, Bytes});
|
||||
uint64_t raw = htobe64_internal(v);
|
||||
s.write(AsBytes(Span{&raw, 1}).last(Bytes));
|
||||
} else {
|
||||
uint64_t raw = htole64(v);
|
||||
s.write({BytePtr(&raw), Bytes});
|
||||
uint64_t raw = htole64_internal(v);
|
||||
s.write(AsBytes(Span{&raw, 1}).first(Bytes));
|
||||
}
|
||||
}
|
||||
|
||||
@ -669,11 +669,11 @@ struct CustomUintFormatter
|
||||
static_assert(std::numeric_limits<U>::max() >= MAX && std::numeric_limits<U>::min() <= 0, "Assigned type too small");
|
||||
uint64_t raw = 0;
|
||||
if (BigEndian) {
|
||||
s.read({BytePtr(&raw) + 8 - Bytes, Bytes});
|
||||
v = static_cast<I>(be64toh(raw));
|
||||
s.read(AsWritableBytes(Span{&raw, 1}).last(Bytes));
|
||||
v = static_cast<I>(be64toh_internal(raw));
|
||||
} else {
|
||||
s.read({BytePtr(&raw), Bytes});
|
||||
v = static_cast<I>(le64toh(raw));
|
||||
s.read(AsWritableBytes(Span{&raw, 1}).first(Bytes));
|
||||
v = static_cast<I>(le64toh_internal(raw));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
21
src/span.h
21
src/span.h
@ -5,10 +5,10 @@
|
||||
#ifndef BITCOIN_SPAN_H
|
||||
#define BITCOIN_SPAN_H
|
||||
|
||||
#include <type_traits>
|
||||
#include <cstddef>
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef DEBUG_CORE
|
||||
#define CONSTEXPR_IF_NOT_DEBUG
|
||||
@ -243,21 +243,16 @@ T& SpanPopBack(Span<T>& span)
|
||||
return back;
|
||||
}
|
||||
|
||||
//! Convert a data pointer to a std::byte data pointer.
|
||||
//! Where possible, please use the safer AsBytes helpers.
|
||||
inline const std::byte* BytePtr(const void* data) { return reinterpret_cast<const std::byte*>(data); }
|
||||
inline std::byte* BytePtr(void* data) { return reinterpret_cast<std::byte*>(data); }
|
||||
|
||||
// From C++20 as_bytes and as_writeable_bytes
|
||||
template <typename T>
|
||||
Span<const std::byte> AsBytes(Span<T> s) noexcept
|
||||
{
|
||||
return {BytePtr(s.data()), s.size_bytes()};
|
||||
return {reinterpret_cast<const std::byte*>(s.data()), s.size_bytes()};
|
||||
}
|
||||
template <typename T>
|
||||
Span<std::byte> AsWritableBytes(Span<T> s) noexcept
|
||||
{
|
||||
return {BytePtr(s.data()), s.size_bytes()};
|
||||
return {reinterpret_cast<std::byte*>(s.data()), s.size_bytes()};
|
||||
}
|
||||
|
||||
template <typename V>
|
||||
@ -272,10 +267,10 @@ Span<std::byte> MakeWritableByteSpan(V&& v) noexcept
|
||||
}
|
||||
|
||||
// Helper functions to safely cast to unsigned char pointers.
|
||||
inline unsigned char* UCharCast(char* c) { return (unsigned char*)c; }
|
||||
inline unsigned char* UCharCast(char* c) { return reinterpret_cast<unsigned char*>(c); }
|
||||
inline unsigned char* UCharCast(unsigned char* c) { return c; }
|
||||
inline unsigned char* UCharCast(std::byte* c) { return (unsigned char*)c; }
|
||||
inline const unsigned char* UCharCast(const char* c) { return (unsigned char*)c; }
|
||||
inline unsigned char* UCharCast(std::byte* c) { return reinterpret_cast<unsigned char*>(c); }
|
||||
inline const unsigned char* UCharCast(const char* c) { return reinterpret_cast<const unsigned char*>(c); }
|
||||
inline const unsigned char* UCharCast(const unsigned char* c) { return c; }
|
||||
inline const unsigned char* UCharCast(const std::byte* c) { return reinterpret_cast<const unsigned char*>(c); }
|
||||
|
||||
|
@ -13,11 +13,11 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
#include <cstdio>
|
||||
#include <ios>
|
||||
#include <limits>
|
||||
#include <optional>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
@ -6,7 +6,7 @@
|
||||
#ifndef BITCOIN_SUPPORT_CLEANSE_H
|
||||
#define BITCOIN_SUPPORT_CLEANSE_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
|
||||
/** Secure overwrite a buffer (possibly containing secret data) with zero-bytes. The write
|
||||
* operation will not be optimized out by the compiler. */
|
||||
|
1043
src/test/argsman_tests.cpp
Normal file
1043
src/test/argsman_tests.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -4,13 +4,13 @@
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <chain.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/string.h>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
/* Equality between doubles is imprecise. Comparison should be done
|
||||
* with a small threshold of tolerance, rather than exact equality.
|
||||
*/
|
||||
|
@ -16,9 +16,9 @@ BOOST_AUTO_TEST_CASE(bswap_tests)
|
||||
uint16_t e1 = 0x3412;
|
||||
uint32_t e2 = 0xbc9a7856;
|
||||
uint64_t e3 = 0xbc9a78563412f0de;
|
||||
BOOST_CHECK(bswap_16(u1) == e1);
|
||||
BOOST_CHECK(bswap_32(u2) == e2);
|
||||
BOOST_CHECK(bswap_64(u3) == e3);
|
||||
BOOST_CHECK(internal_bswap_16(u1) == e1);
|
||||
BOOST_CHECK(internal_bswap_32(u2) == e2);
|
||||
BOOST_CHECK(internal_bswap_64(u3) == e3);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -1083,28 +1083,6 @@ BOOST_AUTO_TEST_CASE(hkdf_hmac_sha256_l32_tests)
|
||||
"8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(countbits_tests)
|
||||
{
|
||||
FastRandomContext ctx;
|
||||
for (unsigned int i = 0; i <= 64; ++i) {
|
||||
if (i == 0) {
|
||||
// Check handling of zero.
|
||||
BOOST_CHECK_EQUAL(CountBits(0), 0U);
|
||||
} else if (i < 10) {
|
||||
for (uint64_t j = (uint64_t)1 << (i - 1); (j >> i) == 0; ++j) {
|
||||
// Exhaustively test up to 10 bits
|
||||
BOOST_CHECK_EQUAL(CountBits(j), i);
|
||||
}
|
||||
} else {
|
||||
for (int k = 0; k < 1000; k++) {
|
||||
// Randomly test 1000 samples of each length above 10 bits.
|
||||
uint64_t j = ((uint64_t)1) << (i - 1) | ctx.randbits(i - 1);
|
||||
BOOST_CHECK_EQUAL(CountBits(j), i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(sha256d64)
|
||||
{
|
||||
for (int i = 0; i <= 32; ++i) {
|
||||
|
@ -816,8 +816,8 @@ void FuncVerifyDB(TestChainSetup& setup)
|
||||
|
||||
// Verify db consistency
|
||||
LOCK(cs_main);
|
||||
BOOST_REQUIRE(CVerifyDB().VerifyDB(chainman.ActiveChainstate(), Params(), chainman.ActiveChainstate().CoinsTip(),
|
||||
*(setup.m_node.evodb), 4, 2));
|
||||
BOOST_REQUIRE(CVerifyDB().VerifyDB(chainman.ActiveChainstate(), Params().GetConsensus(),
|
||||
chainman.ActiveChainstate().CoinsTip(), *(setup.m_node.evodb), 4, 2));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(evo_dip3_activation_tests)
|
||||
|
@ -75,7 +75,6 @@ FUZZ_TARGET_INIT(integer, initialize_integer)
|
||||
static const uint256 u256_max(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
|
||||
const std::vector<uint256> v256{u256, u256_min, u256_max};
|
||||
(void)ComputeMerkleRoot(v256);
|
||||
(void)CountBits(u64);
|
||||
(void)DecompressAmount(u64);
|
||||
{
|
||||
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
#include <event2/event.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <map>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <support/events.h>
|
||||
|
||||
|
@ -30,6 +30,8 @@
|
||||
#include <net.h>
|
||||
#include <net_processing.h>
|
||||
#include <noui.h>
|
||||
#include <node/blockstorage.h>
|
||||
#include <node/chainstate.h>
|
||||
#include <node/miner.h>
|
||||
#include <policy/fees.h>
|
||||
#include <pow.h>
|
||||
@ -38,6 +40,7 @@
|
||||
#include <rpc/server.h>
|
||||
#include <scheduler.h>
|
||||
#include <script/sigcache.h>
|
||||
#include <shutdown.h>
|
||||
#include <spork.h>
|
||||
#include <stats/client.h>
|
||||
#include <streams.h>
|
||||
@ -103,37 +106,38 @@ std::ostream& operator<<(std::ostream& os, const uint256& num)
|
||||
return os;
|
||||
}
|
||||
|
||||
void DashTestSetup(NodeContext& node, const CChainParams& chainparams)
|
||||
void DashChainstateSetup(ChainstateManager& chainman,
|
||||
NodeContext& node,
|
||||
bool fReset,
|
||||
bool fReindexChainState,
|
||||
const Consensus::Params& consensus_params)
|
||||
{
|
||||
CChainState& chainstate = Assert(node.chainman)->ActiveChainstate();
|
||||
DashChainstateSetup(chainman, *Assert(node.govman.get()), *Assert(node.mn_metaman.get()), *Assert(node.mn_sync.get()),
|
||||
*Assert(node.sporkman.get()), node.mn_activeman, node.chain_helper, node.cpoolman, node.dmnman,
|
||||
node.evodb, node.mnhf_manager, llmq::quorumSnapshotManager, node.llmq_ctx,
|
||||
Assert(node.mempool.get()), fReset, fReindexChainState, consensus_params);
|
||||
}
|
||||
|
||||
node.dmnman = std::make_unique<CDeterministicMNManager>(chainstate, *node.evodb);
|
||||
node.mempool->ConnectManagers(node.dmnman.get());
|
||||
void DashChainstateSetupClose(NodeContext& node)
|
||||
{
|
||||
DashChainstateSetupClose(node.chain_helper, node.cpoolman, node.dmnman, node.mnhf_manager,
|
||||
llmq::quorumSnapshotManager, node.llmq_ctx, Assert(node.mempool.get()));
|
||||
}
|
||||
|
||||
void DashPostChainstateSetup(NodeContext& node)
|
||||
{
|
||||
node.cj_ctx = std::make_unique<CJContext>(*node.chainman, *node.connman, *node.dmnman, *node.mn_metaman, *node.mempool,
|
||||
/*mn_activeman=*/nullptr, *node.mn_sync, node.peerman, /*relay_txes=*/true);
|
||||
#ifdef ENABLE_WALLET
|
||||
node.coinjoin_loader = interfaces::MakeCoinJoinLoader(*node.cj_ctx->walletman);
|
||||
#endif // ENABLE_WALLET
|
||||
node.llmq_ctx = std::make_unique<LLMQContext>(*node.chainman, *node.dmnman, *node.evodb, *node.mn_metaman, *node.mnhf_manager, *node.sporkman, *node.mempool,
|
||||
/*mn_activeman=*/nullptr, *node.mn_sync, /*unit_tests=*/true, /*wipe=*/false);
|
||||
Assert(node.mnhf_manager)->ConnectManagers(node.chainman.get(), node.llmq_ctx->qman.get());
|
||||
node.chain_helper = std::make_unique<CChainstateHelper>(*node.cpoolman, *node.dmnman, *node.mnhf_manager, *node.govman, *(node.llmq_ctx->quorum_block_processor), *node.chainman,
|
||||
chainparams.GetConsensus(), *node.mn_sync, *node.sporkman, *(node.llmq_ctx->clhandler), *(node.llmq_ctx->qman));
|
||||
}
|
||||
|
||||
void DashTestSetupClose(NodeContext& node)
|
||||
void DashPostChainstateSetupClose(NodeContext& node)
|
||||
{
|
||||
node.chain_helper.reset();
|
||||
node.llmq_ctx->Interrupt();
|
||||
node.llmq_ctx->Stop();
|
||||
Assert(node.mnhf_manager)->DisconnectManagers();
|
||||
node.llmq_ctx.reset();
|
||||
#ifdef ENABLE_WALLET
|
||||
node.coinjoin_loader.reset();
|
||||
#endif // ENABLE_WALLET
|
||||
node.mempool->DisconnectManagers();
|
||||
node.dmnman.reset();
|
||||
node.cj_ctx.reset();
|
||||
}
|
||||
|
||||
@ -240,8 +244,10 @@ ChainTestingSetup::ChainTestingSetup(const std::string& chainName, const std::ve
|
||||
m_node.fee_estimator = std::make_unique<CBlockPolicyEstimator>();
|
||||
m_node.mempool = std::make_unique<CTxMemPool>(m_node.fee_estimator.get(), 1);
|
||||
|
||||
m_cache_sizes = CalculateCacheSizes(m_args);
|
||||
|
||||
m_node.chainman = std::make_unique<ChainstateManager>();
|
||||
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(1 << 20, true);
|
||||
m_node.chainman->m_blockman.m_block_tree_db = std::make_unique<CBlockTreeDB>(m_cache_sizes.block_tree_db, true);
|
||||
|
||||
m_node.mn_metaman = std::make_unique<CMasternodeMetaMan>();
|
||||
m_node.netfulfilledman = std::make_unique<CNetFulfilledRequestManager>();
|
||||
@ -280,19 +286,38 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
|
||||
// instead of unit tests, but for now we need these here.
|
||||
RegisterAllCoreRPCCommands(tableRPC);
|
||||
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
|
||||
m_node.chainman->InitializeChainstate(m_node.mempool.get(), *m_node.evodb, m_node.chain_helper, llmq::chainLocksHandler, llmq::quorumInstantSendManager);
|
||||
m_node.chainman->ActiveChainstate().InitCoinsDB(
|
||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false);
|
||||
assert(!m_node.chainman->ActiveChainstate().CanFlushToDisk());
|
||||
m_node.chainman->ActiveChainstate().InitCoinsCache(1 << 23);
|
||||
assert(m_node.chainman->ActiveChainstate().CanFlushToDisk());
|
||||
if (!m_node.chainman->ActiveChainstate().LoadGenesisBlock()) {
|
||||
throw std::runtime_error("LoadGenesisBlock failed.");
|
||||
}
|
||||
}
|
||||
auto rv = LoadChainstate(fReindex.load(),
|
||||
*Assert(m_node.chainman.get()),
|
||||
*Assert(m_node.govman.get()),
|
||||
*Assert(m_node.mn_metaman.get()),
|
||||
*Assert(m_node.mn_sync.get()),
|
||||
*Assert(m_node.sporkman.get()),
|
||||
m_node.mn_activeman,
|
||||
m_node.chain_helper,
|
||||
m_node.cpoolman,
|
||||
m_node.dmnman,
|
||||
m_node.evodb,
|
||||
m_node.mnhf_manager,
|
||||
llmq::chainLocksHandler,
|
||||
llmq::quorumInstantSendManager,
|
||||
llmq::quorumSnapshotManager,
|
||||
m_node.llmq_ctx,
|
||||
Assert(m_node.mempool.get()),
|
||||
fPruneMode,
|
||||
m_args.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX),
|
||||
!m_args.GetBoolArg("-disablegovernance", !DEFAULT_GOVERNANCE_ENABLE),
|
||||
m_args.GetBoolArg("-spentindex", DEFAULT_SPENTINDEX),
|
||||
m_args.GetBoolArg("-timestampindex", DEFAULT_TIMESTAMPINDEX),
|
||||
m_args.GetBoolArg("-txindex", DEFAULT_TXINDEX),
|
||||
chainparams.GetConsensus(),
|
||||
chainparams.NetworkIDString(),
|
||||
m_args.GetBoolArg("-reindex-chainstate", false),
|
||||
m_cache_sizes.block_tree_db,
|
||||
m_cache_sizes.coins_db,
|
||||
m_cache_sizes.coins,
|
||||
/*block_tree_db_in_memory=*/true,
|
||||
/*coins_db_in_memory=*/true);
|
||||
assert(!rv.has_value());
|
||||
|
||||
m_node.banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||
m_node.peerman = PeerManager::make(chainparams, *m_node.connman, *m_node.addrman, m_node.banman.get(),
|
||||
@ -305,7 +330,7 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
|
||||
m_node.connman->Init(options);
|
||||
}
|
||||
|
||||
DashTestSetup(m_node, chainparams);
|
||||
DashPostChainstateSetup(m_node);
|
||||
|
||||
BlockValidationState state;
|
||||
if (!m_node.chainman->ActiveChainstate().ActivateBestChain(state)) {
|
||||
@ -315,8 +340,21 @@ TestingSetup::TestingSetup(const std::string& chainName, const std::vector<const
|
||||
|
||||
TestingSetup::~TestingSetup()
|
||||
{
|
||||
DashTestSetupClose(m_node);
|
||||
m_node.connman->Stop();
|
||||
DashPostChainstateSetupClose(m_node);
|
||||
|
||||
// Interrupt() and PrepareShutdown() routines
|
||||
if (m_node.llmq_ctx) {
|
||||
m_node.llmq_ctx->Interrupt();
|
||||
m_node.llmq_ctx->Stop();
|
||||
}
|
||||
if (m_node.connman) {
|
||||
m_node.connman->Stop();
|
||||
}
|
||||
|
||||
// DashChainstateSetup() is called by LoadChainstate() internally but
|
||||
// winding them down is our responsibility
|
||||
DashChainstateSetupClose(m_node);
|
||||
|
||||
m_node.peerman.reset();
|
||||
m_node.banman.reset();
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <fs.h>
|
||||
#include <key.h>
|
||||
#include <util/system.h>
|
||||
#include <node/caches.h>
|
||||
#include <node/context.h>
|
||||
#include <pubkey.h>
|
||||
#include <random.h>
|
||||
@ -24,6 +25,9 @@
|
||||
#include <vector>
|
||||
|
||||
class CChainParams;
|
||||
namespace Consensus {
|
||||
struct Params;
|
||||
};
|
||||
|
||||
/** This is connected to the logger. Can be used to redirect logs to any other log */
|
||||
extern const std::function<void(const std::string&)> G_TEST_LOG_FUN;
|
||||
@ -79,9 +83,17 @@ static inline bool InsecureRandBool() { return g_insecure_rand_ctx.randbool(); }
|
||||
|
||||
static constexpr CAmount CENT{1000000};
|
||||
|
||||
/* Initialize Dash-specific components after chainstate initialization */
|
||||
void DashTestSetup(NodeContext& node, const CChainParams& chainparams);
|
||||
void DashTestSetupClose(NodeContext& node);
|
||||
/** Initialize Dash-specific components during chainstate initialization (NodeContext-friendly aliases) */
|
||||
void DashChainstateSetup(ChainstateManager& chainman,
|
||||
NodeContext& node,
|
||||
bool fReset,
|
||||
bool fReindexChainState,
|
||||
const Consensus::Params& consensus_params);
|
||||
void DashChainstateSetupClose(NodeContext& node);
|
||||
|
||||
/** Initialize Dash-specific components after chainstate initialization */
|
||||
void DashPostChainstateSetup(NodeContext& node);
|
||||
void DashPostChainstateSetupClose(NodeContext& node);
|
||||
|
||||
/** Basic testing setup.
|
||||
* This just configures logging, data dir and chain parameters.
|
||||
@ -101,6 +113,8 @@ struct BasicTestingSetup {
|
||||
* initialization behaviour.
|
||||
*/
|
||||
struct ChainTestingSetup : public BasicTestingSetup {
|
||||
CacheSizes m_cache_sizes{};
|
||||
|
||||
explicit ChainTestingSetup(const std::string& chainName = CBaseChainParams::MAIN, const std::vector<const char*>& extra_args = {});
|
||||
~ChainTestingSetup();
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -8,7 +8,9 @@
|
||||
#include <index/txindex.h>
|
||||
#include <llmq/blockprocessor.h>
|
||||
#include <llmq/chainlocks.h>
|
||||
#include <llmq/context.h>
|
||||
#include <llmq/instantsend.h>
|
||||
#include <node/chainstate.h>
|
||||
#include <node/utxo_snapshot.h>
|
||||
#include <random.h>
|
||||
#include <rpc/blockchain.h>
|
||||
@ -33,7 +35,7 @@ BOOST_FIXTURE_TEST_SUITE(validation_chainstatemanager_tests, ChainTestingSetup)
|
||||
//! First create a legacy (IBD) chainstate, then create a snapshot chainstate.
|
||||
BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
const Consensus::Params& consensus_params = Params().GetConsensus();
|
||||
ChainstateManager& manager = *m_node.chainman;
|
||||
CTxMemPool& mempool = *m_node.mempool;
|
||||
CEvoDB& evodb = *m_node.evodb;
|
||||
@ -49,7 +51,8 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||
/* cache_size_bytes */ 1 << 23, /* in_memory */ true, /* should_wipe */ false);
|
||||
WITH_LOCK(::cs_main, c1.InitCoinsCache(1 << 23));
|
||||
|
||||
DashTestSetup(m_node, chainparams);
|
||||
DashChainstateSetup(manager, m_node, /*fReset=*/false, /*fReindexChainState=*/false, consensus_params);
|
||||
DashPostChainstateSetup(m_node);
|
||||
|
||||
BOOST_CHECK(!manager.IsSnapshotActive());
|
||||
BOOST_CHECK(WITH_LOCK(::cs_main, return !manager.IsSnapshotValidated()));
|
||||
@ -67,7 +70,12 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||
|
||||
BOOST_CHECK(!manager.SnapshotBlockhash().has_value());
|
||||
|
||||
DashTestSetupClose(m_node);
|
||||
DashPostChainstateSetupClose(m_node);
|
||||
if (m_node.llmq_ctx) {
|
||||
m_node.llmq_ctx->Interrupt();
|
||||
m_node.llmq_ctx->Stop();
|
||||
}
|
||||
DashChainstateSetupClose(m_node);
|
||||
|
||||
// Create a snapshot-based chainstate.
|
||||
//
|
||||
@ -78,7 +86,8 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||
);
|
||||
chainstates.push_back(&c2);
|
||||
|
||||
DashTestSetup(m_node, chainparams);
|
||||
DashChainstateSetup(manager, m_node, /*fReset=*/false, /*fReindexChainState=*/false, consensus_params);
|
||||
DashPostChainstateSetup(m_node);
|
||||
|
||||
BOOST_CHECK_EQUAL(manager.SnapshotBlockhash().value(), snapshot_blockhash);
|
||||
|
||||
@ -113,7 +122,12 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
|
||||
// Let scheduler events finish running to avoid accessing memory that is going to be unloaded
|
||||
SyncWithValidationInterfaceQueue();
|
||||
|
||||
DashTestSetupClose(m_node);
|
||||
DashPostChainstateSetupClose(m_node);
|
||||
if (m_node.llmq_ctx) {
|
||||
m_node.llmq_ctx->Interrupt();
|
||||
m_node.llmq_ctx->Stop();
|
||||
}
|
||||
DashChainstateSetupClose(m_node);
|
||||
}
|
||||
|
||||
//! Test rebalancing the caches associated with each chainstate.
|
||||
|
@ -5,11 +5,11 @@
|
||||
#include <util/asmap.h>
|
||||
|
||||
#include <clientversion.h>
|
||||
#include <crypto/common.h>
|
||||
#include <fs.h>
|
||||
#include <logging.h>
|
||||
#include <streams.h>
|
||||
|
||||
#include <bit>
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
@ -108,7 +108,7 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
|
||||
} else if (opcode == Instruction::MATCH) {
|
||||
match = DecodeMatch(pos, endpos);
|
||||
if (match == INVALID) break; // Match bits straddle EOF
|
||||
matchlen = CountBits(match) - 1;
|
||||
matchlen = std::bit_width(match) - 1;
|
||||
if (bits < matchlen) break; // Not enough input bits
|
||||
for (uint32_t bit = 0; bit < matchlen; bit++) {
|
||||
if ((ip[ip.size() - bits]) != ((match >> (matchlen - 1 - bit)) & 1)) {
|
||||
@ -172,7 +172,7 @@ bool SanityCheckASMap(const std::vector<bool>& asmap, int bits)
|
||||
} else if (opcode == Instruction::MATCH) {
|
||||
uint32_t match = DecodeMatch(pos, endpos);
|
||||
if (match == INVALID) return false; // Match bits straddle EOF
|
||||
int matchlen = CountBits(match) - 1;
|
||||
int matchlen = std::bit_width(match) - 1;
|
||||
if (prevopcode != Instruction::MATCH) had_incomplete_match = false;
|
||||
if (matchlen < 8 && had_incomplete_match) return false; // Within a sequence of matches only at most one should be incomplete
|
||||
had_incomplete_match = (matchlen < 8);
|
||||
|
@ -3,11 +3,11 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <sstream>
|
||||
#include <stdio.h>
|
||||
#include <tinyformat.h>
|
||||
#include <util/bip32.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
bool ParseHDKeypath(const std::string& keypath_str, std::vector<uint32_t>& keypath)
|
||||
{
|
||||
|
@ -7,8 +7,8 @@
|
||||
|
||||
#include <fs.h>
|
||||
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
|
@ -5,7 +5,8 @@
|
||||
#include <util/url.h>
|
||||
|
||||
#include <event2/http.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
|
||||
std::string urlDecode(const std::string &urlEncoded) {
|
||||
|
@ -4139,7 +4139,7 @@ CVerifyDB::~CVerifyDB()
|
||||
|
||||
bool CVerifyDB::VerifyDB(
|
||||
CChainState& chainstate,
|
||||
const CChainParams& chainparams,
|
||||
const Consensus::Params& consensus_params,
|
||||
CCoinsView& coinsview,
|
||||
CEvoDB& evoDb,
|
||||
int nCheckLevel, int nCheckDepth)
|
||||
@ -4185,10 +4185,10 @@ bool CVerifyDB::VerifyDB(
|
||||
}
|
||||
CBlock block;
|
||||
// check level 0: read from disk
|
||||
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
|
||||
if (!ReadBlockFromDisk(block, pindex, consensus_params))
|
||||
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
// check level 1: verify block validity
|
||||
if (nCheckLevel >= 1 && !CheckBlock(block, state, chainparams.GetConsensus()))
|
||||
if (nCheckLevel >= 1 && !CheckBlock(block, state, consensus_params))
|
||||
return error("%s: *** found bad block at %d, hash=%s (%s)\n", __func__,
|
||||
pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
|
||||
// check level 2: verify undo validity
|
||||
@ -4236,7 +4236,7 @@ bool CVerifyDB::VerifyDB(
|
||||
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
|
||||
pindex = chainstate.m_chain.Next(pindex);
|
||||
CBlock block;
|
||||
if (!ReadBlockFromDisk(block, pindex, chainparams.GetConsensus()))
|
||||
if (!ReadBlockFromDisk(block, pindex, consensus_params))
|
||||
return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
if (!chainstate.ConnectBlock(block, state, pindex, coins))
|
||||
return error("VerifyDB(): *** found unconnectable block at %d, hash=%s (%s)", pindex->nHeight, pindex->GetBlockHash().ToString(), state.ToString());
|
||||
|
@ -367,7 +367,7 @@ public:
|
||||
~CVerifyDB();
|
||||
bool VerifyDB(
|
||||
CChainState& chainstate,
|
||||
const CChainParams& chainparams,
|
||||
const Consensus::Params& consensus_params,
|
||||
CCoinsView& coinsview,
|
||||
CEvoDB& evoDb,
|
||||
int nCheckLevel,
|
||||
|
@ -25,6 +25,10 @@
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
Span<const std::byte> SpanFromDbt(const BerkeleyBatch::SafeDbt& dbt)
|
||||
{
|
||||
return {reinterpret_cast<const std::byte*>(dbt.get_data()), dbt.get_size()};
|
||||
}
|
||||
|
||||
//! Make sure database has a unique fileid within the environment. If it
|
||||
//! doesn't, throw an error. BDB caches do not work properly when more than one
|
||||
@ -689,10 +693,10 @@ bool BerkeleyBatch::ReadAtCursor(CDataStream& ssKey, CDataStream& ssValue, bool&
|
||||
// Convert to streams
|
||||
ssKey.SetType(SER_DISK);
|
||||
ssKey.clear();
|
||||
ssKey.write({BytePtr(datKey.get_data()), datKey.get_size()});
|
||||
ssKey.write(SpanFromDbt(datKey));
|
||||
ssValue.SetType(SER_DISK);
|
||||
ssValue.clear();
|
||||
ssValue.write({BytePtr(datValue.get_data()), datValue.get_size()});
|
||||
ssValue.write(SpanFromDbt(datValue));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -764,7 +768,8 @@ bool BerkeleyBatch::ReadKey(CDataStream&& key, CDataStream& value)
|
||||
SafeDbt datValue;
|
||||
int ret = pdb->get(activeTxn, datKey, datValue, 0);
|
||||
if (ret == 0 && datValue.get_data() != nullptr) {
|
||||
value.write({BytePtr(datValue.get_data()), datValue.get_size()});
|
||||
value.clear();
|
||||
value.write(SpanFromDbt(datValue));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -168,6 +168,7 @@ public:
|
||||
/** RAII class that provides access to a Berkeley database */
|
||||
class BerkeleyBatch : public DatabaseBatch
|
||||
{
|
||||
public:
|
||||
/** RAII class that automatically cleanses its data on destruction */
|
||||
class SafeDbt final
|
||||
{
|
||||
|
@ -111,7 +111,7 @@ bool EncryptSecret(const CKeyingMaterial& vMasterKey, const CKeyingMaterial &vch
|
||||
memcpy(chIV.data(), &nIV, WALLET_CRYPTO_IV_SIZE);
|
||||
if(!cKeyCrypter.SetKey(vMasterKey, chIV))
|
||||
return false;
|
||||
return cKeyCrypter.Encrypt(*((const CKeyingMaterial*)&vchPlaintext), vchCiphertext);
|
||||
return cKeyCrypter.Encrypt(vchPlaintext, vchCiphertext);
|
||||
}
|
||||
|
||||
// General secure AES 256 CBC encryption routine
|
||||
|
@ -25,6 +25,12 @@ static constexpr int32_t WALLET_SCHEMA_VERSION = 0;
|
||||
static Mutex g_sqlite_mutex;
|
||||
static int g_sqlite_count GUARDED_BY(g_sqlite_mutex) = 0;
|
||||
|
||||
static Span<const std::byte> SpanFromBlob(sqlite3_stmt* stmt, int col)
|
||||
{
|
||||
return {reinterpret_cast<const std::byte*>(sqlite3_column_blob(stmt, col)),
|
||||
static_cast<size_t>(sqlite3_column_bytes(stmt, col))};
|
||||
}
|
||||
|
||||
static void ErrorLogCallback(void* arg, int code, const char* msg)
|
||||
{
|
||||
// From sqlite3_config() documentation for the SQLITE_CONFIG_LOG option:
|
||||
@ -404,9 +410,8 @@ bool SQLiteBatch::ReadKey(CDataStream&& key, CDataStream& value)
|
||||
return false;
|
||||
}
|
||||
// Leftmost column in result is index 0
|
||||
const std::byte* data{BytePtr(sqlite3_column_blob(m_read_stmt, 0))};
|
||||
size_t data_size(sqlite3_column_bytes(m_read_stmt, 0));
|
||||
value.write({data, data_size});
|
||||
value.clear();
|
||||
value.write(SpanFromBlob(m_read_stmt, 0));
|
||||
|
||||
sqlite3_clear_bindings(m_read_stmt);
|
||||
sqlite3_reset(m_read_stmt);
|
||||
@ -495,13 +500,12 @@ bool SQLiteBatch::ReadAtCursor(CDataStream& key, CDataStream& value, bool& compl
|
||||
return false;
|
||||
}
|
||||
|
||||
key.clear();
|
||||
value.clear();
|
||||
|
||||
// Leftmost column in result is index 0
|
||||
const std::byte* key_data{BytePtr(sqlite3_column_blob(m_cursor_stmt, 0))};
|
||||
size_t key_data_size(sqlite3_column_bytes(m_cursor_stmt, 0));
|
||||
key.write({key_data, key_data_size});
|
||||
const std::byte* value_data{BytePtr(sqlite3_column_blob(m_cursor_stmt, 1))};
|
||||
size_t value_data_size(sqlite3_column_bytes(m_cursor_stmt, 1));
|
||||
value.write({value_data, value_data_size});
|
||||
key.write(SpanFromBlob(m_cursor_stmt, 0));
|
||||
value.write(SpanFromBlob(m_cursor_stmt, 1));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user