Spaces:
Build error
Build error
| """ | |
| 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}%") |