11# DigiByte Test Suite - Common Fixes
22
33## Quick Reference
4- Most test failures are caused by these 8 issues (in order of frequency):
4+ Most test failures are caused by these 9 issues (in order of frequency):
551 . ** Block Rewards & Fees** - 72000 DGB (not 50 BTC), fees in sat/kB (not sat/vB)
662 . ** Coinbase Maturity** - Use COINBASE_MATURITY_2 (100) for wallet tests, COINBASE_MATURITY (8) for initial setup
773 . ** Dandelion++** - Causes transaction propagation delays
@@ -10,6 +10,7 @@ Most test failures are caused by these 8 issues (in order of frequency):
10106 . ** Fork Heights** - Difficulty changes at blocks 100, 200, 334, 400, 600
11117 . ** Network Ports** - DigiByte uses different ports than Bitcoin
12128 . ** Address & Key Generation** - Must use proper DigiByte prefixes and encoding
13+ 9 . ** Block Version & Algorithm Changes** - Version bits change at fork heights
1314
1415---
1516
@@ -378,9 +379,177 @@ When a test fails, check in this order:
3783793 . ** Transaction not found?** → Add ` -dandelion=0 ` to all nodes
3793804 . ** Address validation?** → Check prefix (dgbrt, not bcrt)
3803815 . ** Invalid address error?** → Use node.getnewaddress() or see Pattern #8
381- 6 . ** Block rejected?** → Set block.nVersion = 0x00000204
382+ 6 . ** Block rejected?** → Check version & algo bits - see Pattern # 9
3823837 . ** Mining difficulty spike?** → Check fork height, use ` -easypow `
3833848 . ** Connection refused?** → Check port numbers (14022 not 18444)
385+ 9 . ** Algorithm not active?** → Set correct version bits after block 100 - see Pattern #9
386+
387+ ---
388+
389+ ## 9. BLOCK VERSION & ALGORITHM CHANGES (Critical for Mining & Relay Tests)
390+
391+ ### The Problem
392+ DigiByte's block version field encodes BOTH the base version AND the mining algorithm. This changes at specific heights as DigiByte evolved from single-algo to multi-algo mining.
393+
394+ ### Block Version Structure
395+
396+ ``` python
397+ # Block version bits layout:
398+ # Bits 31-28: BIP9 signaling (VERSIONBITS_TOP_BITS)
399+ # Bits 11-8: Algorithm identifier
400+ # Bits 7-0: Base version (always 2)
401+
402+ # Constants from src/primitives/block.h:
403+ BLOCK_VERSION_DEFAULT = 2 # Base version
404+ BLOCK_VERSION_ALGO = (15 << 8 ) # Mask for algo bits: 0x0F00
405+
406+ # Algorithm bits (in bits 8-11):
407+ BLOCK_VERSION_SCRYPT = (0 << 8 ) # 0x0000
408+ BLOCK_VERSION_SHA256D = (2 << 8 ) # 0x0200
409+ BLOCK_VERSION_GROESTL = (4 << 8 ) # 0x0400
410+ BLOCK_VERSION_SKEIN = (6 << 8 ) # 0x0600
411+ BLOCK_VERSION_QUBIT = (8 << 8 ) # 0x0800
412+ BLOCK_VERSION_ODO = (14 << 8 ) # 0x0E00
413+
414+ # BIP9 signaling (after ReserveAlgoBits):
415+ VERSIONBITS_TOP_BITS = 0x 20000000 # Bit 29 set
416+ ```
417+
418+ ### Four Eras of Block Versioning in REGTEST
419+
420+ #### ERA 1: Simple Scrypt (Blocks 0-99)
421+ ``` python
422+ # Before multi-algo activation
423+ # Version = 2 (just base version, no algo bits needed)
424+ block.nVersion = 2 # 0x00000002
425+ ```
426+
427+ #### ERA 2: Multi-Algo without BIP9 (Blocks 100-599)
428+ ``` python
429+ # 5 algorithms active, must set algo bits
430+ # Version = 2 | algo_bits
431+ block.nVersion = 0x 00000002 # Scrypt (2 | 0x0000)
432+ block.nVersion = 0x 00000202 # SHA256D (2 | 0x0200)
433+ block.nVersion = 0x 00000402 # Groestl (2 | 0x0400)
434+ block.nVersion = 0x 00000602 # Skein (2 | 0x0600)
435+ block.nVersion = 0x 00000802 # Qubit (2 | 0x0800)
436+ ```
437+
438+ #### ERA 3: BIP9 + Multi-Algo (Most regtest tests use this)
439+ ``` python
440+ # After ReserveAlgoBits (always active in regtest)
441+ # Version = VERSIONBITS_TOP_BITS | 2 | algo_bits
442+ # ALL 5 algorithms still active:
443+ block.nVersion = 0x 20000002 # Scrypt with BIP9
444+ block.nVersion = 0x 20000202 # SHA256D with BIP9
445+ block.nVersion = 0x 20000402 # Groestl with BIP9
446+ block.nVersion = 0x 20000602 # Skein with BIP9
447+ block.nVersion = 0x 20000802 # Qubit with BIP9
448+ ```
449+
450+ #### ERA 4: With Odocrypt (Blocks 600+)
451+ ``` python
452+ # Now 6 algorithms available (5 original + Odocrypt)
453+ block.nVersion = 0x 20000002 # Scrypt with BIP9
454+ block.nVersion = 0x 20000202 # SHA256D with BIP9
455+ block.nVersion = 0x 20000402 # Groestl with BIP9
456+ block.nVersion = 0x 20000602 # Skein with BIP9
457+ block.nVersion = 0x 20000802 # Qubit with BIP9
458+ block.nVersion = 0x 20000E02 # Odocrypt with BIP9 (NEW!)
459+ ```
460+
461+ ### Quick Fix Guide
462+
463+ #### Fix 1: Tests Creating Blocks Manually
464+ ``` python
465+ # WRONG - Bitcoin style:
466+ block.nVersion = 4
467+
468+ # RIGHT - DigiByte style depends on height:
469+ height = node.getblockcount()
470+ if height < 100 :
471+ block.nVersion = 2 # Pre-multi-algo
472+ else :
473+ # Most tests default to Scrypt with BIP9:
474+ block.nVersion = 0x 20000002
475+ # Or if test needs specific algo:
476+ block.nVersion = 0x 20000202 # SHA256D
477+ ```
478+
479+ #### Fix 2: Tests Checking Version
480+ ``` python
481+ # WRONG - Exact match:
482+ assert block.nVersion == 4
483+
484+ # RIGHT - Check base version only:
485+ base_version = block.nVersion & 0x FF # Get lower 8 bits
486+ assert base_version == 2
487+
488+ # Or accept any valid DigiByte version:
489+ valid_versions = [0x 20000002 , 0x 20000202 , 0x 20000402 , ... ]
490+ assert block.nVersion in valid_versions
491+ ```
492+
493+ #### Fix 3: Mining Tests Failing
494+ ``` python
495+ # ERROR: "Algorithm 'sha256d' is not currently active"
496+ # FIX: Add -easypow to postpone multi-algo:
497+ self .extra_args = [[" -easypow" ]]
498+
499+ # Or stay below block 100:
500+ self .generate(node, 99 ) # Don't cross into multi-algo
501+ ```
502+
503+ #### Fix 4: BIP9 Version Bits Tests
504+ ``` python
505+ # DigiByte uses different mask than Bitcoin:
506+ VERSIONBITS_TOP_MASK = 0x F0000000 # NOT 0xE0000000
507+ VERSIONBITS_TOP_BITS = 0x 20000000
508+
509+ # When checking BIP9 signaling:
510+ if (block.nVersion & VERSIONBITS_TOP_MASK ) == VERSIONBITS_TOP_BITS :
511+ # BIP9 is active
512+ ```
513+
514+ ### Complete Version Reference Table
515+
516+ | Algorithm | ERA 1 (0-99) | ERA 2 (100-599) | ERA 3 (Regtest Default) | ERA 4 (600+) |
517+ | -----------| --------------| -----------------| -------------------------| --------------|
518+ | Scrypt | 0x00000002 | 0x00000002 | 0x20000002 | 0x20000002 |
519+ | SHA256D | Not Active | 0x00000202 | 0x20000202 | 0x20000202 |
520+ | Groestl | Not Active | 0x00000402 | 0x20000402 | 0x20000402 |
521+ | Skein | Not Active | 0x00000602 | 0x20000602 | 0x20000602 |
522+ | Qubit | Not Active | 0x00000802 | 0x20000802 | 0x20000802 |
523+ | Odocrypt | Not Active | Not Active | Not Active | 0x20000E02 |
524+
525+ ### Common Errors & Solutions
526+
527+ | Error | Cause | Fix |
528+ | -------| -------| -----|
529+ | ` Algorithm 'sha256d' is not currently active ` | Wrong version after block 100 | Set algo bits: ` nVersion = 0x20000202 ` |
530+ | ` AssertionError: not(536870914 == 4) ` | Test expects Bitcoin version 4 | Accept DigiByte versions |
531+ | ` bad-version(0x00000002) ` | Missing BIP9 bits | Use ` 0x20000002 ` not ` 2 ` |
532+ | ` Block validation failed ` | Wrong algo for height | Check height, use correct version |
533+
534+ ### Test Framework Already Has This!
535+
536+ ``` python
537+ # From test_framework/messages.py:
538+ BLOCK_VERSION_SCRYPT = (0 << 8 )
539+ BLOCK_VERSION_SHA256D = (2 << 8 )
540+ # ... etc
541+
542+ # Most tests should just use:
543+ from test_framework.blocktools import create_block
544+ block = create_block(... ) # Handles version automatically
545+ ```
546+
547+ ### Pro Tips
548+
549+ 1 . ** Most regtest tests use ` 0x20000002 ` ** (Scrypt with BIP9)
550+ 2 . ** Use ` -easypow ` to avoid multi-algo complexity**
551+ 3 . ** Don't hardcode version checks** - mask out algo bits
552+ 4 . ** Let create_block() handle it** when possible
384553
385554---
386555
0 commit comments