huge chain test, added 1.5% yearly inflation at 3.5 million blocks
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <stdint.h>
|
||||
#include <uint256.h>
|
||||
#include <stdbool.h>
|
||||
#include <block/chain.h>
|
||||
#include <block/block.h>
|
||||
|
||||
#define DECIMALS 1000000000000ULL
|
||||
#define DIFFICULTY_ADJUSTMENT_INTERVAL 960 // Every 960 blocks (roughly every 24 hours with a 90 second block time)
|
||||
@@ -12,6 +14,8 @@
|
||||
#define INITIAL_DIFFICULTY 0x1f0c1422 // Default compact target used by Autolykos2 PoW (This is ridiculously low)
|
||||
//#define INITIAL_DIFFICULTY 0x1d1b7c51 // This takes 90s on my machine with a single thread, good for testing
|
||||
|
||||
#define INFLATION_PERCENTAGE_PER_EPOCH 15 // 1.5%
|
||||
|
||||
// Future Autolykos2 constants:
|
||||
#define EPOCH_LENGTH 350000 // ~1 year at 90s
|
||||
#define BASE_DAG_SIZE (2ULL << 30) // 2 GB
|
||||
@@ -31,15 +35,53 @@
|
||||
* - Phase 2: Stable DAG growth (target is the max cap) to provide a stable environment for GPU miners, 320k blocks (roughly 11 months)
|
||||
**/
|
||||
|
||||
static uint64_t currentReward = 0; // Global variable to track current block reward; updated with each block mined
|
||||
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.
|
||||
|
||||
static uint256_t currentSupply = {{0, 0, 0, 0}}; // Global variable to track total supply; updated with each block mined
|
||||
|
||||
static inline uint64_t CalculateBlockReward(uint256_t currentSupply, uint64_t height) {
|
||||
// Inclusive of block 0
|
||||
(void)height;
|
||||
// Call every epoch
|
||||
static inline uint64_t GetInflationRateReward(uint256_t currentSupply, blockchain_t* chain) {
|
||||
if (!chain || !chain->blocks) { return 0x00; } // Invalid
|
||||
size_t height = Chain_Size(chain);
|
||||
|
||||
block_t* blk = (block_t*)Chain_GetBlock(chain, height - 1); // Last block
|
||||
if (!blk) { return 0x00; } // Invalid
|
||||
|
||||
if (height % EPOCH_LENGTH == 0) {
|
||||
// Calculate the new block reward (using all integer math to avoid floating point issues)
|
||||
|
||||
// 1. Multiply supply by 3
|
||||
uint256_t multiplied = currentSupply;
|
||||
uint256_t temp = currentSupply;
|
||||
uint256_add(&multiplied, &temp); // currentSupply * 2
|
||||
uint256_add(&multiplied, &temp); // currentSupply * 3
|
||||
|
||||
// 2. Divide by 70,000,000 using scalar short division
|
||||
uint64_t divisor = 70000000ULL;
|
||||
uint256_t quotient = {{0, 0, 0, 0}};
|
||||
unsigned __int128 remainder = 0;
|
||||
|
||||
// Work from the most significant limb to the least
|
||||
for (int i = 3; i >= 0; i--) {
|
||||
unsigned __int128 current = (remainder << 64) | multiplied.limbs[i];
|
||||
quotient.limbs[i] = (uint64_t)(current / divisor);
|
||||
remainder = current % divisor;
|
||||
}
|
||||
|
||||
currentReward = quotient.limbs[0]; // Update the global reward variable with the new calculated reward for this epoch
|
||||
return quotient.limbs[0]; // Return the least significant limb as the reward (the rest should be 0 for reasonable supply levels)
|
||||
}
|
||||
|
||||
return currentReward;
|
||||
}
|
||||
|
||||
static inline uint64_t CalculateBlockReward(uint256_t currentSupply, blockchain_t* chain) {
|
||||
if (!chain || !chain->blocks) { return 0x00; } // Invalid
|
||||
|
||||
uint64_t height = Chain_Size(chain);
|
||||
|
||||
if (currentSupply.limbs[1] > 0 ||
|
||||
currentSupply.limbs[2] > 0 ||
|
||||
@@ -58,7 +100,11 @@ static inline uint64_t CalculateBlockReward(uint256_t currentSupply, uint64_t he
|
||||
|
||||
// Check if the calculated reward has fallen below the floor
|
||||
if (reward < TAIL_EMISSION) {
|
||||
return TAIL_EMISSION;
|
||||
if (height < EPOCH_LENGTH * 10) { // Transitionary period to inflation of 1.5% per epoch
|
||||
return TAIL_EMISSION;
|
||||
} else {
|
||||
return GetInflationRateReward(currentSupply, chain); // After the transitionary period, switch to the inflation-based reward
|
||||
}
|
||||
}
|
||||
|
||||
return reward;
|
||||
|
||||
Reference in New Issue
Block a user