Skip to content

feat(lib-blockchain): Add DifficultyConfig struct to blockchain state #626

@umwelt

Description

@umwelt

Description

Part of issue #605: Adaptive Difficulty Adjustment for PoUW Consensus

Add a new DifficultyConfig struct to store governance-controlled difficulty parameters in the blockchain state, replacing hardcoded constants.

Acceptance Criteria

  • Create DifficultyConfig struct in lib-blockchain with fields:
    • target_timespan: u64 (default: 14 days)
    • adjustment_interval: u64 (default: 2016 blocks)
    • min_adjustment_factor: u64 (default: 4 - max 4x decrease)
    • max_adjustment_factor: u64 (default: 4 - max 4x increase)
    • last_updated_at_height: u64 (tracks when last changed)
  • Add difficulty_config: DifficultyConfig field to Blockchain struct
  • Initialize with default values in Blockchain::new()
  • Implement serialization/deserialization for persistence
  • Add getter method get_difficulty_config(&self) -> &DifficultyConfig
  • Write unit tests for serialization round-trip
  • Ensure backward compatibility with existing genesis blocks

Related

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions