aboutsummaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2020-09-06 15:49:36 +0200
committerRiccardo Spagni <ric@spagni.net>2020-09-06 15:49:37 +0200
commitaefa7740c38754b31a4f5748569ac1af59034667 (patch)
treeffb822e7c7e0929d70b706f26f29f94caec7aecd /src/crypto
parentMerge pull request #6802 (diff)
parentfunctional_tests: add a large (many randomx epochs) p2p reorg test (diff)
downloadmonero-aefa7740c38754b31a4f5748569ac1af59034667.tar.xz
Merge pull request #6111
d20ff4f64 functional_tests: add a large (many randomx epochs) p2p reorg test (moneromooo-monero) 6a0b3b1f8 functional_tests: add randomx tests (moneromooo-monero) 9d42649d5 core: fix mining from a block that's not the current top (moneromooo-monero)
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/rx-slow-hash.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/crypto/rx-slow-hash.c b/src/crypto/rx-slow-hash.c
index 1d7f09cab..fa35a32e2 100644
--- a/src/crypto/rx-slow-hash.c
+++ b/src/crypto/rx-slow-hash.c
@@ -116,6 +116,46 @@ static inline int enabled_flags(void) {
#define SEEDHASH_EPOCH_BLOCKS 2048 /* Must be same as BLOCKS_SYNCHRONIZING_MAX_COUNT in cryptonote_config.h */
#define SEEDHASH_EPOCH_LAG 64
+static inline int is_power_of_2(uint64_t n) { return n && (n & (n-1)) == 0; }
+
+static int get_seedhash_epoch_lag(void)
+{
+ static unsigned int lag = (unsigned int)-1;
+ if (lag != (unsigned int)-1)
+ return lag;
+ const char *e = getenv("SEEDHASH_EPOCH_LAG");
+ if (e)
+ {
+ lag = atoi(e);
+ if (lag > SEEDHASH_EPOCH_LAG || !is_power_of_2(lag))
+ lag = SEEDHASH_EPOCH_LAG;
+ }
+ else
+ {
+ lag = SEEDHASH_EPOCH_LAG;
+ }
+ return lag;
+}
+
+static unsigned int get_seedhash_epoch_blocks(void)
+{
+ static unsigned int blocks = (unsigned int)-1;
+ if (blocks != (unsigned int)-1)
+ return blocks;
+ const char *e = getenv("SEEDHASH_EPOCH_BLOCKS");
+ if (e)
+ {
+ blocks = atoi(e);
+ if (blocks < 2 || blocks > SEEDHASH_EPOCH_BLOCKS || !is_power_of_2(blocks))
+ blocks = SEEDHASH_EPOCH_BLOCKS;
+ }
+ else
+ {
+ blocks = SEEDHASH_EPOCH_BLOCKS;
+ }
+ return blocks;
+}
+
void rx_reorg(const uint64_t split_height) {
int i;
CTHR_MUTEX_LOCK(rx_mutex);
@@ -130,14 +170,16 @@ void rx_reorg(const uint64_t split_height) {
}
uint64_t rx_seedheight(const uint64_t height) {
- uint64_t s_height = (height <= SEEDHASH_EPOCH_BLOCKS+SEEDHASH_EPOCH_LAG) ? 0 :
- (height - SEEDHASH_EPOCH_LAG - 1) & ~(SEEDHASH_EPOCH_BLOCKS-1);
+ const uint64_t seedhash_epoch_lag = get_seedhash_epoch_lag();
+ const uint64_t seedhash_epoch_blocks = get_seedhash_epoch_blocks();
+ uint64_t s_height = (height <= seedhash_epoch_blocks+seedhash_epoch_lag) ? 0 :
+ (height - seedhash_epoch_lag - 1) & ~(seedhash_epoch_blocks-1);
return s_height;
}
void rx_seedheights(const uint64_t height, uint64_t *seedheight, uint64_t *nextheight) {
*seedheight = rx_seedheight(height);
- *nextheight = rx_seedheight(height + SEEDHASH_EPOCH_LAG);
+ *nextheight = rx_seedheight(height + get_seedhash_epoch_lag());
}
typedef struct seedinfo {
@@ -194,7 +236,7 @@ static void rx_initdata(randomx_cache *rs_cache, const int miners, const uint64_
void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const char *seedhash, const void *data, size_t length,
char *hash, int miners, int is_alt) {
uint64_t s_height = rx_seedheight(mainheight);
- int toggle = (s_height & SEEDHASH_EPOCH_BLOCKS) != 0;
+ int toggle = (s_height & get_seedhash_epoch_blocks()) != 0;
randomx_flags flags = enabled_flags() & ~disabled_flags();
rx_state *rx_sp;
randomx_cache *cache;