This commit is contained in:
2026-03-30 09:06:17 +02:00
parent 50e357d8a2
commit c358115af4
6 changed files with 272 additions and 111 deletions

View File

@@ -6,7 +6,10 @@
#include <stdbool.h>
#define DECIMALS 1000000000000ULL
#define EMISSION_SPEED_FACTOR 20
#define DIFFICULTY_ADJUSTMENT_INTERVAL 960 // Every 960 blocks (roughly every 24 hours with a 90 second block time)
// Max adjustment per is x2. So if blocks are coming in too fast, the difficulty will at most double every 24 hours, and vice versa if they're coming in too slow.
#define RANDOMX_KEY_ROTATION_INTERVAL 6720 // 1 week at 90s block time
#define TARGET_BLOCK_TIME 90 // Target block time in seconds
static const uint64_t M_CAP = 18446744073709551615ULL; // Max uint64
static const uint64_t TAIL_EMISSION = DECIMALS; // Emission floor is 1.0 coins per block
// No max supply. Instead of halving, it'll follow a more gradual, Monero-like emission curve.
@@ -26,8 +29,11 @@ static inline uint64_t CalculateBlockReward(uint256_t currentSupply, uint64_t he
uint64_t supply_64 = currentSupply.limbs[0];
// Formula: (M - Supply) >> 2^k - lifted from Monero's codebase (thanks guys!)
uint64_t reward = (M_CAP - supply_64) >> EMISSION_SPEED_FACTOR;
// Formula: ((M - Supply) >> 20) * 181 / 256
// Use 128-bit intermediate to avoid overflow while preserving integer math.
__uint128_t rewardWide = (((__uint128_t)(M_CAP - supply_64) >> 20) * 181u) >> 8;
uint64_t reward = (rewardWide > UINT64_MAX) ? UINT64_MAX : (uint64_t)rewardWide;
// At a block time of ~90s and a floor of 1.0 coins, this will make a curve of ~8.5 years
// Check if the calculated reward has fallen below the floor
if (reward < TAIL_EMISSION) {