throttling cli arg
This commit is contained in:
@@ -12,6 +12,8 @@ extern "C" {
|
|||||||
|
|
||||||
typedef struct Autolykos2Context Autolykos2Context;
|
typedef struct Autolykos2Context Autolykos2Context;
|
||||||
|
|
||||||
|
extern uint64_t autolykos2_sleepBetweenHashOperationsMicroseconds;
|
||||||
|
|
||||||
Autolykos2Context* Autolykos2_Create(void);
|
Autolykos2Context* Autolykos2_Create(void);
|
||||||
void Autolykos2_Destroy(Autolykos2Context* ctx);
|
void Autolykos2_Destroy(Autolykos2Context* ctx);
|
||||||
|
|
||||||
@@ -61,6 +63,8 @@ bool Autolykos2_FindNonceSingleCore(
|
|||||||
uint8_t outHash[32]
|
uint8_t outHash[32]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
void Autolykos2_SetSleepBetweenHashOperations(uint64_t sleepMicroseconds);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,6 +4,13 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
#include <windows.h>
|
||||||
|
#else
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint64_t autolykos2_sleepBetweenHashOperationsMicroseconds = 0;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t* buf;
|
uint8_t* buf;
|
||||||
@@ -239,7 +246,19 @@ static bool Autolykos2_HashCore(
|
|||||||
memcpy(finalInput + 32, accHash, 32);
|
memcpy(finalInput + 32, accHash, 32);
|
||||||
memcpy(finalInput + 64, nonceBytes, 8);
|
memcpy(finalInput + 64, nonceBytes, 8);
|
||||||
memcpy(finalInput + 72, heightBytes, 8);
|
memcpy(finalInput + 72, heightBytes, 8);
|
||||||
return Blake2b_Hash(finalInput, sizeof(finalInput), outHash, 32);
|
bool ok = Blake2b_Hash(finalInput, sizeof(finalInput), outHash, 32);
|
||||||
|
|
||||||
|
// Throttle between hash operations if configured (applies to all hash paths).
|
||||||
|
if (autolykos2_sleepBetweenHashOperationsMicroseconds > 0) {
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
DWORD ms = (DWORD)((autolykos2_sleepBetweenHashOperationsMicroseconds + 999) / 1000);
|
||||||
|
Sleep(ms);
|
||||||
|
#else
|
||||||
|
usleep((useconds_t)autolykos2_sleepBetweenHashOperationsMicroseconds);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
Autolykos2Context* Autolykos2_Create(void) {
|
Autolykos2Context* Autolykos2_Create(void) {
|
||||||
@@ -510,3 +529,7 @@ bool Autolykos2_FindNonceSingleCore(
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Autolykos2_SetSleepBetweenHashOperations(uint64_t sleepMicroseconds) {
|
||||||
|
autolykos2_sleepBetweenHashOperationsMicroseconds = sleepMicroseconds;
|
||||||
|
}
|
||||||
|
|||||||
24
src/main.c
24
src/main.c
@@ -444,8 +444,28 @@ static bool VerifyChainFully(blockchain_t* chain) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
(void)argc;
|
//(void)argc;
|
||||||
(void)argv;
|
//(void)argv;
|
||||||
|
if (argc > 1) {
|
||||||
|
// Check for potential startup args.
|
||||||
|
if (strcmp(argv[1], "--throttle") == 0) {
|
||||||
|
// Get throttle value in microseconds if provided, otherwise default to 1000 microseconds (1ms) between hash operations.
|
||||||
|
uint64_t throttleUs = 1000;
|
||||||
|
if (argc > 2) {
|
||||||
|
char* endptr = NULL;
|
||||||
|
throttleUs = strtoull(argv[2], &endptr, 10);
|
||||||
|
if (*argv[2] == '\0' || argv[2][0] == '-' || (endptr && *endptr != '\0')) {
|
||||||
|
printf("invalid throttle value\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Autolykos2_SetSleepBetweenHashOperations(throttleUs);
|
||||||
|
printf("Throttling hash operations with a sleep of %llu microseconds\n", (unsigned long long)throttleUs);
|
||||||
|
} else {
|
||||||
|
printf("Unknown argument: %s\n", argv[1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
signal(SIGINT, handle_sigint);
|
signal(SIGINT, handle_sigint);
|
||||||
srand((unsigned int)time(NULL));
|
srand((unsigned int)time(NULL));
|
||||||
|
|||||||
Reference in New Issue
Block a user