Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch 2 of 1.17 patches #13

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static const CAmount CENT = 1000000;
* critical; in unusual circumstances like a(nother) overflow bug that allowed
* for the creation of coins out of thin air modification could lead to a fork.
* */
static const CAmount MAX_MONEY = 1000000000 * COIN; // Dogecoin: maximum of 100B coins (given some randomness), max transaction 10,000,000,000
static const CAmount MAX_MONEY = 10000000000 * COIN; // Dogecoin: maximum of 100B coins (given some randomness), max transaction 10,000,000,000
inline bool MoneyRange(const CAmount& nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }

#endif // BITCOIN_AMOUNT_H
3 changes: 2 additions & 1 deletion src/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ CBlockHeader CBlockIndex::GetBlockHeader(const Consensus::Params& consensusParam
{
CBlockHeader block;

block.nVersion = nVersion;

/* The CBlockIndex object's block header is missing the auxpow.
So if this is an auxpow block, read it from disk instead. We only
have to read the actual *header*, not the full block. */
Expand All @@ -23,7 +25,6 @@ CBlockHeader CBlockIndex::GetBlockHeader(const Consensus::Params& consensusParam
return block;
}

block.nVersion = nVersion;
if (pprev)
block.hashPrevBlock = pprev->GetBlockHash();
block.hashMerkleRoot = hashMerkleRoot;
Expand Down
10 changes: 9 additions & 1 deletion src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,20 @@ class CBlockIndex
CBlockIndex* GetAncestor(int height);
const CBlockIndex* GetAncestor(int height) const;

/**
* Check if the auxpow flag is set in the version.
* @return True if this block version is marked as auxpow.
*/
inline bool IsAuxpow() const
{
return nVersion & CPureBlockHeader::VERSION_AUXPOW;
}

/* Analyse the block version. */
inline int GetBaseVersion() const
{
return CPureBlockHeader::GetBaseVersion(nVersion);
}

};

arith_uint256 GetBlockProof(const CBlockIndex& block);
Expand Down
34 changes: 26 additions & 8 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class CMainParams : public CChainParams {
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x0000000000000000002e63058c023a9a1de233554f28c7b21380b6c9003f36a8"); //534292

consensus.nDigiShieldStartHeight = 145000;
consensus.nDigishieldMinDifficultyHeight = 0;
consensus.nDigiShieldTargetTimespan = 60;

consensus.nAuxpowChainId = 0x0062; // 98 - Josh Wise!
consensus.nAuxpowStartHeight = 371337;
consensus.fStrictChainId = true;
Expand Down Expand Up @@ -170,13 +174,14 @@ class CMainParams : public CChainParams {
{1750000, uint256S("5c8e7327984f0d6f59447d89d143e5f6eafc524c82ad95d176c5cec082ae2001")},
{2000000, uint256S("9914f0e82e39bbf21950792e8816620d71b9965bdbbc14e72a95e3ab9618fea8")},
{2031142, uint256S("893297d89afb7599a3c571ca31a3b80e8353f4cf39872400ad0f57d26c4c5d42")},
{2691755, uint256S("658a69f81e264291b5d58cb4c51a5aa1778d3d3d52359e53c48a0ea0820aa5de")},
}
};

chainTxData = ChainTxData{
// Data from rpc: getchaintxstats 4096 0000000000000000002e63058c023a9a1de233554f28c7b21380b6c9003f36a8
/* nTime */ 1514549787,
/* nTxCount */ 32796624,
/* nTime */ 1555823202,
/* nTxCount */ 46882258,
/* dTxRate */ 0.04
};

Expand All @@ -197,7 +202,7 @@ class CTestNetParams : public CChainParams {
// BIP34 is never enforced in Dogecoin v2 blocks, so we enforce from v3
consensus.BIP34Height = 708658;
consensus.BIP34Hash = uint256S("0x21b8b97dcdb94caa67c7f8f6dbf22e61e0cfe0e46e1fff3528b22864659e9b38");
consensus.BIP65Height = 5000000; // Dogecoin: Use a stupidly high value as a placeholder until 1.14 locks this in
consensus.BIP65Height = 1854705; // 955bd496d23790aba1ecfacb722b089a6ae7ddabaedf7d8fb0878f48308a71f9 - first v4 block after the last v3 block
consensus.BIP66Height = 708658; // 21b8b97dcdb94caa67c7f8f6dbf22e61e0cfe0e46e1fff3528b22864659e9b38 - this is the last block that could be v2, 1900 blocks past the last v2 block
consensus.powLimit = uint256S("0x00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); // ~uint256(0) >> 20;
consensus.nPowTargetTimespan = 4 * 60 * 60; // pre-digishield: 4 hours
Expand Down Expand Up @@ -227,9 +232,13 @@ class CTestNetParams : public CChainParams {
// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x0000000000000037a8cd3e06cd5edbfe9dd1dbcc5dacab279376ef7cfc2b4c75"); //1354312

consensus.nDigiShieldStartHeight = 145000;
consensus.nDigishieldMinDifficultyHeight = 157500; // Testnet enables target reset at block 157500
consensus.nDigiShieldTargetTimespan = 60;

consensus.nAuxpowStartHeight = 158100;
consensus.fStrictChainId = false;
consensus.nLegacyBlocksBefore = -1;
consensus.nLegacyBlocksBefore = 158100;

pchMessageStart[0] = 0xfc;
pchMessageStart[1] = 0xc1;
Expand Down Expand Up @@ -270,13 +279,17 @@ class CTestNetParams : public CChainParams {
{591117, uint256S("5f6b93b2c28cedf32467d900369b8be6700f0649388a7dbfd3ebd4a01b1ffad8")},
{658924, uint256S("ed6c8324d9a77195ee080f225a0fca6346495e08ded99bcda47a8eea5a8a620b")},
{703635, uint256S("839fa54617adcd582d53030a37455c14a87a806f6615aa8213f13e196230ff7f")},
{1000000, uint256S("1fe4d44ea4d1edb031f52f0d7c635db8190dc871a190654c41d2450086b8ef0e")},
{1202214, uint256S("a2179767a87ee4e95944703976fee63578ec04fa3ac2fc1c9c2c83587d096977")},
{1854705, uint256S("955bd496d23790aba1ecfacb722b089a6ae7ddabaedf7d8fb0878f48308a71f9")},
{1985111, uint256S("c0ef7d7277740c52263e0a379b6818c6fa90981cfeea893ec6815ca6b6a0f294")},
}
};

chainTxData = ChainTxData{
// Data from rpc: getchaintxstats 4096 0000000000000037a8cd3e06cd5edbfe9dd1dbcc5dacab279376ef7cfc2b4c75
/* nTime */ 1440601451,
/* nTxCount */ 1119061,
// Data from rpc: getchaintxstats 4096 c0ef7d7277740c52263e0a379b6818c6fa90981cfeea893ec6815ca6b6a0f294
/* nTime */ 1563054279,
/* nTxCount */ 2990413,
/* dTxRate */ 0.01
};

Expand Down Expand Up @@ -313,16 +326,21 @@ class CRegTestParams : public CChainParams {
consensus.vDeployments[Consensus::DEPLOYMENT_CSV].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].bit = 1;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nStartTime = Consensus::BIP9Deployment::ALWAYS_ACTIVE;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = Consensus::BIP9Deployment::NO_TIMEOUT;
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 0; // Disabled

// The best chain should have at least this much work.
consensus.nMinimumChainWork = uint256S("0x00");

// By default assume that the signatures in ancestors of this block are valid.
consensus.defaultAssumeValid = uint256S("0x00");

consensus.nDigiShieldStartHeight = 145000;
consensus.nDigishieldMinDifficultyHeight = 0;
consensus.nDigiShieldTargetTimespan = 60;

consensus.fStrictChainId = true;
consensus.nLegacyBlocksBefore = 0;

pchMessageStart[0] = 0xfa;
pchMessageStart[1] = 0xbf;
pchMessageStart[2] = 0xb5;
Expand Down
5 changes: 5 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ struct Params {
uint256 nMinimumChainWork;
uint256 defaultAssumeValid;

/** DigiShield parameters */
int nDigiShieldStartHeight;
int nDigishieldMinDifficultyHeight;
int64_t nDigiShieldTargetTimespan;

/** Auxpow parameters */
int32_t nAuxpowChainId;
int nAuxpowStartHeight;
Expand Down
2 changes: 2 additions & 0 deletions src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <amount.h>

#include <string>
#include <arith_uint256.h>
#include <vector>

class CBlock;
Expand All @@ -30,6 +31,7 @@ int ParseSighashString(const UniValue& sighash);

// core_write.cpp
UniValue ValueFromAmount(const CAmount& amount);
UniValue ValueFromAmount(const arith_uint256& amount);
std::string FormatScript(const CScript& script);
std::string EncodeHexTx(const CTransaction& tx, const int serializeFlags = 0);
std::string SighashToStr(unsigned char sighash_type);
Expand Down
11 changes: 11 additions & 0 deletions src/core_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <consensus/consensus.h>
#include <consensus/validation.h>
#include <arith_uint256.h>
#include <key_io.h>
#include <script/script.h>
#include <script/standard.h>
Expand All @@ -26,6 +27,16 @@ UniValue ValueFromAmount(const CAmount& amount)
strprintf("%s%d.%08d", sign ? "-" : "", quotient, remainder));
}

UniValue ValueFromAmount(const arith_uint256& amount)
{
bool sign = amount < 0;
arith_uint256 n_abs = (sign ? -amount : amount);
arith_uint256 quotient = n_abs / COIN;
arith_uint256 remainder = n_abs - (quotient * COIN);
return UniValue(UniValue::VNUM,
strprintf("%s%d.%08d", sign ? "-" : "", (int64_t)quotient.getdouble(), (int64_t)remainder.getdouble()));
}

std::string FormatScript(const CScript& script)
{
std::string ret;
Expand Down
46 changes: 35 additions & 11 deletions src/dogecoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <dogecoin.h>
#include <pow.h>
#include <util.h>
#include <validation.h>

int static generateMTRandom(unsigned int s, int range)
{
Expand All @@ -27,8 +28,7 @@ bool AllowDigishieldMinDifficultyForBlock(const CBlockIndex* pindexLast, const C
return false;

// check if the chain allows minimum difficulty blocks on recalc blocks
if (pindexLast->nHeight < 157500)
// if (!params.fPowAllowDigishieldMinDifficultyBlocks)
if (pindexLast->nHeight < params.nDigishieldMinDifficultyHeight)
return false;

// Allow for a minimum block time if the elapsed time > 2*nTargetSpacing
Expand All @@ -38,9 +38,8 @@ bool AllowDigishieldMinDifficultyForBlock(const CBlockIndex* pindexLast, const C
unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params)
{
int nHeight = pindexLast->nHeight + 1;
bool fNewDifficultyProtocol = (nHeight >= 145000);
// bool fNewDifficultyProtocol = (nHeight >= params.GetDigiShieldForkBlock());
const int64_t retargetTimespan = fNewDifficultyProtocol ? 60 // params.DigiShieldTargetTimespan()
bool fNewDifficultyProtocol = (nHeight >= params.nDigiShieldStartHeight);
const int64_t retargetTimespan = fNewDifficultyProtocol ? params.nDigiShieldTargetTimespan
:
params.nPowTargetTimespan;

Expand Down Expand Up @@ -85,12 +84,6 @@ unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, in
if (bnNew > bnPowLimit)
bnNew = bnPowLimit;

/// debug print
LogPrintf("GetNextWorkRequired RETARGET\n");
LogPrintf("params.nPowTargetTimespan = %d nActualTimespan = %d\n", params.nPowTargetTimespan, nActualTimespan);
LogPrintf("Before: %08x %s\n", pindexLast->nBits, bnOld.ToString());
LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString());

return bnNew.GetCompact();
}

Expand Down Expand Up @@ -155,3 +148,34 @@ CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusP
return 10000 * COIN;
}
}

unsigned int GetDogecoinTxSize(const unsigned int nTxBytes)
{
// Dogecoin: Round TX bytes up to the next 1,000 bytes
unsigned int nMod = nTxBytes % 1000;
if (nMod > 0) {
return nTxBytes + 1000 - nMod;
} else {
return nTxBytes;
}
}

CAmount GetDogecoinMinRelayFee(const CTransaction& tx, unsigned int nSize)
{
CAmount nMinFee = ::minRelayTxFee.GetFee(nSize);
nMinFee += GetDogecoinDustFee(tx.vout, ::minRelayTxFee);
if (!MoneyRange(nMinFee))
nMinFee = MAX_MONEY;
return nMinFee;
}

CAmount GetDogecoinDustFee(const std::vector<CTxOut> &vout, const CFeeRate &baseFeeRate) {
CAmount nFee = 0;

// To limit dust spam, add base fee for each output less than a COIN
for (const CTxOut& txout: vout)
if (txout.nValue < COIN)
nFee += baseFeeRate.GetFeePerK();

return nFee;
}
5 changes: 5 additions & 0 deletions src/dogecoin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "amount.h"
#include "chain.h"
#include "chainparams.h"
#include "policy/feerate.h"

bool AllowDigishieldMinDifficultyForBlock(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params);
CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusParams, uint256 prevHash);
Expand All @@ -17,3 +18,7 @@ unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, in
* @return True iff the PoW is correct.
*/
bool CheckAuxPowProofOfWork(const CBlockHeader& block, const Consensus::Params& params);

unsigned int GetDogecoinTxSize(const unsigned int nTxBytes);
CAmount GetDogecoinMinRelayFee(const CTransaction& tx, unsigned int nSize);
CAmount GetDogecoinDustFee(const std::vector<CTxOut> &vout, const CFeeRate &baseFeeRate);
1 change: 1 addition & 0 deletions src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class NodeImpl : public Node
bool softSetBoolArg(const std::string& arg, bool value) override { return gArgs.SoftSetBoolArg(arg, value); }
void selectParams(const std::string& network) override { SelectParams(network); }
std::string getNetwork() override { return Params().NetworkIDString(); }
std::string getGenesis() override { return Params().GenesisBlock().GetHash().ToString(); }
void initLogging() override { InitLogging(); }
void initParameterInteraction() override { InitParameterInteraction(); }
std::string getWarnings(const std::string& type) override { return GetWarnings(type); }
Expand Down
3 changes: 3 additions & 0 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Node
//! Get network name.
virtual std::string getNetwork() = 0;

//! Get genesis block hash.
virtual std::string getGenesis() = 0;

//! Init logging.
virtual void initLogging() = 0;

Expand Down
6 changes: 4 additions & 2 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,14 +412,16 @@ class WalletImpl : public Wallet
return result;
}
CAmount getRequiredFee(unsigned int tx_bytes) override { return GetRequiredFee(m_wallet, tx_bytes); }
CAmount getMinimumFee(unsigned int tx_bytes,
CAmount getRequiredFee(const CTransaction& tx, unsigned int tx_bytes) override { return GetRequiredFee(m_wallet, tx, tx_bytes); }
CAmount getMinimumFee(const CTransaction& tx,
unsigned int tx_bytes,
const CCoinControl& coin_control,
int* returned_target,
FeeReason* reason) override
{
FeeCalculation fee_calc;
CAmount result;
result = GetMinimumFee(m_wallet, tx_bytes, coin_control, ::mempool, ::feeEstimator, &fee_calc);
result = GetMinimumFee(m_wallet, tx, tx_bytes, coin_control, ::mempool, ::feeEstimator, &fee_calc);
if (returned_target) *returned_target = fee_calc.returnedTarget;
if (reason) *reason = fee_calc.reason;
return result;
Expand Down
8 changes: 6 additions & 2 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,15 @@ class Wallet
//! Return wallet transaction output information.
virtual std::vector<WalletTxOut> getCoins(const std::vector<COutPoint>& outputs) = 0;

//! Get required fee.
//! Get required fee without taking into account dust charges
virtual CAmount getRequiredFee(unsigned int tx_bytes) = 0;

//! Get required fee.
virtual CAmount getRequiredFee(const CTransaction& tx, unsigned int tx_bytes) = 0;

//! Get minimum fee.
virtual CAmount getMinimumFee(unsigned int tx_bytes,
virtual CAmount getMinimumFee(const CTransaction& tx,
unsigned int tx_bytes,
const CCoinControl& coin_control,
int* returned_target,
FeeReason* reason) = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
const int32_t nChainId = chainparams.GetConsensus ().nAuxpowChainId;
// FIXME: Active version bits after the always-auxpow fork!
//const int32_t nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
const int32_t nVersion = 4;
const int32_t nVersion = VERSIONBITS_LAST_OLD_BLOCK_VERSION;
pblock->SetBaseVersion(nVersion, nChainId);
// -regtest only: allow overriding block.nVersion with
// -blockversion=N to test forking scenarios
Expand Down
8 changes: 4 additions & 4 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1783,12 +1783,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
AddTimeData(pfrom->addr, nTimeOffset);

// If the peer is old enough to have the old alert system, send it the final alert.
// XXX: Decide how to handle alert migration in Dogecoin and either make this a Dogecoin
// alert or re-introduce the system
if (pfrom->nVersion <= 70012) {
/* if (pfrom->nVersion <= 70012) {
// TODO: Replace this with a valid Dogecoin alert
// Disabled meantime as the remote client considers the nonsense alert a hack and drops the connection
CDataStream finalAlert(ParseHex("60010000000000000000000000ffffff7f00000000ffffff7ffeffff7f01ffffff7f00000000ffffff7f00ffffff7f002f555247454e543a20416c657274206b657920636f6d70726f6d697365642c2075706772616465207265717569726564004630440220653febd6410f470f6bae11cad19c48413becb1ac2c17f908fd0fd53bdc3abd5202206d0e9c96fe88d4a0f01ed9dedae2b6f9e00da94cad0fecaae66ecf689bf71b50"), SER_NETWORK, PROTOCOL_VERSION);
connman->PushMessage(pfrom, CNetMsgMaker(nSendVersion).Make("alert", finalAlert));
}
} */

// Feeler connections exist only to verify if address is online.
if (pfrom->fFeeler) {
Expand Down
Loading