Documentation
¶
Index ¶
- type BlockMetrics
- type DifficultyAdjuster
- func (da *DifficultyAdjuster) AggregateWindowMetrics(blockMetrics []*BlockMetrics) *WindowMetrics
- func (da *DifficultyAdjuster) CalculateNewDifficulty(currentDifficulty *big.Int, windowMetrics *WindowMetrics) *big.Int
- func (da *DifficultyAdjuster) GetAdjustmentWindowSize() int
- func (da *DifficultyAdjuster) GetConfig() *DifficultyAdjustmentConfig
- func (da *DifficultyAdjuster) ShouldAdjustDifficulty(blockNumber int) bool
- func (da *DifficultyAdjuster) UpdateConfig(newConfig *DifficultyAdjustmentConfig)
- func (da *DifficultyAdjuster) ValidateMetrics(metrics *BlockMetrics) error
- type DifficultyAdjustmentConfig
- type WindowMetrics
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 ¶
func (da *DifficultyAdjuster) GetConfig() *DifficultyAdjustmentConfig
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