balance sheet stuff, added khash hashmaps

This commit is contained in:
2026-04-02 21:21:12 +02:00
parent b20ba9802e
commit df7787ed2d
10 changed files with 824 additions and 16 deletions

View File

@@ -9,6 +9,7 @@
#include <string.h>
#include <time.h>
#include <signal.h>
#include <balance_sheet.h>
#include <constants.h>
#include <autolykos2/autolykos2.h>
@@ -20,6 +21,7 @@
void handle_sigint(int sig) {
printf("Caught signal %d, exiting...\n", sig);
Block_ShutdownPowContext();
BalanceSheet_Destroy();
exit(0);
}
@@ -95,8 +97,9 @@ static bool MineBlock(block_t* block) {
int main(int argc, char* argv[]) {
signal(SIGINT, handle_sigint);
BalanceSheet_Init();
const char* chainDataDir = CHAIN_DATA_DIR;
const uint64_t blocksToMine = 4000000;
const uint64_t blocksToMine = 100;
const double targetSeconds = TARGET_BLOCK_TIME;
uint256_t currentSupply = uint256_from_u64(0);
@@ -107,7 +110,10 @@ int main(int argc, char* argv[]) {
return 1;
}
if (!Chain_LoadFromFile(chain, chainDataDir, &currentSupply, &difficultyTarget, &currentReward)) {
uint8_t lastSavedHash[32];
bool isFirstBlockOfLoadedChain = true;
if (!Chain_LoadFromFile(chain, chainDataDir, &currentSupply, &difficultyTarget, &currentReward, lastSavedHash)) {
printf("No existing chain loaded from %s\n", chainDataDir);
}
@@ -169,11 +175,15 @@ int main(int argc, char* argv[]) {
block->header.version = 1;
block->header.blockNumber = (uint64_t)Chain_Size(chain);
if (Chain_Size(chain) > 0) {
block_t* lastBlock = Chain_GetBlock(chain, Chain_Size(chain) - 1);
if (lastBlock) {
Block_CalculateHash(lastBlock, block->header.prevHash);
if (!isFirstBlockOfLoadedChain) {
block_t* lastBlock = Chain_GetBlock(chain, Chain_Size(chain) - 1);
if (lastBlock) {
Block_CalculateHash(lastBlock, block->header.prevHash);
} else {
memset(block->header.prevHash, 0, sizeof(block->header.prevHash));
}
} else {
memset(block->header.prevHash, 0, sizeof(block->header.prevHash));
memcpy(block->header.prevHash, lastSavedHash, sizeof(lastSavedHash));
}
} else {
memset(block->header.prevHash, 0, sizeof(block->header.prevHash));
@@ -221,7 +231,7 @@ int main(int argc, char* argv[]) {
uint8_t canonicalHash[32];
uint8_t powHash[32];
Block_CalculateHash(block, canonicalHash);
Block_CalculateAutolykos2Hash(block, powHash);
Block_CalculateAutolykos2Hash(block, powHash);
printf("Mined block %llu/%llu (height=%llu) nonce=%llu reward=%llu supply=%s diff=%#x merkle=%02x%02x%02x%02x... pow=%02x%02x%02x%02x... canonical=%02x%02x%02x%02x...\n",
(unsigned long long)(mined + 1),
(unsigned long long)blocksToMine,
@@ -252,6 +262,8 @@ int main(int argc, char* argv[]) {
GetNextDAGSeed(chain, dagSeed);
(void)Block_RebuildAutolykos2Dag(CalculateTargetDAGSize(chain), dagSeed);
}
isFirstBlockOfLoadedChain = false;
}
if (!Chain_SaveToFile(chain, chainDataDir, currentSupply, currentReward)) {
@@ -278,6 +290,8 @@ int main(int argc, char* argv[]) {
}
}*/
BalanceSheet_Print();
Chain_Destroy(chain);
Block_ShutdownPowContext();
return 0;