Monero-style emission
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <constants.h>
|
||||
#include <uint256.h>
|
||||
|
||||
typedef struct {
|
||||
DynArr* blocks;
|
||||
@@ -22,7 +24,7 @@ bool Chain_IsValid(blockchain_t* chain);
|
||||
void Chain_Wipe(blockchain_t* chain);
|
||||
|
||||
// I/O
|
||||
bool Chain_SaveToFile(blockchain_t* chain, const char* dirpath);
|
||||
bool Chain_LoadFromFile(blockchain_t* chain, const char* dirpath);
|
||||
bool Chain_SaveToFile(blockchain_t* chain, const char* dirpath, uint256_t currentSupply);
|
||||
bool Chain_LoadFromFile(blockchain_t* chain, const char* dirpath, uint256_t* outCurrentSupply);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,21 +7,24 @@
|
||||
|
||||
#define DECIMALS 1000000000000ULL
|
||||
#define EMISSION_SPEED_FACTOR 20
|
||||
const uint64_t M_CAP = 18446744073709551615ULL; // Max uint64
|
||||
const uint64_t TAIL_EMISSION = (uint64_t)(1.0 * DECIMALS); // Emission floor is 1.0 coins per block
|
||||
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;
|
||||
|
||||
if (current_supply.limbs[1] > 0 ||
|
||||
current_supply.limbs[2] > 0 ||
|
||||
current_supply.limbs[3] > 0 ||
|
||||
current_supply.limbs[0] >= M_CAP) {
|
||||
if (currentSupply.limbs[1] > 0 ||
|
||||
currentSupply.limbs[2] > 0 ||
|
||||
currentSupply.limbs[3] > 0 ||
|
||||
currentSupply.limbs[0] >= M_CAP) {
|
||||
return TAIL_EMISSION;
|
||||
}
|
||||
|
||||
uint64_t supply_64 = current_supply.limbs[0];
|
||||
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;
|
||||
@@ -34,4 +37,4 @@ static inline uint64_t CalculateBlockReward(uint256_t currentSupply, uint64_t he
|
||||
return reward;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -18,4 +18,4 @@ void RandomX_CalculateHash(const uint8_t* input, size_t inputLen, uint8_t* outpu
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -55,4 +55,4 @@ static inline bool uint256_add(uint256_t* a, const uint256_t* b) {
|
||||
return carry > 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user