Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mining.cpp
Go to the documentation of this file.
45 unsigned int max_target = ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
47 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid conf_target, must be between %u - %u", 1, max_target));
84 // In case there's a situation where minTime == maxTime, we don't want a divide by zero exception.
103 "1. nblocks (numeric, optional, default=120) The number of blocks, or -1 for blocks since last difficulty change.\n"
113 return GetNetworkHashPS(!request.params[0].isNull() ? request.params[0].get_int() : 120, !request.params[1].isNull() ? request.params[1].get_int() : -1);
117 UniValue generateBlocks(std::shared_ptr<CReserveScript> coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript)
132 std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(Params()).CreateNewBlock(coinbaseScript->reserveScript));
140 while (nMaxTries > 0 && pblock->nNonce < nInnerLoopCount && !CheckProofOfWork(pblock->GetHash(), pblock->nBits, Params().GetConsensus())) {
156 //mark script as important because it was used at least for one coinbase output if the script came from the wallet
214 " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
216 " \"errors\": \"...\" (string) DEPRECATED. Same as warnings. Only shown when dashd is started with -deprecatedrpc=getmininginfo\n"
243 // NOTE: Unlike wallet RPC (which use BTC values), mining RPCs follow GBT (BIP 22) in using satoshi amounts
252 "2. fee_delta (numeric, required) The fee value (in duffs) to add (or subtract, if negative).\n"
305 "\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n"
315 " \"mode\":\"template\" (string, optional) This must be set to \"template\", \"proposal\" (see BIP 23), or omitted\n"
317 " \"support\" (string) client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'\n"
329 " \"capabilities\" : [ \"capability\", ... ], (array of strings) specific client side supported features\n"
331 " \"rules\" : [ \"rulename\", ... ], (array of strings) specific block rules that are to be enforced\n"
332 " \"vbavailable\" : { (json object) set of pending, supported versionbit (BIP 9) softfork deployments\n"
333 " \"rulename\" : bitnumber (numeric) identifies the bit number as indicating acceptance and readiness for the named softfork rule\n"
336 " \"vbrequired\" : n, (numeric) bit mask of versionbits the server requires set in submissions\n"
338 " \"transactions\" : [ (array) contents of non-coinbase transactions that should be included in the next block\n"
343 " n (numeric) transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is\n"
346 " \"fee\": n, (numeric) difference in value between transaction inputs and outputs (in duffs); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one\n"
347 " \"sigops\" : n, (numeric) total number of SigOps, as counted for purposes of block limits; if key is not present, sigop count is unknown and clients MUST NOT assume there aren't any\n"
348 " \"required\" : true|false (boolean) if provided and true, this transaction must be in the final block\n"
352 " \"coinbaseaux\" : { (json object) data that should be included in the coinbase's scriptSig content\n"
355 " \"coinbasevalue\" : n, (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in duffs)\n"
358 " \"mintime\" : xxx, (numeric) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT)\n"
360 " \"value\" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'\n"
370 " \"masternode\" : [ (array) required masternode payments that must be included in the next block\n"
377 " \"masternode_payments_started\" : true|false, (boolean) true, if masternode payments started\n"
378 " \"masternode_payments_enforced\" : true|false, (boolean) true, if masternode payments are enforced\n"
379 " \"superblock\" : [ (array) required superblock payees that must be included in the next block\n"
389 " \"coinbase_payload\" : \"xxxxxxxx\" (string) coinbase transaction payload data encoded in hexadecimal\n"
466 throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
474 // Get expected MN/superblock payees. The call to GetBlockTxOuts might fail on regtest/devnet or when
489 // Wait to respond until either the best block changes, OR a minute has passed and there are more transactions
504 // NOTE: Spec does not specify behaviour for non-string longpollid, but this makes testing easier
530 // TODO: Maybe recheck connections/IBD and (if something wrong) send an expires-immediately template to stop miners?
645 // If we do anything other than throw an exception here, be sure version/force isn't sent to old clients
646 throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Support for '%s' rule requires explicit client support", vbinfo.name));
660 // Because BIP 34 changed how the generation transaction is serialized, we can only use version/force back to v2 blocks
661 // This is safe to do [otherwise-]unconditionally only because we are throwing an exception above if a non-force deployment gets activated
662 // Note that this can probably also be removed entirely after the first BIP9 non-force deployment (ie, probably segwit) gets activated
670 result.push_back(Pair("longpollid", chainActive.Tip()->GetBlockHash().GetHex() + i64tostr(nTransactionsUpdatedLast)));
695 result.push_back(Pair("masternode_payments_started", pindexPrev->nHeight + 1 > consensusParams.nMasternodePaymentsStartBlock));
711 result.push_back(Pair("superblocks_started", pindexPrev->nHeight + 1 > consensusParams.nSuperblockStartBlock));
712 result.push_back(Pair("superblocks_enabled", sporkManager.IsSporkActive(SPORK_9_SUPERBLOCKS_ENABLED)));
726 explicit submitblock_StateCatcher(const uint256 &hashIn) : hash(hashIn), found(false), state() {}
822 throw JSONRPCError(RPC_METHOD_DEPRECATED, "estimatefee is deprecated and will be fully removed in v0.17. "
862 " \"errors\": [ str... ] (json array of strings, optional) Errors encountered during processing\n"
913 "2. threshold (numeric, optional) The proportion of transactions in a given feerate range that must have been\n"
914 " confirmed within conf_target in order to consider those feerates as high enough and proceed to check\n"
920 " \"decay\" : x.x, (numeric) exponential decay (per block) for historical moving average of confirmation data\n"
922 " \"pass\" : { (json object, optional) information about the lowest range of feerates to succeed in meeting the threshold\n"
925 " \"withintarget\" : x.x, (numeric) number of txs over history horizon in the feerate range that were confirmed within target\n"
926 " \"totalconfirmed\" : x.x, (numeric) number of txs over history horizon in the feerate range that were confirmed at any point\n"
927 " \"inmempool\" : x.x, (numeric) current number of txs in mempool in the feerate range unconfirmed for at least target blocks\n"
928 " \"leftmempool\" : x.x, (numeric) number of txs over history horizon in the feerate range that left mempool unconfirmed after target\n"
930 " \"fail\" : { ... }, (json object, optional) information about the highest range of feerates to fail to meet the threshold\n"
931 " \"errors\": [ str... ] (json array of strings, optional) Errors encountered during processing\n"
955 for (FeeEstimateHorizon horizon : {FeeEstimateHorizon::SHORT_HALFLIFE, FeeEstimateHorizon::MED_HALFLIFE, FeeEstimateHorizon::LONG_HALFLIFE}) {
969 passbucket.push_back(Pair("totalconfirmed", round(buckets.pass.totalConfirmed * 100.0) / 100.0));
976 failbucket.push_back(Pair("totalconfirmed", round(buckets.fail.totalConfirmed * 100.0) / 100.0));
986 // buckets.fail.start == -1 indicates that all buckets passed, there is no fail bucket to output
Definition: mining.cpp:719
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
Definition: chain.h:195
CTxMemPool mempool
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:80
Definition: versionbits.h:33
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Parse a standard scriptPubKey for the destination address.
Definition: standard.cpp:158
bool FeeModeFromString(const std::string &mode_string, FeeEstimateMode &fee_estimate_mode)
Definition: fees.cpp:50
int64_t UpdateTime(CBlockHeader *pblock, const Consensus::Params &consensusParams, const CBlockIndex *pindexPrev)
Definition: miner.cpp:59
Definition: block.h:72
Definition: versionbits.h:22
bool gbt_force
Whether GBT clients can safely ignore this rule in simplified usage.
Definition: versionbits.h:37
UniValue prioritisetransaction(const JSONRPCRequest &request)
Definition: mining.cpp:244
Definition: protocol.h:44
UniValue GetNetworkHashPS(int lookup, int height)
Return average network hashes per second based on the last 'lookup' blocks, or from the last difficul...
Definition: mining.cpp:57
Definition: versionbits.h:23
Definition: fees.h:75
void RegisterMiningRPCCommands(CRPCTable &t)
Register mining RPC commands.
Definition: mining.cpp:1020
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
Definition: standard.cpp:281
Definition: versionbits.h:25
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: utilstrencodings.h:100
const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS]
Definition: versionbits.cpp:8
Definition: univalue.h:20
double GetDifficulty(const CChain &chain, const CBlockIndex *blockindex)
Definition: blockchain.cpp:64
void BlockChecked(const CBlock &block, const CValidationState &stateIn) override
Notifies listeners of a block validation result.
Definition: mining.cpp:729
std::string StringForFeeEstimateHorizon(FeeEstimateHorizon horizon)
Definition: fees.cpp:17
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:583
Definition: univalue.h:22
uint32_t VersionBitsMask(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Definition: versionbits.cpp:260
int nMasternodePaymentsStartBlock
Definition: params.h:134
void UnregisterValidationInterface(CValidationInterface *pwalletIn)
Unregister a wallet from core.
Definition: validationinterface.cpp:105
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.
Definition: warnings.cpp:41
submitblock_StateCatcher(const uint256 &hashIn)
Definition: mining.cpp:726
bool ProcessNewBlock(const CChainParams &chainparams, const std::shared_ptr< const CBlock > pblock, bool fForceProcessing, bool *fNewBlock)
Process an incoming block.
Definition: validation.cpp:3803
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
Definition: server.cpp:353
Definition: validationinterface.h:64
Definition: univalue.h:22
void RPCTypeCheck(const UniValue ¶ms, const std::list< UniValue::VType > &typesExpected, bool fAllowNull)
Type-check arguments; throws JSONRPCError if wrong type given.
Definition: server.cpp:54
const UniValue & find_value(const UniValue &obj, const std::string &name)
Definition: univalue.cpp:236
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
Definition: chain.h:332
Definition: net.h:145
Definition: univalue.h:22
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
Definition: chain.h:148
UniValue generateBlocks(std::shared_ptr< CReserveScript > coinbaseScript, int nGenerate, uint64_t nMaxTries, bool keepScript)
Generate blocks (mine)
CFeeRate estimateRawFee(int confTarget, double successThreshold, FeeEstimateHorizon horizon, EstimationResult *result=nullptr) const
Return a specific fee estimate calculation with a given success threshold and time horizon...
Definition: fees.cpp:672
Definition: fees.h:117
CFeeRate estimateSmartFee(int confTarget, FeeCalculation *feeCalc, bool conservative) const
Estimate feerate needed to get be included in a block within confTarget blocks.
Definition: fees.cpp:819
unsigned int MaxBlockSigOps(bool fDIP0001Active)
The maximum allowed number of signature check operations in a block (network rule) ...
Definition: consensus.h:17
void RPCTypeCheckArgument(const UniValue &value, UniValue::VType typeExpected)
Type-check one argument; throws JSONRPCError if wrong type given.
Definition: server.cpp:72
static bool IsValidBlockHeight(int nBlockHeight)
Is Valid Superblock Height.
Definition: governance-classes.cpp:437
static UniValue BIP22ValidationResult(const CValidationState &state)
Definition: mining.cpp:273
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network) ...
Definition: validation.cpp:1219
Definition: fees.h:73
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
Definition: standard.cpp:256
std::unique_ptr< CBlockTemplate > CreateNewBlock(const CScript &scriptPubKeyIn)
Construct a new block template with coinbase to scriptPubKeyIn.
Definition: miner.cpp:119
Definition: fees.h:125
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:578
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:185
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
Definition: pow.cpp:233
CScript COINBASE_FLAGS
Constant stuff for coinbase transactions we create:
Definition: validation.cpp:255
bool IsDeprecatedRPCEnabled(const std::string &method)
Definition: server.cpp:447
Definition: spork.h:26
int64_t DifficultyAdjustmentInterval() const
Definition: params.h:180
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.
Definition: validationinterface.cpp:84
Definition: versionbits.h:24
void IncrementExtraNonce(CBlock *pblock, const CBlockIndex *pindexPrev, unsigned int &nExtraNonce)
Modify the extranonce in a block.
Definition: miner.cpp:499
unsigned int HighestTargetTracked(FeeEstimateHorizon horizon) const
Calculation of highest target that estimates are tracked for.
Definition: fees.cpp:710
bool GetBlockTxOuts(int nBlockHeight, CAmount blockReward, std::vector< CTxOut > &voutMasternodePaymentsRet) const
Definition: masternode-payments.cpp:318
uint256 ParseHashStr(const std::string &, const std::string &strName)
Definition: core_read.cpp:134
std::string EncodeDestination(const CTxDestination &dest)
Definition: base58.cpp:329
Definition: versionbits.h:21
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:947
bool TestBlockValidity(CValidationState &state, const CChainParams &chainparams, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot)
Check a block is completely valid from start to finish (only works on top of our current best block...
Definition: validation.cpp:3837
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:453
Definition: server.h:37
unsigned int ParseConfirmTarget(const UniValue &value)
Check bounds on a command line confirm target.
Definition: mining.cpp:42
unsigned int GetTransactionsUpdated() const
Definition: txmempool.cpp:350
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=nullptr, bool *pfOverflow=nullptr)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
Definition: arith_uint256.cpp:206
Definition: chain.h:160
Definition: fees.h:74
Use default settings based on other criteria.
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
bool IsSporkActive(SporkId nSporkID)
IsSporkActive returns a bool for time-based sporks, and should be used to determine whether the spork...
Definition: spork.cpp:211
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:54
CChain & chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:217
std::unique_lock< std::mutex > WaitableLock
Just a typedef for std::unique_lock, can be wrapped later if desired.
Definition: sync.h:109
Definition: script.h:59
ThresholdState VersionBitsState(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::DeploymentPos pos, VersionBitsCache &cache)
Definition: versionbits.cpp:245
void PrioritiseTransaction(const uint256 &hash, const CAmount &nFeeDelta)
Affect CreateNewBlock prioritisation of transactions.
Definition: txmempool.cpp:1317
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
Definition: feerate.h:41
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]
Definition: params.h:171
Error parsing or validating structure in raw format.
Definition: protocol.h:55
Definition: server.h:128