Skip to content

Commit fae4da3

Browse files
committed
DGB v8.22 merge with BTC v26.2 Fixes Part 18
1 parent 673cb2b commit fae4da3

5 files changed

Lines changed: 133 additions & 2849 deletions

File tree

resolve_wallet_conflicts.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Resolve remaining wallet.cpp conflicts for DigiByte v8.22 to Bitcoin v26.2 merge
4+
This script handles the systematic conflict patterns identified during manual review
5+
"""
6+
7+
import re
8+
import sys
9+
10+
def read_file(filename):
11+
with open(filename, 'r') as f:
12+
return f.read()
13+
14+
def write_file(filename, content):
15+
with open(filename, 'w') as f:
16+
f.write(content)
17+
18+
def resolve_conflicts(content):
19+
"""Resolve systematic conflicts based on patterns identified"""
20+
21+
# First, restore the complex conflicts that were replaced with placeholders
22+
# and resolve them properly based on the patterns we identified
23+
24+
# Pattern replacements based on Bitcoin v26.2 improvements:
25+
replacements = [
26+
# Remove conflict markers and choose Bitcoin version
27+
(r'<<<<<<< HEAD\n.*?\n=======\n(.*?)\n>>>>>>> bitcoin-v26-2-converted/digibyte-v26\.2-naming-conversion', r'\1'),
28+
29+
# State system improvements
30+
(r'wtx\.m_confirm', 'wtx.m_state'),
31+
(r'confirm\.status', 'state.index()'),
32+
(r'confirm\.hashBlock', 'conf->confirmed_block_hash'),
33+
(r'confirm\.block_height', 'conf->confirmed_block_height'),
34+
35+
# Function signature updates
36+
(r'CWalletTx::Confirmation&?\s+confirm', 'TxState& state'),
37+
(r'const\s+CWalletTx::Confirmation&?\s+confirm', 'const TxState& state'),
38+
39+
# boost to standard library replacements
40+
(r'boost::replace_all', 'ReplaceAll'),
41+
42+
# Address tracking improvements
43+
(r'IsAddressUsed', 'IsAddressPreviouslySpent'),
44+
(r'SetAddressUsed', 'SetAddressPreviouslySpent'),
45+
46+
# Mempool status improvements
47+
(r'wtx\.fInMempool = chain\(\)\.isInMempool\([^)]+\);', 'RefreshMempoolStatus(wtx, chain());'),
48+
49+
# Constructor changes
50+
(r'std::forward_as_tuple\(this, tx\)', 'std::forward_as_tuple(tx, state)'),
51+
(r'std::forward_as_tuple\(this, nullptr\)', 'std::forward_as_tuple(nullptr, TxStateInactive{})'),
52+
53+
# Function parameter additions
54+
(r'ComputeTimeSmart\(wtx\)', 'ComputeTimeSmart(wtx, rescanning_old_block)'),
55+
(r'AddToSpends\(hash\)', 'AddToSpends(wtx, &batch)'),
56+
57+
# Time function updates
58+
(r'chain\(\)\.getAdjustedTime\(\)', 'GetTime()'),
59+
60+
# Confirmation status checks
61+
(r'wtx\.isConflicted\(\)', 'wtx.state<TxStateConflicted>()'),
62+
(r'wtx\.isConfirmed\(\)', 'wtx.state<TxStateConfirmed>()'),
63+
64+
# Placeholder cleanup
65+
(r'# PLACEHOLDER_FOR_BITCOIN_VERSION\n', ''),
66+
]
67+
68+
result = content
69+
for pattern, replacement in replacements:
70+
result = re.sub(pattern, replacement, result, flags=re.MULTILINE | re.DOTALL)
71+
72+
return result
73+
74+
def main():
75+
if len(sys.argv) != 2:
76+
print("Usage: python3 resolve_wallet_conflicts.py <wallet.cpp>")
77+
sys.exit(1)
78+
79+
filename = sys.argv[1]
80+
print(f"Resolving conflicts in {filename}")
81+
82+
content = read_file(filename)
83+
resolved_content = resolve_conflicts(content)
84+
write_file(filename, resolved_content)
85+
86+
print("Conflicts resolved successfully")
87+
88+
if __name__ == "__main__":
89+
main()

src/wallet/bdb.cpp

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,16 @@ class SafeDbt final
256256
};
257257

258258
SafeDbt::SafeDbt()
259-
>>>>>>> bitcoin-v26-2-converted/digibyte-v26.2-naming-conversion
260259
{
261260
m_dbt.set_flags(DB_DBT_MALLOC);
262261
}
263262

263+
SafeDbt::SafeDbt(void* data, size_t size)
264264
: m_dbt(data, size)
265265
{
266266
}
267267

268+
SafeDbt::~SafeDbt()
268269
{
269270
if (m_dbt.get_data() != nullptr) {
270271
// Clear memory, e.g. in case it was a private key
@@ -278,29 +279,21 @@ SafeDbt::SafeDbt()
278279
}
279280
}
280281

282+
const void* SafeDbt::get_data() const
281283
{
282284
return m_dbt.get_data();
283285
}
284286

287+
uint32_t SafeDbt::get_size() const
285288
{
286289
return m_dbt.get_size();
287290
}
288291

292+
SafeDbt::operator Dbt*()
289293
{
290294
return &m_dbt;
291295
}
292296

293-
<<<<<<< HEAD
294-
bool BerkeleyDatabase::Verify(bilingual_str& errorStr)
295-
{
296-
fs::path walletDir = env->Directory();
297-
fs::path file_path = walletDir / strFile;
298-
299-
LogPrintf("Using BerkeleyDB version %s\n", BerkeleyDatabaseVersion());
300-
LogPrintf("Using wallet %s\n", fs::PathToString(file_path));
301-
return {reinterpret_cast<const std::byte*>(dbt.get_data()), dbt.get_size()};
302-
}
303-
304297
BerkeleyDatabase::BerkeleyDatabase(std::shared_ptr<BerkeleyEnvironment> env, fs::path filename, const DatabaseOptions& options) :
305298
WalletDatabase(), env(std::move(env)), m_filename(std::move(filename)), m_max_log_mb(options.max_log_mb)
306299
{
@@ -315,7 +308,6 @@ bool BerkeleyDatabase::Verify(bilingual_str& errorStr)
315308

316309
LogPrintf("Using BerkeleyDB version %s\n", BerkeleyDatabaseVersion());
317310
LogPrintf("Using wallet %s\n", fs::PathToString(file_path));
318-
>>>>>>> bitcoin-v26-2-converted/digibyte-v26.2-naming-conversion
319311

320312
if (!env->Open(errorStr)) {
321313
return false;
@@ -345,28 +337,22 @@ void BerkeleyEnvironment::CheckpointLSN(const std::string& strFile)
345337
dbenv->lsn_reset(strFile.c_str(), 0);
346338
}
347339

340+
Span<const std::byte> SpanFromDbt(const Dbt& dbt)
341+
{
342+
return {reinterpret_cast<const std::byte*>(dbt.get_data()), dbt.get_size()};
343+
}
344+
348345
BerkeleyDatabase::~BerkeleyDatabase()
349346
{
350347
if (env) {
351348
LOCK(cs_db);
352-
<<<<<<< HEAD
353-
env->CloseDb(strFile);
354-
assert(!m_db);
355-
size_t erased = env->m_databases.erase(strFile);
356-
assert(erased == 1);
357-
env->m_fileids.erase(strFile);
358-
}
359-
}
360-
361-
BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const bool read_only, bool fFlushOnCloseIn) : pdb(nullptr), activeTxn(nullptr), m_cursor(nullptr), m_database(database)
362349
size_t erased = env->m_databases.erase(m_filename);
363350
assert(erased == 1);
364351
env->m_fileids.erase(fs::PathToString(m_filename));
365352
}
366353
}
367354

368355
BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const bool read_only, bool fFlushOnCloseIn) : m_database(database)
369-
>>>>>>> bitcoin-v26-2-converted/digibyte-v26.2-naming-conversion
370356
{
371357
database.AddRef();
372358
database.Open();
@@ -462,16 +448,11 @@ void BerkeleyBatch::Close()
462448
Flush();
463449
}
464450

465-
<<<<<<< HEAD
466-
void BerkeleyEnvironment::CloseDb(const std::string& strFile)
451+
void BerkeleyEnvironment::CloseDb(const fs::path& filename)
467452
{
468453
{
469454
LOCK(cs_db);
470455
auto it = m_databases.find(filename);
471-
{
472-
LOCK(cs_db);
473-
auto it = m_databases.find(filename);
474-
>>>>>>> bitcoin-v26-2-converted/digibyte-v26.2-naming-conversion
475456
assert(it != m_databases.end());
476457
BerkeleyDatabase& database = it->second.get();
477458
if (database.m_db) {
@@ -494,19 +475,12 @@ void BerkeleyEnvironment::ReloadDbEnv()
494475
return true;
495476
});
496477

497-
<<<<<<< HEAD
498-
std::vector<std::string> filenames;
499-
for (auto it : m_databases) {
500-
filenames.push_back(it.first);
501-
}
502-
// Close the individual Db's
503-
for (const fs::path& filename : filenames) {
478+
std::vector<fs::path> filenames;
504479
for (const auto& it : m_databases) {
505480
filenames.push_back(it.first);
506481
}
507482
// Close the individual Db's
508483
for (const fs::path& filename : filenames) {
509-
>>>>>>> bitcoin-v26-2-converted/digibyte-v26.2-naming-conversion
510484
CloseDb(filename);
511485
}
512486
// Reset the environment
@@ -525,7 +499,6 @@ DbTxn* BerkeleyEnvironment::TxnBegin(int flags)
525499
return ptxn;
526500
}
527501

528-
>>>>>>> bitcoin-v26-2-converted/digibyte-v26.2-naming-conversion
529502
bool BerkeleyDatabase::Rewrite(const char* pszSkip)
530503
{
531504
while (true) {
@@ -744,7 +717,7 @@ BerkeleyCursor::BerkeleyCursor(BerkeleyDatabase& database, const BerkeleyBatch&
744717
}
745718
// Transaction argument to cursor is only needed when using the cursor to
746719
// write to the database. Read-only cursors do not need a txn pointer.
747-
int ret = database.m_db->cursor(batch.txn(), &m_cursor, 0);
720+
int ret = database.m_db->cursor(batch.activeTxn, &m_cursor, 0);
748721
if (ret != 0) {
749722
throw std::runtime_error(STR_INTERNAL_BUG(strprintf("BDB Cursor could not be created. Returned %d", ret)));
750723
}
@@ -927,7 +900,6 @@ bool BerkeleyBatch::ErasePrefix(Span<const std::byte> prefix)
927900
return TxnCommit() && (ret == 0 || ret == DB_NOTFOUND);
928901
}
929902

930-
>>>>>>> bitcoin-v26-2-converted/digibyte-v26.2-naming-conversion
931903
void BerkeleyDatabase::AddRef()
932904
{
933905
LOCK(cs_db);

0 commit comments

Comments
 (0)