mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
refactor: [index] Replace deprecated char with uint8_t in serialization
This commit is contained in:
parent
d22e7ee933
commit
fafb880e88
@ -13,7 +13,7 @@
|
|||||||
#include <validation.h> // For g_chainman
|
#include <validation.h> // For g_chainman
|
||||||
#include <warnings.h>
|
#include <warnings.h>
|
||||||
|
|
||||||
constexpr char DB_BEST_BLOCK = 'B';
|
constexpr uint8_t DB_BEST_BLOCK{'B'};
|
||||||
|
|
||||||
constexpr int64_t SYNC_LOG_INTERVAL = 30; // seconds
|
constexpr int64_t SYNC_LOG_INTERVAL = 30; // seconds
|
||||||
constexpr int64_t SYNC_LOCATOR_WRITE_INTERVAL = 30; // seconds
|
constexpr int64_t SYNC_LOCATOR_WRITE_INTERVAL = 30; // seconds
|
||||||
|
@ -24,9 +24,9 @@
|
|||||||
* as big-endian so that sequential reads of filters by height are fast.
|
* as big-endian so that sequential reads of filters by height are fast.
|
||||||
* Keys for the hash index have the type [DB_BLOCK_HASH, uint256].
|
* Keys for the hash index have the type [DB_BLOCK_HASH, uint256].
|
||||||
*/
|
*/
|
||||||
constexpr char DB_BLOCK_HASH = 's';
|
constexpr uint8_t DB_BLOCK_HASH{'s'};
|
||||||
constexpr char DB_BLOCK_HEIGHT = 't';
|
constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
|
||||||
constexpr char DB_FILTER_POS = 'P';
|
constexpr uint8_t DB_FILTER_POS{'P'};
|
||||||
|
|
||||||
constexpr unsigned int MAX_FLTR_FILE_SIZE = 0x1000000; // 16 MiB
|
constexpr unsigned int MAX_FLTR_FILE_SIZE = 0x1000000; // 16 MiB
|
||||||
/** The pre-allocation chunk size for fltr?????.dat files */
|
/** The pre-allocation chunk size for fltr?????.dat files */
|
||||||
@ -63,7 +63,7 @@ struct DBHeightKey {
|
|||||||
template<typename Stream>
|
template<typename Stream>
|
||||||
void Unserialize(Stream& s)
|
void Unserialize(Stream& s)
|
||||||
{
|
{
|
||||||
char prefix = ser_readdata8(s);
|
const uint8_t prefix{ser_readdata8(s)};
|
||||||
if (prefix != DB_BLOCK_HEIGHT) {
|
if (prefix != DB_BLOCK_HEIGHT) {
|
||||||
throw std::ios_base::failure("Invalid format for block filter index DB height key");
|
throw std::ios_base::failure("Invalid format for block filter index DB height key");
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ struct DBHashKey {
|
|||||||
explicit DBHashKey(const uint256& hash_in) : hash(hash_in) {}
|
explicit DBHashKey(const uint256& hash_in) : hash(hash_in) {}
|
||||||
|
|
||||||
SERIALIZE_METHODS(DBHashKey, obj) {
|
SERIALIZE_METHODS(DBHashKey, obj) {
|
||||||
char prefix = DB_BLOCK_HASH;
|
uint8_t prefix{DB_BLOCK_HASH};
|
||||||
READWRITE(prefix);
|
READWRITE(prefix);
|
||||||
if (prefix != DB_BLOCK_HASH) {
|
if (prefix != DB_BLOCK_HASH) {
|
||||||
throw std::ios_base::failure("Invalid format for block filter index DB hash key");
|
throw std::ios_base::failure("Invalid format for block filter index DB hash key");
|
||||||
@ -149,7 +149,7 @@ bool BlockFilterIndex::ReadFilterFromDisk(const FlatFilePos& pos, BlockFilter& f
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint256 block_hash;
|
uint256 block_hash;
|
||||||
std::vector<unsigned char> encoded_filter;
|
std::vector<uint8_t> encoded_filter;
|
||||||
try {
|
try {
|
||||||
filein >> block_hash >> encoded_filter;
|
filein >> block_hash >> encoded_filter;
|
||||||
filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter));
|
filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter));
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
#include <undo.h>
|
#include <undo.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
|
||||||
static constexpr char DB_BLOCK_HASH = 's';
|
static constexpr uint8_t DB_BLOCK_HASH{'s'};
|
||||||
static constexpr char DB_BLOCK_HEIGHT = 't';
|
static constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
|
||||||
static constexpr char DB_MUHASH = 'M';
|
static constexpr uint8_t DB_MUHASH{'M'};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ struct DBHeightKey {
|
|||||||
template <typename Stream>
|
template <typename Stream>
|
||||||
void Unserialize(Stream& s)
|
void Unserialize(Stream& s)
|
||||||
{
|
{
|
||||||
char prefix{static_cast<char>(ser_readdata8(s))};
|
const uint8_t prefix{ser_readdata8(s)};
|
||||||
if (prefix != DB_BLOCK_HEIGHT) {
|
if (prefix != DB_BLOCK_HEIGHT) {
|
||||||
throw std::ios_base::failure("Invalid format for coinstatsindex DB height key");
|
throw std::ios_base::failure("Invalid format for coinstatsindex DB height key");
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ struct DBHashKey {
|
|||||||
|
|
||||||
SERIALIZE_METHODS(DBHashKey, obj)
|
SERIALIZE_METHODS(DBHashKey, obj)
|
||||||
{
|
{
|
||||||
char prefix{DB_BLOCK_HASH};
|
uint8_t prefix{DB_BLOCK_HASH};
|
||||||
READWRITE(prefix);
|
READWRITE(prefix);
|
||||||
if (prefix != DB_BLOCK_HASH) {
|
if (prefix != DB_BLOCK_HASH) {
|
||||||
throw std::ios_base::failure("Invalid format for coinstatsindex DB hash key");
|
throw std::ios_base::failure("Invalid format for coinstatsindex DB hash key");
|
||||||
|
@ -10,14 +10,13 @@
|
|||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
|
|
||||||
constexpr char DB_BEST_BLOCK = 'B';
|
constexpr uint8_t DB_BEST_BLOCK{'B'};
|
||||||
constexpr char DB_TXINDEX = 't';
|
constexpr uint8_t DB_TXINDEX{'t'};
|
||||||
constexpr char DB_TXINDEX_BLOCK = 'T';
|
constexpr uint8_t DB_TXINDEX_BLOCK{'T'};
|
||||||
|
|
||||||
std::unique_ptr<TxIndex> g_txindex;
|
std::unique_ptr<TxIndex> g_txindex;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Access to the txindex database (indexes/txindex/) */
|
/** Access to the txindex database (indexes/txindex/) */
|
||||||
class TxIndex::DB : public BaseIndex::DB
|
class TxIndex::DB : public BaseIndex::DB
|
||||||
{
|
{
|
||||||
@ -60,8 +59,8 @@ bool TxIndex::DB::WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>>& v_
|
|||||||
*/
|
*/
|
||||||
static void WriteTxIndexMigrationBatches(CDBWrapper& newdb, CDBWrapper& olddb,
|
static void WriteTxIndexMigrationBatches(CDBWrapper& newdb, CDBWrapper& olddb,
|
||||||
CDBBatch& batch_newdb, CDBBatch& batch_olddb,
|
CDBBatch& batch_newdb, CDBBatch& batch_olddb,
|
||||||
const std::pair<unsigned char, uint256>& begin_key,
|
const std::pair<uint8_t, uint256>& begin_key,
|
||||||
const std::pair<unsigned char, uint256>& end_key)
|
const std::pair<uint8_t, uint256>& end_key)
|
||||||
{
|
{
|
||||||
// Sync new DB changes to disk before deleting from old DB.
|
// Sync new DB changes to disk before deleting from old DB.
|
||||||
newdb.WriteBatch(batch_newdb, /*fSync=*/ true);
|
newdb.WriteBatch(batch_newdb, /*fSync=*/ true);
|
||||||
@ -113,9 +112,9 @@ bool TxIndex::DB::MigrateData(CBlockTreeDB& block_tree_db, const CBlockLocator&
|
|||||||
CDBBatch batch_newdb(*this);
|
CDBBatch batch_newdb(*this);
|
||||||
CDBBatch batch_olddb(block_tree_db);
|
CDBBatch batch_olddb(block_tree_db);
|
||||||
|
|
||||||
std::pair<unsigned char, uint256> key;
|
std::pair<uint8_t, uint256> key;
|
||||||
std::pair<unsigned char, uint256> begin_key{DB_TXINDEX, uint256()};
|
std::pair<uint8_t, uint256> begin_key{DB_TXINDEX, uint256()};
|
||||||
std::pair<unsigned char, uint256> prev_key = begin_key;
|
std::pair<uint8_t, uint256> prev_key = begin_key;
|
||||||
|
|
||||||
bool interrupted = false;
|
bool interrupted = false;
|
||||||
std::unique_ptr<CDBIterator> cursor(block_tree_db.NewIterator());
|
std::unique_ptr<CDBIterator> cursor(block_tree_db.NewIterator());
|
||||||
|
Loading…
Reference in New Issue
Block a user