Skip to content

Commit 7269993

Browse files
Claude Codeclaude
andcommitted
validation: Correct _bulk_tx formula for Dash's weight calculation
The previous fix removed the division by 4 (correct for Dash since get_weight() returns vsize, not weight units), but incorrectly kept the +3 offset from Bitcoin's formula. In Bitcoin: (target - current + 3) // 4 - The +3 ensures rounding up - After division, adds 0-3 vbytes based on remainder In Dash: target - current - No division needed since get_weight() = vsize - The +3 was causing transactions to be 3 bytes too large - This caused insufficient fees (min relay fee not met) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 221ace0 commit 7269993

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

test/functional/test_framework/wallet.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ def _bulk_tx(self, tx, target_weight):
9999
returns the tx
100100
"""
101101
tx.vout.append(CTxOut(nValue=0, scriptPubKey=CScript([OP_RETURN, b'a'])))
102-
# In Dash, get_weight() returns vsize directly (no witness scaling)
103-
# We need to account for compact size encoding overhead
104-
current_weight = tx.get_weight()
105-
# Estimate bytes needed, accounting for potential compact size encoding changes
106-
# The +3 accounts for worst-case rounding in compact size encoding
107-
dummy_vbytes = max(0, target_weight - current_weight + 3)
102+
# In Dash, get_weight() returns vsize directly (no witness scaling factor like Bitcoin's 4)
103+
# Bitcoin's formula: (target_weight - tx.get_weight() + 3) // 4
104+
# - The +3 ensures rounding up when dividing by 4
105+
# - After division, this adds 0-3 vbytes depending on remainder
106+
# For Dash (no division by 4), we calculate bytes needed directly
107+
dummy_vbytes = target_weight - tx.get_weight()
108108
tx.vout[-1].scriptPubKey = CScript([OP_RETURN, b'a' * dummy_vbytes])
109109
# Lower bound should always be off by at most 3
110110
assert_greater_than_or_equal(tx.get_weight(), target_weight)

0 commit comments

Comments
 (0)