quality-of-life improvements, lower client slave thread stack to 512KB (maybe still too much), dynamic fullverify - freeing transactions after verification

This commit is contained in:
2026-04-23 21:34:12 +02:00
parent 9c99eec3a8
commit a89a912898
8 changed files with 26 additions and 3 deletions

View File

@@ -8,6 +8,8 @@ I need to figure out a way to make the privacy work without a UTXO system, and i
Move the Networking Code to support win32 as well, as I'm just doing POSIX right now Move the Networking Code to support win32 as well, as I'm just doing POSIX right now
Maybe move the node system to an async event loop instead of spawning threads. Maybe move the node system to an async event loop instead of spawning threads.
A potential race could occur if the P2P node receives a new block, or flushes a new block to disk while the user is running a full verify.
DONE: DONE:
I want to move away from the Monero emission. I want to do something a bit radical for cryptocurrency, but I feel like it's necessary to make it more like money: I want to move away from the Monero emission. I want to do something a bit radical for cryptocurrency, but I feel like it's necessary to make it more like money:
a constant inflation rate of 1.5% per year. It's lower than fiat (USD is ~2.8% per year), and it additionally doesn't fluctuate during crisis. It's constant. a constant inflation rate of 1.5% per year. It's lower than fiat (USD is ~2.8% per year), and it additionally doesn't fluctuate during crisis. It's constant.

View File

@@ -10,6 +10,8 @@
// Nets // Nets
#define MAX_CONS 32 // Some baseline for now #define MAX_CONS 32 // Some baseline for now
#define LISTEN_PORT 9393 #define LISTEN_PORT 9393
#define TCP_THREAD_STACK_SIZE (512 * 1024) // 512 KB. We could get away with like 128 KB since it's mostly just recv bufs, but it's good having some breathing room.
// This is also for client threads. The server has the default (~8 MB on POSIX).
// Economics // Economics
#define DECIMALS 1000000000000ULL #define DECIMALS 1000000000000ULL

View File

@@ -4,6 +4,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <stddef.h> #include <stddef.h>
#include <constants.h>
#include <tcpd/tcpconnection.h> #include <tcpd/tcpconnection.h>
typedef struct { typedef struct {

View File

@@ -4,6 +4,7 @@
#include <arpa/inet.h> #include <arpa/inet.h>
#include <pthread.h> #include <pthread.h>
#include <stddef.h> #include <stddef.h>
#include <constants.h>
#include <tcpd/tcpconnection.h> #include <tcpd/tcpconnection.h>

View File

@@ -85,7 +85,7 @@ bool Transaction_Verify(const signed_transaction_t* tx) {
// If all checks pass, verify the signature // If all checks pass, verify the signature
return Crypto_VerifySignature( return Crypto_VerifySignature(
txHash, txHash,
sizeof(transaction_t), 32,
tx->signature.signature, tx->signature.signature,
tx->transaction.compressedPublicKey tx->transaction.compressedPublicKey
); );

View File

@@ -416,6 +416,11 @@ static bool VerifyChainFully(blockchain_t* chain) {
if (memcmp(blk->header.merkleRoot, expectedMerkle, sizeof(expectedMerkle)) != 0) { if (memcmp(blk->header.merkleRoot, expectedMerkle, sizeof(expectedMerkle)) != 0) {
return false; return false;
} }
// Transactions are persisted on disk. Once this block is fully verified,
// release its in-memory transaction list to reduce peak memory usage.
DynArr_destroy(blk->transactions);
blk->transactions = NULL;
} }
return true; return true;

View File

@@ -126,12 +126,18 @@ int TcpClient_Connect(
client->on_connect(conn); client->on_connect(conn);
} }
if (pthread_create(&conn->ioThread, NULL, TcpClient_ThreadProc, client) != 0) { pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, TCP_THREAD_STACK_SIZE);
if (pthread_create(&conn->ioThread, &attr, TcpClient_ThreadProc, client) != 0) {
TcpConnection_Destroy(conn); TcpConnection_Destroy(conn);
free(conn); free(conn);
client->connection = NULL; client->connection = NULL;
pthread_attr_destroy(&attr);
return -1; return -1;
} }
pthread_attr_destroy(&attr);
return 0; return 0;
} }

View File

@@ -144,11 +144,17 @@ static void* TcpServer_threadprocess(void* ptr) {
arg->clientPtr = heapCli; arg->clientPtr = heapCli;
arg->serverPtr = svr; arg->serverPtr = svr;
if (pthread_create(&heapCli->ioThread, NULL, TcpServer_clientthreadprocess, arg) != 0) { pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, TCP_THREAD_STACK_SIZE);
if (pthread_create(&heapCli->ioThread, &attr, TcpServer_clientthreadprocess, arg) != 0) {
free(arg); free(arg);
TcpServer_Disconnect(svr, heapCli); TcpServer_Disconnect(svr, heapCli);
pthread_attr_destroy(&attr);
continue; continue;
} }
pthread_attr_destroy(&attr);
} }
return NULL; return NULL;