difficulty

package
v0.0.0-...-fc775d1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockMetrics

type BlockMetrics struct {
	BlockTime       time.Duration `json:"block_time"`
	EnergyUsed      int64         `json:"energy_used"`
	NetworkHashrate int64         `json:"network_hashrate"`
	Difficulty      *big.Int      `json:"difficulty"`
}

BlockMetrics holds metrics for a block

type DifficultyAdjuster

type DifficultyAdjuster struct {
	// contains filtered or unexported fields
}

DifficultyAdjuster handles difficulty adjustment calculations

func NewDifficultyAdjuster

func NewDifficultyAdjuster(config *DifficultyAdjustmentConfig) *DifficultyAdjuster

NewDifficultyAdjuster creates a new difficulty adjuster

func (*DifficultyAdjuster) AggregateWindowMetrics

func (da *DifficultyAdjuster) AggregateWindowMetrics(blockMetrics []*BlockMetrics) *WindowMetrics

AggregateWindowMetrics aggregates metrics from a window of blocks

func (*DifficultyAdjuster) CalculateNewDifficulty

func (da *DifficultyAdjuster) CalculateNewDifficulty(
	currentDifficulty *big.Int,
	windowMetrics *WindowMetrics,
) *big.Int

CalculateNewDifficulty calculates the new difficulty based on recent block metrics

func (*DifficultyAdjuster) GetAdjustmentWindowSize

func (da *DifficultyAdjuster) GetAdjustmentWindowSize() int

GetAdjustmentWindowSize returns the size of the adjustment window

func (*DifficultyAdjuster) GetConfig

GetConfig returns the current configuration

func (*DifficultyAdjuster) ShouldAdjustDifficulty

func (da *DifficultyAdjuster) ShouldAdjustDifficulty(blockNumber int) bool

ShouldAdjustDifficulty determines if difficulty should be adjusted

func (*DifficultyAdjuster) UpdateConfig

func (da *DifficultyAdjuster) UpdateConfig(newConfig *DifficultyAdjustmentConfig)

UpdateConfig updates the difficulty adjustment configuration

func (*DifficultyAdjuster) ValidateMetrics

func (da *DifficultyAdjuster) ValidateMetrics(metrics *BlockMetrics) error

ValidateMetrics validates that metrics are within acceptable ranges

type DifficultyAdjustmentConfig

type DifficultyAdjustmentConfig struct {
	// Basic adjustment parameters
	TargetBlockTime     time.Duration `json:"target_block_time"`     // 10 seconds
	AdjustmentWindow    int           `json:"adjustment_window"`     // 2016 blocks
	MaxAdjustmentFactor float64       `json:"max_adjustment_factor"` // 4.0 (400%)
	MinAdjustmentFactor float64       `json:"min_adjustment_factor"` // 0.25 (25%)

	// Multi-factor parameters
	EnableMultiFactor bool    `json:"enable_multi_factor"` // false initially
	EnergyWeight      float64 `json:"energy_weight"`       // 0.3 (30%)
	NetworkWeight     float64 `json:"network_weight"`      // 0.3 (30%)
	TimeWeight        float64 `json:"time_weight"`         // 0.4 (40%)

	// Energy consumption parameters
	TargetEnergyUsage int64   `json:"target_energy_usage"` // CPU cycles
	EnergyTolerance   float64 `json:"energy_tolerance"`    // 0.1 (10%)

	// Network parameters
	TargetNetworkHashrate int64   `json:"target_network_hashrate"` // hashes per second
	NetworkTolerance      float64 `json:"network_tolerance"`       // 0.1 (10%)

	// Time parameters
	TimeTolerance float64 `json:"time_tolerance"` // 0.1 (10%)
}

DifficultyAdjustmentConfig holds configuration for difficulty adjustment

func DefaultDifficultyAdjustmentConfig

func DefaultDifficultyAdjustmentConfig() *DifficultyAdjustmentConfig

DefaultDifficultyAdjustmentConfig returns the default configuration

type WindowMetrics

type WindowMetrics struct {
	AverageBlockTime       time.Duration `json:"average_block_time"`
	AverageEnergyUsed      int64         `json:"average_energy_used"`
	AverageNetworkHashrate int64         `json:"average_network_hashrate"`
	BlockCount             int           `json:"block_count"`
}

WindowMetrics holds aggregated metrics for the adjustment window

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL