File size: 2,081 Bytes
1170181
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""

Utility functions for mining statistics and estimates

"""
import math
import logging

def calculate_mining_estimate(hash_rate_per_core: float, num_cores: int, target: int, best_hash: str) -> dict:
    """

    Calculate mining estimates based on current performance

    

    Args:

        hash_rate_per_core: Hashes per second per core

        num_cores: Number of cores being used

        target: Current network target

        best_hash: Best hash found so far (hex string)

    """
    total_hash_rate = hash_rate_per_core * num_cores
    
    # Convert target and best hash to integers for comparison
    target_int = target
    best_hash_int = int(best_hash, 16)
    
    # Calculate probability of finding a block
    max_target = int('0xFFFF' + '0' * 62, 16)
    probability_per_hash = target_int / max_target
    
    # Calculate expected hashes needed
    expected_hashes = 1 / probability_per_hash
    
    # Calculate time estimates
    seconds_to_block = expected_hashes / total_hash_rate
    days_to_block = seconds_to_block / (24 * 3600)
    
    # Calculate progress towards target
    progress_ratio = best_hash_int / target_int
    progress_percent = (1 - progress_ratio) * 100 if progress_ratio < 1 else 0
    
    return {
        'probability_per_hash': probability_per_hash,
        'expected_hashes_needed': expected_hashes,
        'estimated_days': days_to_block,
        'progress_percent': progress_percent,
        'total_hash_rate': total_hash_rate
    }

def log_mining_statistics(stats: dict):
    """Log mining statistics in a human-readable format"""
    logging.info(f"Mining Statistics:")
    logging.info(f"Total Hash Rate: {stats['total_hash_rate']/1e6:.2f} MH/s")
    logging.info(f"Probability per hash: {stats['probability_per_hash']:.2e}")
    logging.info(f"Expected hashes needed: {stats['expected_hashes_needed']:.2e}")
    logging.info(f"Estimated days to find block: {stats['estimated_days']:.2f} days")
    logging.info(f"Progress towards target: {stats['progress_percent']:.2f}%")