Skip to content

Commit

Permalink
Merge pull request #52 from JSKitty/sync_tests_fix
Browse files Browse the repository at this point in the history
[Tests] Fix sync_tests header include
  • Loading branch information
Liquid369 authored Jun 4, 2021
2 parents ca92da3 + ec82e16 commit ccae35c
Show file tree
Hide file tree
Showing 21 changed files with 738 additions and 270 deletions.
37 changes: 33 additions & 4 deletions doc/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,48 @@ RPC Changes

The `backupwallet` RPC command no longer allows for overwriting the currently in use wallet.dat file. This was done to avoid potential file corruption caused by multiple conflicting file access operations.

### Spendzerocoin Security Level Removed

- "isPublicSpend" boolean (optional) input parameter is removed from the following commands:
- `createrawzerocoinspend`
- `spendzerocoin`
- `spendzerocoinmints`
- `spendrawzerocoin`

The `securitylevel` argument has been removed from the `spendzerocoin` RPC command.

### Spendzerocoinmints Added

- "mintchange" and "minimizechange" boolean input parameters are removed from the following commands:
- `spendzerocoin`

Introduce the `spendzerocoinmints` RPC call to enable spending specific zerocoins, provided as an array of hex strings (serial hashes).

### Getreceivedbyaddress Update

- `setstakesplitthreshold` now accepts decimal amounts. If the provided value is `0`, split staking gets disabled. `getstakesplitthreshold` returns a double.

When calling `getreceivedbyaddress` with a non-wallet address, return a proper error code/message instead of just `0`

### Validateaddress More Verbosity
- The output of `getstakingstatus` was reworked. It now shows the following information:
```
{
"staking_status": true|false, (boolean) whether the wallet is staking or not
"staking_enabled": true|false, (boolean) whether staking is enabled/disabled in pivx.conf
"coldstaking_enabled": true|false, (boolean) whether cold-staking is enabled/disabled in pivx.conf
"haveconnections": true|false, (boolean) whether network connections are present
"mnsync": true|false, (boolean) whether masternode data is synced
"walletunlocked": true|false, (boolean) whether the wallet is unlocked
"stakeablecoins": n, (numeric) number of stakeable UTXOs
"stakingbalance": d, (numeric) DOGEC value of the stakeable coins (minus reserve balance, if any)
"stakesplitthreshold": d, (numeric) value of the current threshold for stake split
"lastattempt_age": n, (numeric) seconds since last stake attempt
"lastattempt_depth": n, (numeric) depth of the block on top of which the last stake attempt was made
"lastattempt_hash": xxx, (hex string) hash of the block on top of which the last stake attempt was made
"lastattempt_coins": n, (numeric) number of stakeable coins available during last stake attempt
"lastattempt_tries": n, (numeric) number of stakeable coins checked during last stake attempt
}
```


### Removed commands

`validateaddress` now has the ability to return more (non-critical or identifying) details about P2SH (multisig) addresses by removing the needless check against ISMINE_NO.

Expand Down
3 changes: 0 additions & 3 deletions src/config/dogecash-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@
/* Define to 1 if you have the `crypt32' library (-lcrypt32). */
#undef HAVE_LIBCRYPT32

/* Define to 1 if you have the `crypto' library (-lcrypto). */
#undef HAVE_LIBCRYPTO

/* Define to 1 if you have the `gdi32' library (-lgdi32). */
#undef HAVE_LIBGDI32

Expand Down
12 changes: 0 additions & 12 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ bool Stake(const CBlockIndex* pindexPrev, CStakeInput* stakeInput, unsigned int

// Time protocol V2: one-try
if (Params().IsTimeProtocolV2(nHeight)) {
// store a time stamp of when we last hashed on this block
mapHashedBlocks.clear();
mapHashedBlocks[pindexPrev->nHeight] = GetTime();

// check required min depth for stake
const int nHeightBlockFrom = pindexFrom->nHeight;
if (nHeight < nHeightBlockFrom + Params().COINSTAKE_MIN_DEPTH())
Expand Down Expand Up @@ -400,10 +396,6 @@ bool StakeV1(const CBlockIndex* pindexPrev, CStakeInput* stakeInput, const uint3
return error("%s : stake age violation, nTimeBlockFrom = %d, prevBlockTime = %d -- maxTime = %d ", __func__, nTimeBlockFrom, prevBlockTime, maxTime);

while (nTryTime > minTime) {
// store a time stamp of when we last hashed on this block
mapHashedBlocks.clear();
mapHashedBlocks[pindexPrev->nHeight] = GetTime();

//new block came in, move on
if (chainActive.Height() != pindexPrev->nHeight) break;

Expand All @@ -418,10 +410,6 @@ bool StakeV1(const CBlockIndex* pindexPrev, CStakeInput* stakeInput, const uint3
}

nTimeTx = nTryTime;

mapHashedBlocks.clear();
mapHashedBlocks[pindexPrev->nHeight] = GetTime(); //store a time stamp of when we last hashed on this block

return fSuccess;
}

Expand Down
16 changes: 3 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ using namespace libzerocoin;
RecursiveMutex cs_main;

BlockMap mapBlockIndex;
map<uint256, uint256> mapProofOfStake;
set<pair<COutPoint, unsigned int> > setStakeSeen;
map<unsigned int, unsigned int> mapHashedBlocks;
std::map<uint256, uint256> mapProofOfStake;
CChain chainActive;
CBlockIndex* pindexBestHeader = nullptr;
int64_t nTimeBestReceived = 0;
Expand Down Expand Up @@ -2926,7 +2924,7 @@ bool RecalculateDOGECSupply(int nHeightStart, bool fSkipZdogec)
pindex->nMoneySupply = nSupplyPrev + nValueOut - nValueIn;
nSupplyPrev = pindex->nMoneySupply;

// Rewrite zpiv supply too
// Rewrite zdogec supply too
if (!fSkipZdogec && pindex->nHeight >= Params().Zerocoin_StartHeight()) {
UpdatezdogecSupply(block, pindex, true);
}
Expand Down Expand Up @@ -3016,7 +3014,7 @@ bool UpdatezdogecSupply(const CBlock& block, CBlockIndex* pindex, bool fJustChec
//Reset the supply to previous block
pindex->mapZerocoinSupply = pindex->pprev->mapZerocoinSupply;

//Add mints to zPIV supply (mints are forever disabled after last checkpoint)
//Add mints to zdogec supply (mints are forever disabled after last checkpoint)
if (pindex->nHeight < Params().Zerocoin_Block_LastGoodCheckpoint()) {
std::list<CZerocoinMint> listMints;
std::set<uint256> setAddedToWallet;
Expand Down Expand Up @@ -4093,10 +4091,6 @@ CBlockIndex* AddToBlockIndex(const CBlock& block)
pindexNew->nSequenceId = 0;
BlockMap::iterator mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;

//mark as PoS seen
if (pindexNew->IsProofOfStake())
setStakeSeen.insert(make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime));

pindexNew->phashBlock = &((*mi).first);
BlockMap::iterator miPrev = mapBlockIndex.find(block.hashPrevBlock);
if (miPrev != mapBlockIndex.end()) {
Expand Down Expand Up @@ -5244,10 +5238,6 @@ CBlockIndex* InsertBlockIndex(uint256 hash)
throw runtime_error("LoadBlockIndex() : new CBlockIndex failed");
mi = mapBlockIndex.insert(make_pair(hash, pindexNew)).first;

//mark as PoS seen
if (pindexNew->IsProofOfStake())
setStakeSeen.insert(make_pair(pindexNew->prevoutStake, pindexNew->nStakeTime));

pindexNew->phashBlock = &((*mi).first);

return pindexNew;
Expand Down
5 changes: 0 additions & 5 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,9 @@ extern bool fClearSpendCache;
extern bool fLargeWorkForkFound;
extern bool fLargeWorkInvalidChainFound;

extern unsigned int nStakeMinAge;
extern int64_t nLastCoinStakeSearchInterval;
extern int64_t nLastCoinStakeSearchTime;
extern int64_t nReserveBalance;

extern std::map<uint256, int64_t> mapRejectedBlocks;
extern std::map<unsigned int, unsigned int> mapHashedBlocks;
extern std::set<std::pair<COutPoint, unsigned int> > setStakeSeen;
extern std::map<uint256, int64_t> mapZerocoinspends; //txid, time received

/** Best header we've seen so far (used for getheaders queries' starting points). */
Expand Down
101 changes: 50 additions & 51 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class COrphan

uint64_t nLastBlockTx = 0;
uint64_t nLastBlockSize = 0;
int64_t nLastCoinStakeSearchInterval = 0;

// We want to sort transactions by priority and fee rate, so:
typedef boost::tuple<double, CFeeRate, const CTransaction*> TxPriority;
Expand Down Expand Up @@ -102,28 +101,30 @@ void UpdateTime(CBlockHeader* pblock, const CBlockIndex* pindexPrev)
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
}

CBlockIndex* GetChainTip()
{
LOCK(cs_main);
CBlockIndex* p = chainActive.Tip();
if (!p)
return nullptr;
// Do not pass in the chain active tip, because it can change.
// Instead pass the blockindex directly from mapblockindex, which is const
return mapBlockIndex.at(p->GetBlockHash());
}

std::pair<int, std::pair<uint256, uint256> > pCheckpointCache;
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, bool fProofOfStake)
{
CReserveKey reservekey(pwallet);

// Create new block
unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
if (!pblocktemplate.get())
return NULL;
std::unique_ptr<CBlockTemplate> pblocktemplate(new CBlockTemplate());
if (!pblocktemplate.get()) return nullptr;
CBlock* pblock = &pblocktemplate->block; // pointer for convenience

// Tip
CBlockIndex* pindexPrev = nullptr;
{ // Don't keep cs_main locked
LOCK(cs_main);
pindexPrev = chainActive.Tip();
if (!pindexPrev)
return nullptr;
// Do not pass in the chain tip, because it can change.
// Instead pass the blockindex directly from mapblockindex, which is const
pindexPrev = mapBlockIndex.at(pindexPrev->GetBlockHash());
}
CBlockIndex* pindexPrev = GetChainTip();
if (!pindexPrev) return nullptr;

const int nHeight = pindexPrev->nHeight + 1;

Expand Down Expand Up @@ -156,32 +157,20 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
pblocktemplate->vTxFees.push_back(-1); // updated at end
pblocktemplate->vTxSigOps.push_back(-1); // updated at end

// ppcoin: if coinstake available add coinstake tx
static int64_t nLastCoinStakeSearchTime = GetAdjustedTime(); // only initialized at startup

if (fProofOfStake) {
boost::this_thread::interruption_point();
pblock->nTime = GetAdjustedTime();
pblock->nBits = GetNextWorkRequired(pindexPrev, pblock);
CMutableTransaction txCoinStake;
int64_t nSearchTime = pblock->nTime; // search to current time
bool fStakeFound = false;
if (nSearchTime >= nLastCoinStakeSearchTime) {
int64_t nTxNewTime = 0;
if (pwallet->CreateCoinStake(*pwallet, pindexPrev, pblock->nBits, nSearchTime - nLastCoinStakeSearchTime, txCoinStake, nTxNewTime)) {
pblock->nTime = nTxNewTime;
pblock->vtx[0].vout[0].SetEmpty();
pblock->vtx.push_back(CTransaction(txCoinStake));
fStakeFound = true;
}
nLastCoinStakeSearchInterval = nSearchTime - nLastCoinStakeSearchTime;
nLastCoinStakeSearchTime = nSearchTime;
}

if (!fStakeFound) {
int64_t nTxNewTime = 0;
if (!pwallet->CreateCoinStake(*pwallet, pindexPrev, pblock->nBits, txCoinStake, nTxNewTime)) {
LogPrint("staking", "CreateNewBlock(): stake not found\n");
return NULL;
return nullptr;
}
// Stake found
pblock->nTime = nTxNewTime;
pblock->vtx[0].vout[0].SetEmpty();
pblock->vtx.push_back(CTransaction(txCoinStake));
}

// Largest block you're willing to create:
Expand Down Expand Up @@ -491,7 +480,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet,
uint256 nCheckpoint;
uint256 hashBlockLastAccumulated = chainActive[nHeight - (nHeight % 10) - 10]->GetBlockHash();
if (nHeight >= pCheckpointCache.first || pCheckpointCache.second.first != hashBlockLastAccumulated) {
//For the period before v2 activation, zPIV will be disabled and previous block's checkpoint is all that will be needed
//For the period before v2 activation, zdogec will be disabled and previous block's checkpoint is all that will be needed
pCheckpointCache.second.second = pindexPrev->nAccumulatorCheckpoint;
if (pindexPrev->nHeight + 1 >= Params().Zerocoin_Block_V2_Start()) {
AccumulatorMap mapAccumulators(Params().Zerocoin_Params(false));
Expand Down Expand Up @@ -654,18 +643,26 @@ void BitcoinMiner(CWallet* pwallet, bool fProofOfStake)
LogPrintf("DogeCashMiner started\n");
SetThreadPriority(THREAD_PRIORITY_LOWEST);
util::ThreadRename("dogecash-miner");
const int64_t nSpacingMillis = Params().TargetSpacing() * 1000;
const int last_pow_block = Params().LAST_POW_BLOCK();

// Each thread has its own key and counter
CReserveKey reservekey(pwallet);
unsigned int nExtraNonce = 0;
bool fLastLoopOrphan = false;
bool fColdStake = GetBoolArg("-coldstaking", true);
CAmount stakingBalance = 0;

while (fGenerateBitcoins || fProofOfStake) {
CBlockIndex* pindexPrev = GetChainTip();
if (!pindexPrev) {
MilliSleep(Params().TargetSpacing() * 1000); // sleep a block
continue;
}
if (fProofOfStake) {
if (pindexPrev->nHeight < Params().LAST_POW_BLOCK()) {
// The last PoW block hasn't even been mined yet.
MilliSleep(Params().TargetSpacing() * 1000); // sleep a block
continue;
}

//control the amount of times the client will check for mintable coins
if ((GetTime() - nMintableLastCheck > 5 * 60)) // 5 minute check time
{
Expand All @@ -676,13 +673,11 @@ void BitcoinMiner(CWallet* pwallet, bool fProofOfStake)

while (vNodes.empty() || pwallet->IsLocked() || !fMintableCoins ||
(stakingBalance > 0 && nReserveBalance >= stakingBalance) || masternodeSync.NotCompleted()) {
nLastCoinStakeSearchInterval = 0;
MilliSleep(5000);
continue;
}

while (vNodes.empty() || pwallet->IsLocked() || !fMintableCoins || (pwallet->GetBalance() > 0 && nReserveBalance >= pwallet->GetBalance()) || !masternodeSync.IsSynced()) {
nLastCoinStakeSearchInterval = 0;
// Do a separate 1 minute check here to ensure fMintableCoins is updated
if (!fMintableCoins && (GetTime() - nMintableLastCheck > 1 * 60)) // 1 minute check time
{
Expand All @@ -695,28 +690,32 @@ void BitcoinMiner(CWallet* pwallet, bool fProofOfStake)
continue;
}

const bool fTimeV2 = Params().IsTimeProtocolV2(chainActive.Height()+1);
const bool fTimeV2 = Params().IsTimeProtocolV2(pindexPrev->nHeight+1);
//search our map of hashed blocks, see if bestblock has been hashed yet
const int chainHeight = chainActive.Height();
if (mapHashedBlocks.count(chainHeight) && !fLastLoopOrphan)
if (pwallet->pStakerStatus->GetLastHash() == pindexPrev->GetBlockHash())
{
int64_t tipHashTime = mapHashedBlocks[chainHeight];
if ( (!fTimeV2 && GetTime() < tipHashTime + 22) ||
(fTimeV2 && GetCurrentTimeSlot() <= tipHashTime) )
int64_t lastHashTime = pwallet->pStakerStatus->GetLastTime();
if ( (!fTimeV2 && GetTime() < lastHashTime + 22) ||
(fTimeV2 && GetCurrentTimeSlot() <= lastHashTime) )
{
MilliSleep(2000);
continue;
}
}
}
} else { // PoW
if ((pindexPrev->nHeight - 6) > Params().LAST_POW_BLOCK())
{
// Run for a little while longer, just in case there is a rewind on the chain.
LogPrintf("%s: Exiting Proof of Work Mining Thread at height: %d\n",
__func__, chainActive.Tip()->nHeight);
return;
}
}

//
// Create new block
//
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
CBlockIndex* pindexPrev = chainActive.Tip();
if (!pindexPrev)
continue;

unique_ptr<CBlockTemplate> pblocktemplate(
fProofOfStake ? CreateNewBlock(CScript(), pwallet, fProofOfStake) : CreateNewBlockWithKey(reservekey, pwallet)
Expand Down Expand Up @@ -750,10 +749,10 @@ void BitcoinMiner(CWallet* pwallet, bool fProofOfStake)
continue;
}

LogPrintf("CPUMiner : proof-of-stake block was signed %s \n", pblock->GetHash().ToString().c_str());
LogPrintf("%s : proof-of-stake block was signed %s \n", __func__, pblock->GetHash().ToString().c_str());
SetThreadPriority(THREAD_PRIORITY_NORMAL);
if (!ProcessBlockFound(pblock, *pwallet, reservekey)) {
fLastLoopOrphan = true;
LogPrintf("%s: New block orphaned\n", __func__);
continue;
}
SetThreadPriority(THREAD_PRIORITY_LOWEST);
Expand Down
2 changes: 2 additions & 0 deletions src/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class CWallet;

struct CBlockTemplate;

/** Get reliable pointer to current chain tip */
CBlockIndex* GetChainTip();
/** Generate a new block, without valid proof-of-work */
CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, bool fProofOfStake);
CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, CWallet* pwallet, bool fProofOfStake);
Expand Down
8 changes: 4 additions & 4 deletions src/qt/dogecash/send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,17 @@ void SendWidget::setFocusOnLastEntry()
void SendWidget::showHideCheckBoxDelegations()
{
// Show checkbox only when there is any available owned delegation,
// coincontrol is not selected, and we are trying to spend PIV (not zPIV)
const bool isZpiv = ui->pushRight->isChecked();
// coincontrol is not selected, and we are trying to spend DOGEC (not zdogec)
const bool iszdogec = ui->pushRight->isChecked();
const bool isCControl = CoinControlDialog::coinControl->HasSelected();
const bool hasDel = cachedDelegatedBalance > 0;

const bool showCheckBox = !isZpiv && !isCControl && hasDel;
const bool showCheckBox = !iszdogec && !isCControl && hasDel;
ui->checkBoxDelegations->setVisible(showCheckBox);
if (showCheckBox)
ui->checkBoxDelegations->setToolTip(
tr("Possibly spend coins delegated for cold-staking (currently available: %1").arg(
GUIUtil::formatBalance(cachedDelegatedBalance, nDisplayUnit, isZpiv))
GUIUtil::formatBalance(cachedDelegatedBalance, nDisplayUnit, iszdogec))
);
}

Expand Down
Loading

0 comments on commit ccae35c

Please sign in to comment.