temoporarily changed DAG size for testing, fix TX loading, move some TX logic to Transaction_Init()

This commit is contained in:
2026-04-03 15:20:13 +02:00
parent b83f52a448
commit ae64bb9dfc
6 changed files with 30 additions and 7 deletions

View File

@@ -51,6 +51,7 @@ typedef struct {
transaction_sig_t signature; transaction_sig_t signature;
} signed_transaction_t; } signed_transaction_t;
void Transaction_Init(signed_transaction_t* tx);
void Transaction_CalculateHash(const signed_transaction_t* tx, uint8_t* outHash); void Transaction_CalculateHash(const signed_transaction_t* tx, uint8_t* outHash);
void Transaction_Sign(signed_transaction_t* tx, const uint8_t* privateKey); void Transaction_Sign(signed_transaction_t* tx, const uint8_t* privateKey);
bool Transaction_Verify(const signed_transaction_t* tx); bool Transaction_Verify(const signed_transaction_t* tx);

View File

@@ -30,7 +30,8 @@
// Future Autolykos2 constants: // Future Autolykos2 constants:
#define EPOCH_LENGTH 350000 // ~1 year at 90s #define EPOCH_LENGTH 350000 // ~1 year at 90s
#define DAG_BASE_GROWTH (1ULL << 30) // 1 GB per epoch, adjusted by acceleration #define DAG_BASE_GROWTH (1ULL << 30) // 1 GB per epoch, adjusted by acceleration
#define DAG_BASE_SIZE (6ULL << 30) // 6 GB, adjusted per cycle based off DAG_BASE_GROWTH //#define DAG_BASE_SIZE (6ULL << 30) // 6 GB, adjusted per cycle based off DAG_BASE_GROWTH
#define DAG_BASE_SIZE (1ULL << 30) // TEMPORARY FOR TESTING
// Swings - calculated as MIN(percentage, absolute GB) to prevent absurd swings from low hashrate or very large DAG growth // Swings - calculated as MIN(percentage, absolute GB) to prevent absurd swings from low hashrate or very large DAG growth
#define DAG_MAX_UP_SWING_PERCENTAGE 1.15 // 15% #define DAG_MAX_UP_SWING_PERCENTAGE 1.15 // 15%
#define DAG_MAX_DOWN_SWING_PERCENTAGE 0.90 // 10% #define DAG_MAX_DOWN_SWING_PERCENTAGE 0.90 // 10%

View File

@@ -52,6 +52,10 @@ block_t* Block_Create() {
free(block); free(block);
return NULL; return NULL;
} }
// Zero out padding
memset(block->header.reserved, 0, sizeof(block->header.reserved));
return block; return block;
} }

View File

@@ -521,10 +521,18 @@ bool Chain_LoadFromFile(blockchain_t* chain, const char* dirpath, uint256_t* out
}*/ // Transactions are not read, we use the merkle root for validity }*/ // Transactions are not read, we use the merkle root for validity
blk->transactions = NULL; blk->transactions = NULL;
Chain_AddBlock(chain, blk); // Loading from disk currently restores headers only. Do not run Chain_AddBlock,
// because it enforces transaction presence and mutates balances.
if (!DynArr_push_back(chain->blocks, blk)) {
fclose(chainFile);
fclose(tableFile);
Block_Destroy(blk);
return false;
}
chain->size++;
// Chain_AddBlock stores blocks by value, so the copied block now owns // DynArr_push_back stores blocks by value, so the copied block now owns
// blk->transactions. Only free the temporary wrapper struct here. // blk->transactions (NULL in header-only load mode). Free wrapper only.
free(blk); free(blk);
} }

View File

@@ -1,6 +1,14 @@
#include <block/transaction.h> #include <block/transaction.h>
#include <string.h> #include <string.h>
void Transaction_Init(signed_transaction_t* tx) {
if (!tx) { return; }
// Zero out everything
memset(tx, 0, sizeof(signed_transaction_t));
// NOTE: Other things might be added here
}
void Transaction_CalculateHash(const signed_transaction_t* tx, uint8_t* outHash) { void Transaction_CalculateHash(const signed_transaction_t* tx, uint8_t* outHash) {
if (!tx || !outHash) { if (!tx || !outHash) {
return; return;

View File

@@ -158,7 +158,7 @@ int main(int argc, char* argv[]) {
BalanceSheet_Init(); BalanceSheet_Init();
const char* chainDataDir = CHAIN_DATA_DIR; const char* chainDataDir = CHAIN_DATA_DIR;
const uint64_t blocksToMine = 100; const uint64_t blocksToMine = 1000;
const double targetSeconds = TARGET_BLOCK_TIME; const double targetSeconds = TARGET_BLOCK_TIME;
uint256_t currentSupply = uint256_from_u64(0); uint256_t currentSupply = uint256_from_u64(0);
@@ -264,7 +264,7 @@ int main(int argc, char* argv[]) {
block->header.nonce = 0; block->header.nonce = 0;
signed_transaction_t coinbaseTx; signed_transaction_t coinbaseTx;
memset(&coinbaseTx, 0, sizeof(coinbaseTx)); Transaction_Init(&coinbaseTx);
coinbaseTx.transaction.version = 1; coinbaseTx.transaction.version = 1;
coinbaseTx.transaction.amount1 = currentReward; coinbaseTx.transaction.amount1 = currentReward;
coinbaseTx.transaction.fee = 0; coinbaseTx.transaction.fee = 0;
@@ -345,7 +345,7 @@ int main(int argc, char* argv[]) {
MakeTestRecipientAddress(recipientAddress); MakeTestRecipientAddress(recipientAddress);
signed_transaction_t spendTx; signed_transaction_t spendTx;
memset(&spendTx, 0, sizeof(spendTx)); Transaction_Init(&spendTx);
spendTx.transaction.version = 1; spendTx.transaction.version = 1;
spendTx.transaction.fee = 0; spendTx.transaction.fee = 0;
spendTx.transaction.amount1 = spendAmount; spendTx.transaction.amount1 = spendAmount;
@@ -383,6 +383,7 @@ int main(int argc, char* argv[]) {
spendBlock->header.nonce = 0; spendBlock->header.nonce = 0;
signed_transaction_t testCoinbaseTx; signed_transaction_t testCoinbaseTx;
Transaction_Init(&testCoinbaseTx);
memset(&testCoinbaseTx, 0, sizeof(testCoinbaseTx)); memset(&testCoinbaseTx, 0, sizeof(testCoinbaseTx));
testCoinbaseTx.transaction.version = 1; testCoinbaseTx.transaction.version = 1;
testCoinbaseTx.transaction.amount1 = currentReward; testCoinbaseTx.transaction.amount1 = currentReward;