aboutsummaryrefslogtreecommitdiff
path: root/src/rpcmining.cpp
diff options
context:
space:
mode:
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