|
| 1 | +# context.py for CPU-based Bitcoin Mining |
| 2 | + |
| 3 | +# Flag to indicate if the mining process should be shut down |
1 | 4 | fShutdown = False |
| 5 | + |
| 6 | +# List to keep track of the running state of threads (e.g., mining, listening) |
2 | 7 | listfThreadRunning = [False] * 2 |
| 8 | + |
| 9 | +# Current height of the local blockchain copy |
3 | 10 | local_height = 0 |
| 11 | + |
| 12 | +# Dictionary to store the best difficulty achieved for each height |
4 | 13 | nHeightDiff = {} |
| 14 | + |
| 15 | +# Hash of the previous block (to detect new blocks in the network) |
5 | 16 | updatedPrevHash = None |
| 17 | + |
| 18 | +# Mining-related parameters (updated with each new block or job) |
6 | 19 | job_id = None |
7 | 20 | prevhash = None |
8 | 21 | coinb1 = None |
|
15 | 28 | sub_details = None |
16 | 29 | extranonce1 = None |
17 | 30 | extranonce2_size = None |
| 31 | + |
| 32 | +# Performance Metrics for CPU Mining |
| 33 | +total_hashes_computed = 0 # Total number of hashes computed |
| 34 | +hash_rate = 0 # Hash rate (hashes per second) |
| 35 | +mining_time_per_block = [] # Time taken to mine each block |
| 36 | +resource_utilization = { # Resource utilization (CPU, memory) |
| 37 | + 'cpu_usage': 0, |
| 38 | + 'memory_usage': 0 |
| 39 | +} |
| 40 | + |
| 41 | +# Network Statistics |
| 42 | +network_difficulty = None # Current network difficulty |
| 43 | +average_block_time = None # Average time for block discovery in the network |
| 44 | + |
| 45 | +# Error Handling and Logging |
| 46 | +error_count = 0 # Number of errors encountered |
| 47 | +last_error_message = "" # Last error message for debugging |
| 48 | + |
| 49 | +# Adaptive Mining Configuration |
| 50 | +adaptive_difficulty = True # Flag to enable adaptive difficulty |
| 51 | +reconnection_attempts = 0 # Number of attempts to reconnect to the pool |
| 52 | + |
| 53 | +# Blockchain Data |
| 54 | +last_block_hashes = [] # Store hashes of the last N blocks |
| 55 | + |
| 56 | +# User Customization |
| 57 | +user_preferences = { |
| 58 | + 'logging_level': 'info', |
| 59 | + 'ui_settings': {} |
| 60 | +} |
0 commit comments