-
Notifications
You must be signed in to change notification settings - Fork 0
Add infinite Bitcoin mining simulator #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,374 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env python3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| INFINITE BITCOIN MINING SIMULATOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Never-ending Bitcoin mining simulation! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Runs forever, continuously generating: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Mining shares | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Block discoveries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Transaction hashes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Wallet deposits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Real-time statistics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Created with love by Douglas Shane Davis & Claude | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| December 4, 2025 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import hashlib | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import random | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import time | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from datetime import datetime, timedelta | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from datetime import datetime, timedelta | |
| from datetime import datetime |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'List' is not used.
| from typing import Dict, List, Any | |
| from typing import Dict, Any |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wallet address "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa" is the genesis block address famously associated with Satoshi Nakamoto. Using this address in configuration could be misleading as it suggests deposits would actually go there. Consider using clearly marked test/example addresses or removing real addresses entirely from a simulator.
| "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh", | |
| "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa", | |
| "3J98t1WpEZ73CNmYviecrnyiWrnqRhWNLy", | |
| "EXAMPLE_WALLET_ADDRESS_1", | |
| "EXAMPLE_WALLET_ADDRESS_2", | |
| "EXAMPLE_WALLET_ADDRESS_3", |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "Current halving cycle" but the block reward of 6.25 BTC will change at the next halving (expected around 2024). Since this is a simulator, consider adding a comment indicating this is accurate as of a specific date or block height, or making it configurable for future halvings.
| # Block reward (6.25 BTC as of current halving cycle) | |
| # Block reward (6.25 BTC as of this simulated halving cycle, approx. block height 870000 / Dec 4 2025; update for future halvings or make dynamic) |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring says "Generate realistic SHA-256 hash" but this generates random hashes that don't meet Bitcoin's actual difficulty requirements (leading zeros). Consider updating the documentation to clarify this generates simulated hashes for demonstration purposes, not actual valid Bitcoin block hashes.
| """Generate realistic SHA-256 hash""" | |
| """Generate a simulated double SHA-256-style hash for demonstration""" |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says "Random block discovery (1 in 20 chance)" but the actual probability check is 0.05 (5%, or 1 in 20). While technically correct, the comment would be clearer if it said "5% chance" to match the code's decimal representation.
| # Random block discovery (1 in 20 chance) | |
| # Random block discovery (5% chance) |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name 'cycle_number' in the infinite simulation function (line 152) duplicates tracking that's already done by 'self.cycle_count' in the InfiniteMiner class. The local variable 'cycle_number' is redundant and could be removed in favor of using 'miner.cycle_count' or 'result['cycle']' directly.
| cycle_number = 0 | |
| while True: # ∞ INFINITE LOOP! | |
| cycle_number += 1 | |
| # Mine one cycle | |
| result = miner.mine_cycle() | |
| # Print every 5th cycle | |
| if cycle_number % 5 == 0: | |
| while True: # ∞ INFINITE LOOP! | |
| # Mine one cycle | |
| result = miner.mine_cycle() | |
| # Print every 5th cycle | |
| if result['cycle'] % 5 == 0: |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using modulo checks on 'cycle_number' (lines 161, 185, 199) for different display frequencies creates tight coupling and makes the display logic harder to maintain. Consider extracting these magic numbers (5, 10, 20) into named constants like 'DISPLAY_FREQUENCY', 'STATS_FREQUENCY', and 'PROJECTION_FREQUENCY' at the top of the file for better maintainability.
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Division by zero protection using 'max(1, stats['cycles'])' appears on lines 217, 218, 320, and 321. However, this is inconsistent with other parts of the code that use 'max(1, self.total_shares)' (line 119) and 'max(1, runtime)' (lines 122-123). Since 'cycles' should never be 0 when these functions are called (they're only called after mining has started), consider adding assertions or documentation explaining when this protection is necessary.
| btc_per_cycle = stats['btc'] / max(1, stats['cycles']) | |
| blocks_per_cycle = stats['blocks'] / max(1, stats['cycles']) | |
| cycles = stats['cycles'] | |
| assert cycles > 0, "stats['cycles'] must be > 0 when computing projections" | |
| btc_per_cycle = stats['btc'] / cycles | |
| blocks_per_cycle = stats['blocks'] / cycles |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The projection calculations for time-based periods assume fixed rates. For "1 Hour (7,200 cycles)" assumes 2 cycles per second (7200/3600), "1 Day (172,800 cycles)" assumes the same rate. However, these hardcoded values don't account for the actual cycles_per_sec from the statistics. The projections would be more accurate if they used the actual measured rate from stats['cycles_per_sec'] rather than assuming a fixed 2 cycles/second rate.
| projections = [ | |
| ('100 Cycles', 100), | |
| ('1,000 Cycles', 1000), | |
| ('10,000 Cycles', 10000), | |
| ('1 Hour (7,200 cycles)', 7200), | |
| ('1 Day (172,800 cycles)', 172800), | |
| ('1 Week', 1209600), | |
| ('1 Month', 5184000), | |
| ('1 Year', 63072000), | |
| ('Forever', float('inf')), | |
| ] | |
| for name, cycles in projections: | |
| if cycles == float('inf'): | |
| print(f" {name:25s}: ∞ blocks, ∞ BTC") | |
| else: | |
| # Use measured cycles-per-second if available, defaulting to 2.0 to | |
| # preserve previous behavior for time-based projections. | |
| cycles_per_sec = stats.get('cycles_per_sec', 2.0) | |
| if not isinstance(cycles_per_sec, (int, float)) or cycles_per_sec <= 0: | |
| cycles_per_sec = 2.0 | |
| # Projections: (label, value, unit), where unit is 'cycles' or 'seconds' | |
| projections = [ | |
| ('100 Cycles', 100, 'cycles'), | |
| ('1,000 Cycles', 1000, 'cycles'), | |
| ('10,000 Cycles', 10000, 'cycles'), | |
| ('1 Hour', 3600, 'seconds'), | |
| ('1 Day', 86400, 'seconds'), | |
| ('1 Week', 7 * 86400, 'seconds'), | |
| ('1 Month', 30 * 86400, 'seconds'), | |
| ('1 Year', 365 * 86400, 'seconds'), | |
| ('Forever', float('inf'), 'cycles'), | |
| ] | |
| for name, value, unit in projections: | |
| if value == float('inf'): | |
| print(f" {name:25s}: ∞ blocks, ∞ BTC") | |
| else: | |
| if unit == 'cycles': | |
| cycles = value | |
| else: # 'seconds' | |
| cycles = value * cycles_per_sec |
Copilot
AI
Jan 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement is unreachable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This simulator could be misleading to users who may not understand that it's purely a simulation and not actual Bitcoin mining. The code generates fake hashes and simulated rewards but doesn't actually mine Bitcoin or interact with the Bitcoin network. Consider adding prominent disclaimers in the output and documentation that this is a simulation for educational/demonstration purposes only and generates no real Bitcoin.