aboutsummaryrefslogtreecommitdiff
path: root/src/rpcmining.cpp
diff options
context:
space:
mode:
authorRoss Nicoll <[email protected]>2015-07-05 17:45:38 +0100
committerRoss Nicoll <[email protected]>2015-07-10 20:23:14 +0100
commitc453bcc9e5fd98ae4aebd1f2fc85192b5fd7410a (patch)
tree0422e17d73ffc244e48ba41c4ea63cd39c8b09dd /src/rpcmining.cpp
parentMerge AuxPoW support from Namecore (diff)
downloaddiscoin-c453bcc9e5fd98ae4aebd1f2fc85192b5fd7410a.tar.xz
discoin-c453bcc9e5fd98ae4aebd1f2fc85192b5fd7410a.zip
Adapt AuxPoW to Dogecoin
Changed AuxPoW parent block hashing to use Scrypt rather than SHA256 hash. Update chain parameters to match Dogecoin Move CheckProofOfWork into dogecoin.cpp and rename it to CheckAuxPowProofOfWork. Add operator overrides to CBlockVersion so that naive usage operates on the underlying version without chain ID or flags. Modify RPC mining to more closely match existing submitblock() structure
Diffstat (limited to 'src/rpcmining.cpp')
-rw-r--r--src/rpcmining.cpp66
1 files changed, 38 insertions, 28 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index 3639ac931..7eee8bb05 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -8,6 +8,7 @@
#include "consensus/consensus.h"
#include "consensus/validation.h"
#include "core_io.h"
+#include "dogecoin.h"
#include "init.h"
#include "main.h"
#include "miner.h"
@@ -30,30 +31,6 @@
using namespace json_spirit;
using namespace std;
-#ifdef ENABLE_WALLET
-// Key used by getwork miners.
-// Allocated in InitRPCMining, free'd in ShutdownRPCMining
-static CReserveKey* pminingKey = NULL;
-
-void InitRPCMining()
-{
- if (!pwalletMain)
- return;
-
- // getwork/getblocktemplate mining rewards paid here:
- pminingKey = new CReserveKey(pwalletMain);
-}
-
-void ShutdownRPCMining()
-{
- if (!pminingKey)
- return;
-
- delete pminingKey;
- pminingKey = NULL;
-}
-#endif // ENABLE_WALLET
-
/**
* Return average network hashes per second based on the last 'lookup' blocks,
* or from the last difficulty change if 'lookup' is nonpositive.
@@ -182,7 +159,7 @@ Value generate(const Array& params, bool fHelp)
LOCK(cs_main);
IncrementExtraNonce(pblock, chainActive.Tip(), nExtraNonce);
}
- while (!CheckProofOfWork(pblock->GetHash(), pblock->nBits, Params().GetConsensus())) {
+ while (!CheckProofOfWork(pblock->GetPoWHash(), pblock->nBits, Params().GetConsensus())) {
// Yes, there is a chance every nonce could fail to satisfy the -regtest
// target -- 1 in 2^(2^32). That ain't gonna happen.
++pblock->nNonce;
@@ -787,7 +764,6 @@ Value getauxblock(const Array& params, bool fHelp)
if (pwalletMain == NULL)
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found (disabled)");
- assert (pminingKey);
if (vNodes.empty() && !Params().MineBlocksOnDemand())
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED,
@@ -822,6 +798,7 @@ Value getauxblock(const Array& params, bool fHelp)
static uint64_t nStart;
static CBlockTemplate* pblocktemplate;
static unsigned nExtraNonce = 0;
+ CReserveKey reservekey(pwalletMain);
// Update block
{
@@ -840,7 +817,7 @@ Value getauxblock(const Array& params, bool fHelp)
}
// Create new block with nonce = 0 and extraNonce = 1
- pblocktemplate = CreateNewBlockWithKey(*pminingKey);
+ pblocktemplate = CreateNewBlockWithKey(reservekey);
if (!pblocktemplate)
throw JSONRPCError(RPC_OUT_OF_MEMORY, "out of memory");
@@ -900,6 +877,39 @@ Value getauxblock(const Array& params, bool fHelp)
block.SetAuxpow(new CAuxPow(pow));
assert(block.GetHash() == hash);
- return ProcessBlockFound(&block, *pwalletMain, *pminingKey);
+ // This is a straight cut & paste job from submitblock()
+ bool fBlockPresent = false;
+ {
+ LOCK(cs_main);
+ BlockMap::iterator mi = mapBlockIndex.find(hash);
+ if (mi != mapBlockIndex.end()) {
+ CBlockIndex *pindex = mi->second;
+ if (pindex->IsValid(BLOCK_VALID_SCRIPTS))
+ return "duplicate";
+ if (pindex->nStatus & BLOCK_FAILED_MASK)
+ return "duplicate-invalid";
+ // Otherwise, we might only have the header - process the block before returning
+ fBlockPresent = true;
+ }
+ }
+
+ CValidationState state;
+ submitblock_StateCatcher sc(block.GetHash());
+ RegisterValidationInterface(&sc);
+ bool fAccepted = ProcessNewBlock(state, NULL, &block, true, NULL);
+ UnregisterValidationInterface(&sc);
+ if (fBlockPresent)
+ {
+ if (fAccepted && !sc.found)
+ return "duplicate-inconclusive";
+ return "duplicate";
+ }
+ if (fAccepted)
+ {
+ if (!sc.found)
+ return "inconclusive";
+ state = sc.state;
+ }
+ return BIP22ValidationResult(state);
}
#endif // ENABLE_WALLET