Skip to content

Commit dc8da2a

Browse files
committed
Merge bitcoin/bitcoin#21824: refactor: [index] Replace deprecated char with uint8_t in serialization
fafb880 refactor: [index] Replace deprecated char with uint8_t in serialization (MarcoFalke) Pull request description: All char representations are serialized in the same way, however the `char` one is deprecated according to https://github.com/bitcoin/bitcoin/blob/d22e7ee93313b13365bd14a5fffeb055cff4dcd2/src/serialize.h#L227 . Also, using `uint8_t` directly avoids casts. ACKs for top commit: jonatack: Approach ACK fafb880 laanwj: Code review ACK fafb880 practicalswift: cr ACK fafb880: patch looks correct Tree-SHA512: ed08fb1b18cb75a695e15924bcaa30ff8746bcd5f17cc83e79f94fe5ff8d9f2083435cb49b8245e3341ede2512140940d864299f4746bc40c8ed8bfdbdacac24
2 parents 3f8f238 + fafb880 commit dc8da2a

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

src/index/base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <validation.h> // For g_chainman
1414
#include <warnings.h>
1515

16-
constexpr char DB_BEST_BLOCK = 'B';
16+
constexpr uint8_t DB_BEST_BLOCK{'B'};
1717

1818
constexpr int64_t SYNC_LOG_INTERVAL = 30; // seconds
1919
constexpr int64_t SYNC_LOCATOR_WRITE_INTERVAL = 30; // seconds

src/index/blockfilterindex.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
* as big-endian so that sequential reads of filters by height are fast.
2525
* Keys for the hash index have the type [DB_BLOCK_HASH, uint256].
2626
*/
27-
constexpr char DB_BLOCK_HASH = 's';
28-
constexpr char DB_BLOCK_HEIGHT = 't';
29-
constexpr char DB_FILTER_POS = 'P';
27+
constexpr uint8_t DB_BLOCK_HASH{'s'};
28+
constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
29+
constexpr uint8_t DB_FILTER_POS{'P'};
3030

3131
constexpr unsigned int MAX_FLTR_FILE_SIZE = 0x1000000; // 16 MiB
3232
/** The pre-allocation chunk size for fltr?????.dat files */
@@ -63,7 +63,7 @@ struct DBHeightKey {
6363
template<typename Stream>
6464
void Unserialize(Stream& s)
6565
{
66-
char prefix = ser_readdata8(s);
66+
const uint8_t prefix{ser_readdata8(s)};
6767
if (prefix != DB_BLOCK_HEIGHT) {
6868
throw std::ios_base::failure("Invalid format for block filter index DB height key");
6969
}
@@ -77,7 +77,7 @@ struct DBHashKey {
7777
explicit DBHashKey(const uint256& hash_in) : hash(hash_in) {}
7878

7979
SERIALIZE_METHODS(DBHashKey, obj) {
80-
char prefix = DB_BLOCK_HASH;
80+
uint8_t prefix{DB_BLOCK_HASH};
8181
READWRITE(prefix);
8282
if (prefix != DB_BLOCK_HASH) {
8383
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
149149
}
150150

151151
uint256 block_hash;
152-
std::vector<unsigned char> encoded_filter;
152+
std::vector<uint8_t> encoded_filter;
153153
try {
154154
filein >> block_hash >> encoded_filter;
155155
filter = BlockFilter(GetFilterType(), block_hash, std::move(encoded_filter));

src/index/coinstatsindex.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
#include <undo.h>
1313
#include <validation.h>
1414

15-
static constexpr char DB_BLOCK_HASH = 's';
16-
static constexpr char DB_BLOCK_HEIGHT = 't';
17-
static constexpr char DB_MUHASH = 'M';
15+
static constexpr uint8_t DB_BLOCK_HASH{'s'};
16+
static constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
17+
static constexpr uint8_t DB_MUHASH{'M'};
1818

1919
namespace {
2020

@@ -66,7 +66,7 @@ struct DBHeightKey {
6666
template <typename Stream>
6767
void Unserialize(Stream& s)
6868
{
69-
char prefix{static_cast<char>(ser_readdata8(s))};
69+
const uint8_t prefix{ser_readdata8(s)};
7070
if (prefix != DB_BLOCK_HEIGHT) {
7171
throw std::ios_base::failure("Invalid format for coinstatsindex DB height key");
7272
}
@@ -81,7 +81,7 @@ struct DBHashKey {
8181

8282
SERIALIZE_METHODS(DBHashKey, obj)
8383
{
84-
char prefix{DB_BLOCK_HASH};
84+
uint8_t prefix{DB_BLOCK_HASH};
8585
READWRITE(prefix);
8686
if (prefix != DB_BLOCK_HASH) {
8787
throw std::ios_base::failure("Invalid format for coinstatsindex DB hash key");

src/index/txindex.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
#include <util/translation.h>
1111
#include <validation.h>
1212

13-
constexpr char DB_BEST_BLOCK = 'B';
14-
constexpr char DB_TXINDEX = 't';
15-
constexpr char DB_TXINDEX_BLOCK = 'T';
13+
constexpr uint8_t DB_BEST_BLOCK{'B'};
14+
constexpr uint8_t DB_TXINDEX{'t'};
15+
constexpr uint8_t DB_TXINDEX_BLOCK{'T'};
1616

1717
std::unique_ptr<TxIndex> g_txindex;
1818

1919

20-
2120
/** Access to the txindex database (indexes/txindex/) */
2221
class TxIndex::DB : public BaseIndex::DB
2322
{
@@ -60,8 +59,8 @@ bool TxIndex::DB::WriteTxs(const std::vector<std::pair<uint256, CDiskTxPos>>& v_
6059
*/
6160
static void WriteTxIndexMigrationBatches(CDBWrapper& newdb, CDBWrapper& olddb,
6261
CDBBatch& batch_newdb, CDBBatch& batch_olddb,
63-
const std::pair<unsigned char, uint256>& begin_key,
64-
const std::pair<unsigned char, uint256>& end_key)
62+
const std::pair<uint8_t, uint256>& begin_key,
63+
const std::pair<uint8_t, uint256>& end_key)
6564
{
6665
// Sync new DB changes to disk before deleting from old DB.
6766
newdb.WriteBatch(batch_newdb, /*fSync=*/ true);
@@ -113,9 +112,9 @@ bool TxIndex::DB::MigrateData(CBlockTreeDB& block_tree_db, const CBlockLocator&
113112
CDBBatch batch_newdb(*this);
114113
CDBBatch batch_olddb(block_tree_db);
115114

116-
std::pair<unsigned char, uint256> key;
117-
std::pair<unsigned char, uint256> begin_key{DB_TXINDEX, uint256()};
118-
std::pair<unsigned char, uint256> prev_key = begin_key;
115+
std::pair<uint8_t, uint256> key;
116+
std::pair<uint8_t, uint256> begin_key{DB_TXINDEX, uint256()};
117+
std::pair<uint8_t, uint256> prev_key = begin_key;
119118

120119
bool interrupted = false;
121120
std::unique_ptr<CDBIterator> cursor(block_tree_db.NewIterator());

0 commit comments

Comments
 (0)