Compare commits

...

7 Commits

  1. 12
      contrib/sda_checkpoints.pl
  2. 12
      depends/packages/libcurl.mk
  3. 24
      doc/developer-notes.md
  4. 6
      src/hush_globals.h
  5. 172
      src/miner.cpp
  6. 18
      util/gen-linux-binary-release.sh

12
contrib/sda_checkpoints.pl

@ -12,8 +12,8 @@ my $hush = "./src/hush-cli";
my $getblock= "$hush getblock";
my $gethash = "$hush getblockhash";
my $gettree = "$hush getblockmerkletree";
my $start = shift || 1190000;
my $end = shift || 1260000;
my $start = shift || 1390000;
my $end = shift || 1422000;
my $stride = shift || 10000;
my $blocks = qx{$hush getblockcount};
@ -41,8 +41,12 @@ while (1) {
chomp $merkle;
chomp $blockhash;
chomp $blocktime;
$blocktime =~ s/^\s+|\s+$//g ;
print qq{{\n\t"network": "main",\n\t"height": "$block",\n\t"hash": "$blockhash",\n\t$blocktime\n\t"saplingTree": "$merkle"\n},\n};
$blocktime =~ s/^\s+|\s+$//g;
my $checkpoint = qq{{\n\t"network": "main",\n\t"height": "$block",\n\t"hash": "$blockhash",\n\t$blocktime\n\t"saplingTree": "$merkle"\n}\n};
my $filename = "$block.json";
open(FH, '>', $filename) or die $!;
print FH $checkpoint;
close(FH);
$block += $stride;
}

12
depends/packages/libcurl.mk

@ -1,9 +1,17 @@
package=libcurl
ifeq ($(host_os),mingw32)
$(package)_version=7.67.0
$(package)_file_name=curl-$($(package)_version).tar.gz
$(package)_sha256_hash=52af3361cf806330b88b4fe6f483b6844209d47ae196ac46da4de59bb361ab02
else
$(package)_version=7.77.0
$(package)_dependencies=wolfssl
$(package)_download_path=https://curl.haxx.se/download
$(package)_file_name=curl-$($(package)_version).tar.gz
$(package)_sha256_hash=b0a3428acb60fa59044c4d0baae4e4fc09ae9af1d8a3aa84b2e3fbcd99841f77
endif
$(package)_dependencies=wolfssl
$(package)_download_path=https://curl.haxx.se/download
$(package)_config_opts_linux=--disable-shared --enable-static --with-wolfssl --without-ssl --prefix=$(host_prefix) --host=$(host)
$(package)_config_opts_mingw32=--enable-mingw --disable-shared --enable-static --with-wolfssl --without-ssl --prefix=$(host_prefix) --host=x86_64-w64-mingw32
$(package)_config_opts_darwin=--disable-shared --enable-static --with-wolfssl --without-ssl --prefix=$(host_prefix)

24
doc/developer-notes.md

@ -104,6 +104,30 @@ We should also check a recent block height to verify it's working correctly. The
* If you stop a node, and restart, are the stats from `getchaintxtstats` correct, i.e. the anonset stats? For instance, `shielded_pool_size` should be close to 500000, if it's close to or exactly 0, something is wrong.
* Is there a new file called `zindex.dat` in `~/.hush/HUSH3/` ?
* Is `zindex.dat` 149 bytes ?
# Adding a PoW algorithm
We will describe here the high-level ideas on how to add a new PoW algorithm to
the Hush codebase. Adding a new PoW algo means adding a new option to the `-ac_algo`
CLI param for HSC's.
* Add the new value to the end of the `ASSETCHAINS_ALGORITHMS` array in `src/hush_utils.h`
* You cannot add it to the front because the first element is the default "equihash"
* You will also need to add a new constant, such as `ASSETCHAINS_FOOHASH` to `src/hush_globals.h`
* Increase the value of `ASSETCHAINS_NUMALGOS` by one
* This value cannot be automatically be determined by the length of the above array because Equihash has different supported variants of (N,K) values
* Add the new PoW mining library to a subdirectory in src, such as RandomX official code being in `src/RandomX`
* The largest part of adding a new PoW algo is adding a new class to src/miner.cpp
* Originally there was only BitcoinMiner, which was modified from a double-sha256 miner to an equihash miner, without changing the name
* When RandomX was added as an option, many big internals changes were needed to support more than a single miner class
* It is now easier to add PoW algos because the internals support using different miner classes
* Currently BitcoinMiner and RandomXMiner classes have a lot of duplicated code, but this is intentional
* In theory we could refactor the miner classes to share more code, but this means changes to one miner could break another and it is very challenging to test every possibile edge case for mining code
* So code duplication is purposeful, because it isolates the risk of breaking one PoW by changing another. We tried very hard to not break Equihash mining when adding RandomX mining.
* When adding a new mining class, copying the RandomXMiner class is best, since it's newer and does not contain various legacy code that still exists in BitcoinMiner
* So copy RandomXMiner to your new FooMiner, delete all the randomx-specific stuff and add in the PoW mining code
* Some other changes to src/miner.cpp will be needed
* Update `GenerateBitcoins` function to start mining threads with your new algo with `else if(ASSETCHAINS_ALGO == ASSETCHAINS_FOOHASH) { minerThreads->create_thread(&FooMiner)}`
# Coding

6
src/hush_globals.h

@ -81,11 +81,13 @@ std::vector<std::string> ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS;
// this is the offset in the ASSETCHAINS_ALGORITHMS array
#define _ASSETCHAINS_EQUIHASH 0
#define _ASSETCHAINS_RANDOMX 1
#define _ASSETCHAINS_MEMHASH 2
uint32_t ASSETCHAINS_NUMALGOS = 4; // there are different variants of equihash with different (N,K)
uint32_t ASSETCHAINS_NUMALGOS = 5; // there are different variants of equihash with different (N,K)
uint32_t ASSETCHAINS_EQUIHASH = _ASSETCHAINS_EQUIHASH;
uint32_t ASSETCHAINS_RANDOMX = _ASSETCHAINS_RANDOMX;
const char *ASSETCHAINS_ALGORITHMS[] = {"equihash", "randomx"};
uint32_t ASSETCHAINS_MEMHASH = _ASSETCHAINS_MEMHASH;
const char *ASSETCHAINS_ALGORITHMS[] = {"equihash", "randomx", "memhash"};
uint64_t ASSETCHAINS_NONCEMASK[] = {0xffff};
uint32_t ASSETCHAINS_NONCESHIFT[] = {32};
uint32_t ASSETCHAINS_HASHESPERROUND[] = {1};

172
src/miner.cpp

@ -118,7 +118,7 @@ public:
};
extern int8_t ASSETCHAINS_ADAPTIVEPOW;
extern uint32_t ASSETCHAINS_RANDOMX;
extern uint32_t ASSETCHAINS_RANDOMX, ASSETCHAINS_MEMHASH;
extern bool fRandomXDebug;
void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev)
@ -1412,6 +1412,172 @@ void static RandomXMiner()
c.disconnect();
}
#ifdef ENABLE_WALLET
void static MemhashMiner(CWallet *pwallet)
#else
void static MemhashMiner()
#endif
{
LogPrintf("HushMemhashMiner started\n");
SetThreadPriority(THREAD_PRIORITY_LOWEST);
RenameThread("hush-memhash");
const CChainParams& chainparams = Params();
#ifdef ENABLE_WALLET
// Each thread has its own key
CReserveKey reservekey(pwallet);
#endif
// Each thread has its own counter
unsigned int nExtraNonce = 0;
uint8_t *script; uint64_t total; int32_t i,j,gpucount=HUSH_MAXGPUCOUNT,notaryid = -1;
while ( (ASSETCHAIN_INIT == 0 || HUSH_INITDONE == 0) )
{
sleep(1);
if ( hush_baseid(SMART_CHAIN_SYMBOL) < 0 )
break;
}
std::mutex m_cs;
bool cancelSolver = false;
boost::signals2::connection c = uiInterface.NotifyBlockTip.connect(
[&m_cs, &cancelSolver](const uint256& hashNewTip) mutable {
std::lock_guard<std::mutex> lock{m_cs};
cancelSolver = true;
}
);
miningTimer.start();
// TODO: Start actual memhash stuff
try {
fprintf(stderr,"MemhashMiner: mining %s with memhash\n",SMART_CHAIN_SYMBOL);
while(true) {
fprintf(stderr,"MemhashMiner: beginning mining loop on %s with nExtraNonce=%u\n",SMART_CHAIN_SYMBOL, nExtraNonce);
if (chainparams.MiningRequiresPeers()) {
miningTimer.stop();
do {
bool fvNodesEmpty;
{
fvNodesEmpty = vNodes.empty();
}
if (!fvNodesEmpty )
break;
MilliSleep(15000);
} while (true);
miningTimer.start();
}
// Create new block
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
CBlockIndex* pindexPrev = chainActive.LastTip();
// If we don't have a valid chain tip to work from, wait and try again.
if (pindexPrev == nullptr) {
fprintf(stderr,"%s: null pindexPrev, trying again...\n",__func__);
MilliSleep(1000);
continue;
}
if ( Mining_height != pindexPrev->GetHeight()+1 )
{
Mining_height = pindexPrev->GetHeight()+1;
Mining_start = (uint32_t)time(NULL);
}
#ifdef ENABLE_WALLET
CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, 0);
#else
CBlockTemplate *ptr = CreateNewBlockWithKey();
#endif
if ( ptr == 0 )
{
if ( !GetBoolArg("-gen",false))
{
miningTimer.stop();
c.disconnect();
LogPrintf("HushMemhashMiner terminated\n");
return;
}
static uint32_t counter;
if ( counter++ < 10 )
fprintf(stderr,"MemhashMiner: created illegal blockB, retry with counter=%u\n", counter);
sleep(1);
continue;
}
unique_ptr<CBlockTemplate> pblocktemplate(ptr);
if (!pblocktemplate.get())
{
if (GetArg("-mineraddress", "").empty()) {
LogPrintf("Error in HushMemhashMiner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n");
} else {
// Should never reach here, because -mineraddress validity is checked in init.cpp
LogPrintf("Error in HushMemhashMiner: Invalid -mineraddress\n");
}
return;
}
CBlock *pblock = &pblocktemplate->block;
if ( ASSETCHAINS_REWARD[0] == 0 && !ASSETCHAINS_LASTERA )
{
if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT )
{
static uint32_t counter;
if ( counter++ < 10 )
fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",SMART_CHAIN_SYMBOL);
sleep(10);
continue;
} else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",SMART_CHAIN_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT);
}
IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
LogPrintf("Running HushMemhashMiner 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());
savebits = pblock->nBits;
HASHTarget = arith_uint256().SetCompact(savebits);
roundrobin_delay = ROUNDROBIN_DELAY;
Mining_start = 0;
gotinvalid = 0;
while (true)
{
if ( gotinvalid != 0 ) {
fprintf(stderr,"HushMemhashMiner: gotinvalid=%d\n",gotinvalid);
break;
}
hush_longestchain();
fprintf(stderr,"HushMemhashMiner: solving with nNonce = %s\n",pblock->nNonce.ToString().c_str());
arith_uint256 hashTarget;
hashTarget = HASHTarget;
CDataStream memhashInput(SER_NETWORK, PROTOCOL_VERSION);
// Use the current block as input
memhashInput << pblocktemplate->block;
//TODO: calculate actual memhash hash with input
//TODO: Use hash to build a valid block
}
}
} catch (const boost::thread_interrupted&) {
miningTimer.stop();
c.disconnect();
LogPrintf("HushRandomXMiner terminated\n");
throw;
} catch (const std::runtime_error &e) {
miningTimer.stop();
c.disconnect();
fprintf(stderr,"RandomXMiner: runtime error: %s\n", e.what());
return;
}
miningTimer.stop();
c.disconnect();
}
#ifdef ENABLE_WALLET
void static BitcoinMiner(CWallet *pwallet)
#else
@ -1869,12 +2035,16 @@ void static BitcoinMiner()
minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet));
} else if (ASSETCHAINS_ALGO == ASSETCHAINS_RANDOMX ) {
minerThreads->create_thread(boost::bind(&RandomXMiner, pwallet));
} else if (ASSETCHAINS_ALGO == ASSETCHAINS_MEMHASH ) {
minerThreads->create_thread(boost::bind(&MemhashMiner, pwallet));
}
#else
if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) {
minerThreads->create_thread(&BitcoinMiner);
} else if (ASSETCHAINS_ALGO == ASSETCHAINS_RANDOMX) {
minerThreads->create_thread(&RandomXMiner);
} else if (ASSETCHAINS_ALGO == ASSETCHAINS_MEMHASH ) {
minerThreads->create_thread(boost::bind(&MemhashMiner));
}
#endif
}

18
util/gen-linux-binary-release.sh

@ -8,7 +8,8 @@ set -x
#hardcode and uncomment if hushd is not running on this machine
#VERSION=3.6.3
VERSION=$(./src/hushd --version|grep version|cut -d' ' -f4|cut -d- -f1|sed 's/v//g')
FILE="hush-$VERSION-linux-amd64.tar"
DIR="hush-$VERSION-linux-amd64"
FILE="$DIR.tar"
TIME=$(perl -e 'print time')
if [ -d "build" ]
@ -17,14 +18,17 @@ then
echo "Moved existing build/ dir to build.$TIME"
fi
mkdir build
echo "Created new build/ dir"
cp contrib/asmap/asmap.dat build/
cp sapling*.params build/
BUILD="build/$DIR"
mkdir $BUILD
echo "Created new build dir $BUILD"
cp contrib/asmap/asmap.dat $BUILD
cp sapling*.params $BUILD
cd src
cp hushd hush-cli hush-tx hush-smart-chain dragonx-cli dragonxd ../build
cd ../build
cp hushd hush-cli hush-tx hush-smart-chain dragonx-cli dragonxd ../$BUILD
cd ../$BUILD
strip hushd hush-cli hush-tx
tar -f $FILE -c *
cd ..
tar -f $FILE -c hush-$VERSION-linux-amd64/*
gzip -9 $FILE
sha256sum *.gz
du -sh *.gz

Loading…
Cancel
Save