aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoss Nicoll <[email protected]>2018-02-11 21:00:50 +0000
committerRoss Nicoll <[email protected]>2018-09-19 22:11:47 +0100
commit9c3a11b2488f3e01e6763bc1217598a4d1c69bde (patch)
treeed6b54c5b71a4543a32968dc5b1d391bfe59dfed /src
parentInsert Dogecoin testnet merkle tree root value (#1469) (diff)
downloaddiscoin-9c3a11b2488f3e01e6763bc1217598a4d1c69bde.tar.xz
discoin-9c3a11b2488f3e01e6763bc1217598a4d1c69bde.zip
Clean up RPC tests (#1465)
* Enable full block tests * Fix invalidblocktest * Move watch only address funding to immediately before it's used, so node 0 doesn't spend the output before it checks it later. * Fix `fundrawtransaction` tests and sanitize fee calculation at the same time * Correct resolution of chain parameters when validating tx inputs, especially from previous coinbase transactions * Set block versions on full block tests so that the generated blocks are AuxPoW compatible
Diffstat (limited to 'src')
-rw-r--r--src/amount.cpp5
-rw-r--r--src/chainparams.cpp1
-rw-r--r--src/consensus/consensus.h2
-rw-r--r--src/dogecoin.cpp11
-rw-r--r--src/dogecoin.h1
-rw-r--r--src/net_processing.cpp2
-rw-r--r--src/test/test_bitcoin.cpp3
-rw-r--r--src/txmempool.cpp5
-rw-r--r--src/validation.cpp18
-rw-r--r--src/validation.h2
-rw-r--r--src/wallet/wallet.cpp2
11 files changed, 23 insertions, 29 deletions
diff --git a/src/amount.cpp b/src/amount.cpp
index a5f6bc3cd..d6a7d8c30 100644
--- a/src/amount.cpp
+++ b/src/amount.cpp
@@ -25,6 +25,11 @@ CAmount CFeeRate::GetFee(size_t nBytes_) const
assert(nBytes_ <= uint64_t(std::numeric_limits<int64_t>::max()));
int64_t nSize = int64_t(nBytes_);
+ // Dogecoin: Round up to the nearest 1000 bytes so we get round tx fees
+ if (nSize % 1000 > 0) {
+ nSize = nSize + 1000 - (nSize % 1000);
+ }
+
CAmount nFee = nSatoshisPerK * nSize / 1000;
if (nFee == 0 && nSize != 0) {
diff --git a/src/chainparams.cpp b/src/chainparams.cpp
index 4043add1c..bdd4a7d46 100644
--- a/src/chainparams.cpp
+++ b/src/chainparams.cpp
@@ -221,6 +221,7 @@ public:
consensus.nHeightEffective = 0;
consensus.nPowTargetTimespan = 4 * 60 * 60; // pre-digishield: 4 hours
consensus.fDigishieldDifficultyCalculation = false;
+ consensus.nCoinbaseMaturity = 30;
consensus.fPowAllowMinDifficultyBlocks = true;
consensus.fPowAllowDigishieldMinDifficultyBlocks = false;
consensus.nSubsidyHalvingInterval = 100000;
diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h
index b7053e869..fadb947de 100644
--- a/src/consensus/consensus.h
+++ b/src/consensus/consensus.h
@@ -16,8 +16,6 @@ static const unsigned int MAX_BLOCK_WEIGHT = 4000000;
static const unsigned int MAX_BLOCK_BASE_SIZE = 1000000;
/** The maximum allowed number of signature check operations in a block (network rule) */
static const int64_t MAX_BLOCK_SIGOPS_COST = 80000;
-/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
-static const int COINBASE_MATURITY = 60*4; // 4 hours of blocks
/** Flags for nSequence and nLockTime locks */
enum {
diff --git a/src/dogecoin.cpp b/src/dogecoin.cpp
index 3e57791fd..3f06e8a49 100644
--- a/src/dogecoin.cpp
+++ b/src/dogecoin.cpp
@@ -146,17 +146,6 @@ CAmount GetDogecoinBlockSubsidy(int nHeight, const Consensus::Params& consensusP
}
}
-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 nBytes, bool fAllowFree)
{
{
diff --git a/src/dogecoin.h b/src/dogecoin.h
index 45dc7fc79..3bc63635d 100644
--- a/src/dogecoin.h
+++ b/src/dogecoin.h
@@ -18,6 +18,5 @@ unsigned int CalculateDogecoinNextWorkRequired(const CBlockIndex* pindexLast, in
*/
bool CheckAuxPowProofOfWork(const CBlockHeader& block, const Consensus::Params& params);
-unsigned int GetDogecoinTxSize(const unsigned int nTxBytes);
CAmount GetDogecoinMinRelayFee(const CTransaction& tx, unsigned int nBytes, bool fAllowFree);
CAmount GetDogecoinDustFee(const std::vector<CTxOut> &vout, CFeeRate &baseFeeRate);
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 856072f32..706b4c68f 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1644,7 +1644,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
// If pruning, don't inv blocks unless we have on disk and are likely to still have
// for some reasonable time window (1 hour) that block relay might require.
const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - 3600 / chainparams.GetConsensus(pindex->nHeight).nPowTargetSpacing;
- if (fPruneMode && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= chainActive.Tip()->nHeight - nPrunedBlocksLikelyToHave))
+ if (fPruneMode && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= chainActive.Height() - nPrunedBlocksLikelyToHave))
{
LogPrint("net", " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
break;
diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp
index 9a3eecf99..5ed3796be 100644
--- a/src/test/test_bitcoin.cpp
+++ b/src/test/test_bitcoin.cpp
@@ -36,6 +36,9 @@ FastRandomContext insecure_rand_ctx(true);
extern bool fPrintToConsole;
extern void noui_connect();
+/** Coinbase transaction outputs can only be spent after this number of new blocks (network rule) */
+static const int COINBASE_MATURITY = 60*4; // 4 hours of blocks
+
BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
{
ECC_Start();
diff --git a/src/txmempool.cpp b/src/txmempool.cpp
index de0a1489e..c6b679aec 100644
--- a/src/txmempool.cpp
+++ b/src/txmempool.cpp
@@ -658,6 +658,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
CCoinsViewCache mempoolDuplicate(const_cast<CCoinsViewCache*>(pcoins));
const int64_t nSpendHeight = GetSpendHeight(mempoolDuplicate);
+ const CChainParams& params = Params();
LOCK(cs);
std::list<const CTxMemPoolEntry*> waitingOnDependants;
@@ -739,7 +740,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
else {
CValidationState state;
bool fCheckResult = tx.IsCoinBase() ||
- Consensus::CheckTxInputs(tx, state, mempoolDuplicate, nSpendHeight);
+ Consensus::CheckTxInputs(params, tx, state, mempoolDuplicate, nSpendHeight);
assert(fCheckResult);
UpdateCoins(tx, mempoolDuplicate, 1000000);
}
@@ -755,7 +756,7 @@ void CTxMemPool::check(const CCoinsViewCache *pcoins) const
assert(stepsSinceLastRemove < waitingOnDependants.size());
} else {
bool fCheckResult = entry->GetTx().IsCoinBase() ||
- Consensus::CheckTxInputs(entry->GetTx(), state, mempoolDuplicate, nSpendHeight);
+ Consensus::CheckTxInputs(params, entry->GetTx(), state, mempoolDuplicate, nSpendHeight);
assert(fCheckResult);
UpdateCoins(entry->GetTx(), mempoolDuplicate, 1000000);
stepsSinceLastRemove = 0;
diff --git a/src/validation.cpp b/src/validation.cpp
index 1f29a9b6b..c5041cea9 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1396,7 +1396,7 @@ int GetSpendHeight(const CCoinsViewCache& inputs)
}
namespace Consensus {
-bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight)
+bool CheckTxInputs(const CChainParams& params, const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight)
{
// This doesn't trigger the DoS code on purpose; if it did, it would make it easier
// for an attacker to attempt to split the network.
@@ -1414,7 +1414,7 @@ bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoins
// If prev is coinbase, check that it's matured
if (coins->IsCoinBase()) {
// Dogecoin: Switch maturity at depth 145,000
- int nCoinbaseMaturity = Params().GetConsensus(coins->nHeight)->nCoinbaseMaturity;
+ int nCoinbaseMaturity = params.GetConsensus(coins->nHeight).nCoinbaseMaturity;
if (nSpendHeight - coins->nHeight < nCoinbaseMaturity)
return state.Invalid(false,
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase",
@@ -1447,7 +1447,7 @@ bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsVi
{
if (!tx.IsCoinBase())
{
- if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs)))
+ if (!Consensus::CheckTxInputs(Params(), tx, state, inputs, GetSpendHeight(inputs)))
return false;
if (pvChecks)
@@ -2459,7 +2459,7 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
}
if (fBlocksDisconnected) {
- mempool.removeForReorg(pcoinsTip, chainActive.Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
+ mempool.removeForReorg(pcoinsTip, chainActive.Height() + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
LimitMempoolSize(mempool, GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000, GetArg("-mempoolexpiry", DEFAULT_MEMPOOL_EXPIRY) * 60 * 60);
}
mempool.check(pcoinsTip);
@@ -2628,7 +2628,7 @@ bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, C
// ActivateBestChain considers blocks already in chainActive
// unconditionally valid already, so force disconnect away from it.
if (!DisconnectTip(state, chainparams)) {
- mempool.removeForReorg(pcoinsTip, chainActive.Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
+ mempool.removeForReorg(pcoinsTip, chainActive.Height() + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
return false;
}
}
@@ -2646,7 +2646,7 @@ bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, C
}
InvalidChainFound(pindex);
- mempool.removeForReorg(pcoinsTip, chainActive.Tip()->nHeight + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
+ mempool.removeForReorg(pcoinsTip, chainActive.Height() + 1, STANDARD_LOCKTIME_VERIFY_FLAGS);
uiInterface.NotifyBlockTip(IsInitialBlockDownload(), pindex->pprev);
return true;
}
@@ -3426,7 +3426,7 @@ void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeig
return;
// last block to prune is the lesser of (user-specified height, MIN_BLOCKS_TO_KEEP from the tip)
- unsigned int nLastBlockWeCanPrune = std::min((unsigned)nManualPruneHeight, chainActive.Tip()->nHeight - MIN_BLOCKS_TO_KEEP);
+ unsigned int nLastBlockWeCanPrune = std::min((unsigned)nManualPruneHeight, chainActive.Height() - MIN_BLOCKS_TO_KEEP);
int count=0;
for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) {
if (vinfoBlockFile[fileNumber].nSize == 0 || vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
@@ -3452,11 +3452,11 @@ void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight
if (chainActive.Tip() == NULL || nPruneTarget == 0) {
return;
}
- if ((uint64_t)chainActive.Tip()->nHeight <= nPruneAfterHeight) {
+ if ((uint64_t)chainActive.Height() <= nPruneAfterHeight) {
return;
}
- unsigned int nLastBlockWeCanPrune = chainActive.Tip()->nHeight - MIN_BLOCKS_TO_KEEP;
+ unsigned int nLastBlockWeCanPrune = chainActive.Height() - MIN_BLOCKS_TO_KEEP;
uint64_t nCurrentUsage = CalculateCurrentUsage();
// We don't check to prune until after we've allocated new space for files
// So we should leave a buffer under our target to account for another allocation
diff --git a/src/validation.h b/src/validation.h
index 0ec5388df..b77477469 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -386,7 +386,7 @@ namespace Consensus {
* This does not modify the UTXO set. This does not check scripts and sigs.
* Preconditions: tx.IsCoinBase() is false.
*/
-bool CheckTxInputs(const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight);
+bool CheckTxInputs(const CChainParams& params, const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight);
} // namespace Consensus
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index c61272c8b..27bee7f58 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2808,14 +2808,12 @@ bool CWallet::AddAccountingEntry(const CAccountingEntry& acentry, CWalletDB *pwa
CAmount CWallet::GetRequiredFee(const CMutableTransaction& tx, unsigned int nTxBytes)
{
- nTxBytes = GetDogecoinTxSize(nTxBytes);
// Dogecoin: Add an increased fee for each dust output
return std::max(minTxFee.GetFee(nTxBytes) + GetDogecoinDustFee(tx.vout, minTxFee), ::minRelayTxFee.GetFee(nTxBytes));
}
CAmount CWallet::GetRequiredFee(unsigned int nTxBytes)
{
- nTxBytes = GetDogecoinTxSize(nTxBytes);
return std::max(minTxFee.GetFee(nTxBytes), ::minRelayTxFee.GetFee(nTxBytes));
}