From f2d235c1cdfe5f93fb3594d55ce7814c6ffbe0e7 Mon Sep 17 00:00:00 2001 From: pasta Date: Thu, 29 Oct 2026 21:53:54 +0000 Subject: [PATCH] fix: complete bitcoin#36669 for BlockInfo and AutoFile file positions bitcoin#36669 reached develop through the v23.1.9 merge (#7961) without two of its upstream hunks, because v23.1.x's port had no equivalent sites for them: - kernel/chain.h: BlockInfo::data_pos becomes uint64_t. Dash keeps BlockInfo in interfaces/chain.h; kernel/chain.cpp fills it from the now 64-bit CBlockIndex::nDataPos and TxIndex::CustomAppend builds a CDiskTxPos from it, so the position was narrowed back to 32 bits there. - streams.cpp: AutoFile reads its position through FileTell64() instead of std::ftell(), which uses a 32-bit long on Windows. Dash's AutoFile has no cached position or seek wrapper, so this applies to the XOR read and write paths. Neither path is reachable with today's 128 MiB block files and unset XOR keys; this keeps the 64-bit position handling consistent with upstream. Co-Authored-By: Claude Opus 5.5 --- src/interfaces/chain.h | 2 +- src/streams.cpp | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 75fa104be59c..fe711c74d265 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -97,7 +97,7 @@ struct BlockInfo { const uint256* prev_hash = nullptr; int height = -1; int file_number = -1; - unsigned data_pos = 0; + uint64_t data_pos = 0; const CBlock* data = nullptr; const CBlockUndo* undo_data = nullptr; // The maximum time in the chain up to and including this block. diff --git a/src/streams.cpp b/src/streams.cpp index 6921dad67733..98e29cd4d0ed 100644 --- a/src/streams.cpp +++ b/src/streams.cpp @@ -4,6 +4,7 @@ #include #include +#include #include @@ -13,7 +14,7 @@ std::size_t AutoFile::detail_fread(Span dst) if (m_xor.empty()) { return std::fread(dst.data(), 1, dst.size(), m_file); } else { - const auto init_pos{std::ftell(m_file)}; + const auto init_pos{FileTell64(m_file)}; if (init_pos < 0) throw std::ios_base::failure("AutoFile::read: ftell failed"); std::size_t ret{std::fread(dst.data(), 1, dst.size(), m_file)}; util::Xor(dst.subspan(0, ret), m_xor, init_pos); @@ -49,7 +50,7 @@ void AutoFile::write(Span src) throw std::ios_base::failure("AutoFile::write: write failed"); } } else { - auto current_pos{std::ftell(m_file)}; + auto current_pos{FileTell64(m_file)}; if (current_pos < 0) throw std::ios_base::failure("AutoFile::write: ftell failed"); std::array buf; while (src.size() > 0) {