Skip to content

Commit 45d3b21

Browse files
thepastaclawclaude
andcommitted
fix: use consistent encoding for governance debug log seek
debug_log_size(mode="rb") returns a byte offset, but the file is opened in text mode with encoding="utf-8" — seeking to a byte offset in a text stream is not valid (and on logs containing multi-byte UTF-8 it can land mid-character or at a wrong position). Match the encoding to the text-mode read so the seek position is computed in the same units. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 67683f3 commit 45d3b21

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

test/functional/feature_governance_cl.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ def run_test(self):
147147
expected_msg = f'CGovernanceManager::UpdatedBlockTip -- nCachedBlockHeight: {tip_height}'
148148

149149
def governance_tip_updated(node):
150-
with open(node.debug_log_path, encoding='utf-8') as dl:
150+
with open(node.debug_log_path, "rb") as dl:
151151
seek_pos = node.debug_log_size(mode="rb") - 100 * 1024 # read the last 100 KiB only
152152
dl.seek(seek_pos if seek_pos > 0 else 0)
153-
debug_log_part = dl.read()
153+
debug_log_part = dl.read().decode("utf-8", errors="replace")
154154
return expected_msg in debug_log_part
155155

156156
for node in self.nodes[0:5]:

0 commit comments

Comments
 (0)