diff options
| author | Ross Nicoll <[email protected]> | 2017-12-28 15:04:08 +0000 |
|---|---|---|
| committer | Ross Nicoll <[email protected]> | 2018-09-19 19:24:06 +0100 |
| commit | 1be681a1b97b686f838af90682a57f2030d26015 (patch) | |
| tree | b2795e4a1d35004dbfd84d49b07bc54413a2a9e1 /src/rpc | |
| parent | Change BIP65/66 enforcement to match Dogecoin (#1403) (diff) | |
| download | discoin-1be681a1b97b686f838af90682a57f2030d26015.tar.xz discoin-1be681a1b97b686f838af90682a57f2030d26015.zip | |
Modify chain consensus parameters to be height aware (#1396)
* Modify chain consensus parameters to be height aware
* Correct implementation of simplified rewards in parameters
* Correct max money
* Use base block version in IsSuperMajority() instead of full version
* Correct mining of blocks in AuxPoW tests
* Add in missing pre-AuxPoW consensus checks
Diffstat (limited to 'src/rpc')
| -rw-r--r-- | src/rpc/blockchain.cpp | 6 | ||||
| -rw-r--r-- | src/rpc/mining.cpp | 12 | ||||
| -rw-r--r-- | src/rpc/rawtransaction.cpp | 7 |
3 files changed, 14 insertions, 11 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index d06c00cbc..6fb45a515 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -720,7 +720,7 @@ UniValue getblockheader(const JSONRPCRequest& request) if (!fVerbose) { CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION); - ssBlock << pblockindex->GetBlockHeader(Params().GetConsensus()); + ssBlock << pblockindex->GetBlockHeader(Params().GetConsensus(pblockindex->nHeight)); std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()); return strHex; } @@ -787,7 +787,7 @@ UniValue getblock(const JSONRPCRequest& request) if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) throw JSONRPCError(RPC_MISC_ERROR, "Block not available (pruned data)"); - if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) + if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus(pblockindex->nHeight))) // Block not found on disk. This could be because we have the block // header in our index but don't have the block (for example if a // non-whitelisted node sends us an unrequested long chain of valid @@ -1185,7 +1185,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); obj.push_back(Pair("pruned", fPruneMode)); - const Consensus::Params& consensusParams = Params().GetConsensus(); + const Consensus::Params& consensusParams = Params().GetConsensus(0); CBlockIndex* tip = chainActive.Tip(); UniValue softforks(UniValue::VARR); UniValue bip9_softforks(UniValue::VOBJ); diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index b355ccdc9..0e2dbe2cb 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -48,7 +48,8 @@ UniValue GetNetworkHashPS(int lookup, int height) { // If lookup is -1, then use blocks since last difficulty change. if (lookup <= 0) - lookup = pb->nHeight % Params().GetConsensus().DifficultyAdjustmentInterval() + 1; + lookup = pb->nHeight % Params().GetConsensus(pb->nHeight).DifficultyAdjustmentInterval() + 1; + // // If lookup is larger than chain, then set it to chain length. if (lookup > pb->nHeight) @@ -125,7 +126,7 @@ UniValue generateBlocks(boost::shared_ptr<CReserveScript> coinbaseScript, int nG } CAuxPow::initAuxPow(*pblock); CPureBlockHeader& miningHeader = pblock->auxpow->parentBlock; - while (nMaxTries > 0 && miningHeader.nNonce < nInnerLoopCount && !CheckProofOfWork(miningHeader.GetHash(), pblock->nBits, Params().GetConsensus())) { + while (nMaxTries > 0 && miningHeader.nNonce < nInnerLoopCount && !CheckProofOfWork(miningHeader.GetHash(), pblock->nBits, Params().GetConsensus(nHeight))) { ++miningHeader.nNonce; --nMaxTries; } @@ -561,7 +562,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) pindexPrev = pindexPrevNew; } CBlock* pblock = &pblocktemplate->block; // pointer for convenience - const Consensus::Params& consensusParams = Params().GetConsensus(); + const Consensus::Params& consensusParams = Params().GetConsensus(pindexPrev->nHeight + 1); // Update nTime UpdateTime(pblock, consensusParams, pindexPrev); @@ -778,7 +779,8 @@ UniValue submitblock(const JSONRPCRequest& request) LOCK(cs_main); BlockMap::iterator mi = mapBlockIndex.find(block.hashPrevBlock); if (mi != mapBlockIndex.end()) { - UpdateUncommittedBlockStructures(block, mi->second, Params().GetConsensus()); + int nHeight = chainActive.Height() + 1; + UpdateUncommittedBlockStructures(block, mi->second, Params().GetConsensus(nHeight)); } } @@ -990,7 +992,7 @@ UniValue getauxblock(const JSONRPCRequest& request) past the point of merge-mining start. Check nevertheless. */ { LOCK(cs_main); - if (chainActive.Height() + 1 < Params().GetConsensus().nAuxpowStartHeight) + if (Params().GetConsensus(chainActive.Height() + 1).fAllowLegacyBlocks) throw std::runtime_error("getauxblock method is not yet available"); } diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 0fabb9f5a..994057e20 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -219,7 +219,8 @@ UniValue getrawtransaction(const JSONRPCRequest& request) CTransactionRef tx; uint256 hashBlock; - if (!GetTransaction(hash, tx, Params().GetConsensus(), hashBlock, true)) + // Dogecoin: Is this the best value for consensus height? + if (!GetTransaction(hash, tx, Params().GetConsensus(0), hashBlock, true)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, std::string(fTxIndex ? "No such mempool or blockchain transaction" : "No such mempool transaction. Use -txindex to enable blockchain transaction queries") + ". Use gettransaction for wallet transactions."); @@ -290,7 +291,7 @@ UniValue gettxoutproof(const JSONRPCRequest& request) if (pblockindex == NULL) { CTransactionRef tx; - if (!GetTransaction(oneTxid, tx, Params().GetConsensus(), hashBlock, false) || hashBlock.IsNull()) + if (!GetTransaction(oneTxid, tx, Params().GetConsensus(0), hashBlock, false) || hashBlock.IsNull()) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not yet in block"); if (!mapBlockIndex.count(hashBlock)) throw JSONRPCError(RPC_INTERNAL_ERROR, "Transaction index corrupt"); @@ -298,7 +299,7 @@ UniValue gettxoutproof(const JSONRPCRequest& request) } CBlock block; - if(!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) + if(!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus(pblockindex->nHeight))) throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); unsigned int ntxFound = 0; |