stuff
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <randomx/librx_wrapper.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
uint64_t blockNumber;
|
||||
@@ -27,11 +28,13 @@ typedef struct {
|
||||
|
||||
block_t* Block_Create();
|
||||
void Block_CalculateHash(const block_t* block, uint8_t* outHash);
|
||||
void Block_CalculateMerkleRoot(const block_t* block, uint8_t* outHash);
|
||||
void Block_CalculateRandomXHash(const block_t* block, uint8_t* outHash);
|
||||
void Block_AddTransaction(block_t* block, signed_transaction_t* tx);
|
||||
void Block_RemoveTransaction(block_t* block, uint8_t* txHash);
|
||||
bool Block_HasValidProofOfWork(const block_t* block);
|
||||
bool Block_AllTransactionsValid(const block_t* block);
|
||||
void Block_Destroy(block_t* block);
|
||||
void Block_Print(const block_t* block);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user