From 22f353cb61cef5f48daa607beed4d159fa3fa21a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 3 Jul 2022 13:20:13 -0400 Subject: [PATCH] Use the current block template as randomxInput --- src/miner.cpp | 28 ++++++++++++++++++---------- test_randomx | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index db9426270..86d9cc4f2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1157,8 +1157,10 @@ void static RandomXMiner() LogPrintf("Running HushRandomXMiner with %u transactions in block (%u bytes)\n",pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); // Search - uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); - pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); + uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; + uint32_t savebits; + int64_t nStart = GetTime(); + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); savebits = pblock->nBits; HASHTarget = arith_uint256().SetCompact(savebits); roundrobin_delay = ROUNDROBIN_DELAY; @@ -1184,10 +1186,16 @@ void static RandomXMiner() // since magic is 4 bytes, rpc port is 4 bytes and smart chain symbol must be at least 1 character long snprintf(randomxKey, 81, "%08x%s%08x", ASSETCHAINS_MAGIC, SMART_CHAIN_SYMBOL, ASSETCHAINS_RPCPORT); - char randomxInput[80]; - sprintf(randomxInput, "%08x Extreme Privacy Hush Smart Chain %08x", ASSETCHAINS_MAGIC, ASSETCHAINS_MAGIC); + //char randomxInput[80]; + //std::string randomxInput; + //sprintf(randomxInput, "%08x Extreme Privacy Hush Smart Chain %08x", ASSETCHAINS_MAGIC, ASSETCHAINS_MAGIC); - fprintf(stderr,"RandomXMiner: created randomxKey=%s , randomxInput=%s\n", randomxKey, randomxInput); + CDataStream randomxInput(SER_NETWORK, PROTOCOL_VERSION); + // Use the current block as randomx input + randomxInput << pblocktemplate->block; + + std::cerr << "RandomXMiner: randomxInput=" << HexStr(randomxInput) << "\n"; + fprintf(stderr,"RandomXMiner: created randomxKey=%s , randomxInput.size=%lu\n", randomxKey, randomxInput.size() ); //randomxInput); randomx_flags flags = randomx_get_flags(); randomx_cache *randomxCache = randomx_alloc_cache(flags); @@ -1206,7 +1214,7 @@ void static RandomXMiner() fprintf(stderr,"RandomXMiner: using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag); fprintf(stderr,"RandomXMiner: Mining_height=%u\n", Mining_height); - // Use the initial key at the start of the chain + // Use the initial key at the start of the chain, until the first key block if( (Mining_height) < randomxInterval + randomxBlockLag) { randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); fprintf(stderr,"RandomXMiner: initialized cache with initial key\n"); @@ -1229,22 +1237,22 @@ void static RandomXMiner() fprintf(stderr,"RandomXMiner: Cannot create RandomX VM, aborting!\n"); return; } - fprintf(stderr,"RandomXMiner: created VM\n"); + // fprintf(stderr,"RandomXMiner: created VM\n"); randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash); fprintf(stderr,"RandomXMiner: calculated randomx hash\n"); randomx_destroy_vm(myVM); - fprintf(stderr,"RandomXMiner: destroyed VM\n"); + // fprintf(stderr,"RandomXMiner: destroyed VM\n"); randomx_release_cache(randomxCache); - printf("RandomX Hash: "); + printf("RandomXMiner: randomxHash="); for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) { printf("%02x", randomxHash[i] & 0xff); } printf("\n"); - // TODO: use randomx hash to build a block + // Use randomx hash to build a valid block std::function)> validBlock = #ifdef ENABLE_WALLET diff --git a/test_randomx b/test_randomx index 4d783f4c4..bba394f6b 100755 --- a/test_randomx +++ b/test_randomx @@ -1,6 +1,6 @@ #!/bin/bash - ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX9 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 + ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX10 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 # to run via the debugger # type "run" when gdb prompt appears