bitcoin-mining-difficulty
Difficulty adjustment algorithm: 2016-block re-target window, max 4x factor, time-warp considerations, real-world hashrate dynamics. USE WHEN: predicting next adjustment, understanding hashrate/ difficulty cycles, building mining analytics.
What this skill does
# Difficulty Adjustment
Bitcoin re-targets the difficulty every **2016 blocks** to maintain
~10-minute average block time despite hashrate fluctuations.
## Algorithm
```python
def next_difficulty(current_difficulty, actual_time, expected_time):
# actual_time = sum of block_n.timestamp - block_(n-2015).timestamp
# expected_time = 2016 * 10 * 60 = 1,209,600 seconds
factor = expected_time / actual_time
factor = clamp(factor, 0.25, 4.0) # 4x max change per epoch
return current_difficulty * factor
```
Implemented in `pow.cpp:CalculateNextWorkRequired()` in Bitcoin Core.
## Time-warp protection
Sequential blocks must have:
- `block.timestamp > MTP(last 11 blocks)`.
- `block.timestamp ≤ network_time + 2 hours` (avoids future-dated
blocks).
These rules limit miner manipulation of timestamps to game the
adjustment.
## Real-world dynamics
- China mining ban (May 2021): hashrate dropped ~50% over weeks;
difficulty took ~3 weeks to drop accordingly. Miners enjoyed
high-revenue period during the lag.
- Halvings cause hashrate dips that recover over months.
- Seasonal fluctuations (China's wet season → cheaper hydropower
→ hashrate spikes).
## Common adjustments
Typical adjustments: 0.5% to 5% per epoch in normal conditions.
Large adjustments (10%+) signal major hashrate event (region ban,
ASIC manufacturing surge, etc.).
## Difficulty number vs hashrate
```
hashrate_estimate = difficulty * 2^32 / 600 # H/s
```
Where `2^32` = full nonce space probed for one solution at expected
target, and 600 seconds = average block time.
## Common bugs
- Computing actual_time incorrectly (off-by-one on block count).
- Forgetting the 4x cap → catastrophic divergence.
- Using block timestamps directly without MTP for time-locks.
## See also
- [pow/SKILL.md](../pow/SKILL.md)
- [stratum-v2/SKILL.md](../stratum-v2/SKILL.md)
Related in Data & Analytics
clawarr-suite
IncludedComprehensive management for self-hosted media stacks (Sonarr, Radarr, Lidarr, Readarr, Prowlarr, Bazarr, Overseerr, Plex, Tautulli, SABnzbd, Recyclarr, Unpackerr, Notifiarr, Maintainerr, Kometa, FlareSolverr). Deep library exploration, analytics, dashboard generation, content management, request handling, subtitle management, indexer control, download monitoring, quality profile sync, library cleanup automation, notification routing, collection/overlay management, and media tracker integration (Trakt, Letterboxd, Simkl).
querying-soql
IncludedSOQL query generation, optimization, and analysis with 100-point scoring. Use this skill when the user needs SOQL/SOSL authoring or optimization: natural-language-to-query generation, relationship queries, aggregates, query-plan analysis, and performance or safety improvements for Salesforce queries. TRIGGER when: user writes, optimizes, or debugs SOQL/SOSL queries, touches .soql files, or asks about relationship queries, aggregates, or query performance. DO NOT TRIGGER when: bulk data operations (use handling-sf-data), Apex DML logic (use generating-apex), or report/dashboard queries.
app-store-optimization
IncludedApp Store Optimization (ASO) toolkit for researching keywords, analyzing competitor rankings, generating metadata suggestions, and improving app visibility on Apple App Store and Google Play Store. Use when the user asks about ASO, app store rankings, app metadata, app titles and descriptions, app store listings, app visibility, or mobile app marketing on iOS or Android. Supports keyword research and scoring, competitor keyword analysis, metadata optimization, A/B test planning, launch checklists, and tracking ranking changes.
habit-flow
IncludedAI-powered atomic habit tracker with natural language logging, streak tracking, smart reminders, and coaching. Use for creating habits, logging completions naturally ("I meditated today"), viewing progress, and getting personalized coaching.
app-store-optimization
IncludedApp Store Optimization (ASO) toolkit for researching keywords, analyzing competitor rankings, generating metadata suggestions, and improving app visibility on Apple App Store and Google Play Store. Use when the user asks about ASO, app store rankings, app metadata, app titles and descriptions, app store listings, app visibility, or mobile app marketing on iOS or Android. Supports keyword research and scoring, competitor keyword analysis, metadata optimization, A/B test planning, launch checklists, and tracking ranking changes.
visualizing-data
IncludedBuilds dashboards, reports, and data-driven interfaces requiring charts, graphs, or visual analytics. Provides systematic framework for selecting appropriate visualizations based on data characteristics and analytical purpose. Includes 24+ visualization types organized by purpose (trends, comparisons, distributions, relationships, flows, hierarchies, geospatial), accessibility patterns (WCAG 2.1 AA compliance), colorblind-safe palettes, and performance optimization strategies. Use when creating visualizations, choosing chart types, displaying data graphically, or designing data interfaces.