diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index d154523..be4ab5e 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
| @@ -3936,6 +3936,14 @@ connected: | |||
| 3936 | std::string jobId; | 3936 | std::string jobId; |
| 3937 | unsigned char header[80] = {}; | 3937 | unsigned char header[80] = {}; |
| 3938 | uint256 target; | 3938 | uint256 target; |
| 3939 | // Cached answer to "which block is this job built on", for the | ||
| 3940 | // mining.notify handler below -- see the comment there. Session-local, so | ||
| 3941 | // a reconnect re-resolves rather than trusting an answer obtained before | ||
| 3942 | // a possible change of pool. | ||
| 3943 | uint256 hashPrevResolved; // prevhash the cached answer describes | ||
| 3944 | bool fPrevResolved = false; // whether that answer exists yet | ||
| 3945 | int nPrevHeight = -1; // its height, or -1 == unknown to us | ||
| 3946 | int nBestHeightResolved = -1; // nBestHeight when we last resolved | ||
| 3939 | double currentDifficulty = 1.0; // updated by mining.set_difficulty from pool | 3947 | double currentDifficulty = 1.0; // updated by mining.set_difficulty from pool |
| 3940 | bool haveJob = false; | 3948 | bool haveJob = false; |
| 3941 | bool gotSubscribeAck = false; | 3949 | bool gotSubscribeAck = false; |
| @@ -4064,8 +4072,64 @@ connected: | |||
| 4064 | jobShared.jobSeq++; | 4072 | jobShared.jobSeq++; |
| 4065 | jobShared.haveJob = true; | 4073 | jobShared.haveJob = true; |
| 4066 | } | 4074 | } |
| 4067 | LogPrint("worker", "[pool->worker] new job %s received\n", | 4075 | // Log the chain position the pool is |
| 4068 | jobId.c_str()); | 4076 | // building on, so a stale or private |
| 4077 | // fork is auditable from worker logs. | ||
| 4078 | // The prevhash comes from the header we | ||
| 4079 | // actually hash (== p[2] of the notify); | ||
| 4080 | // a brief cs_main lookup is safe here -- | ||
| 4081 | // this thread holds no other lock. | ||
| 4082 | // | ||
| 4083 | // Resolving it is the expensive half, and | ||
| 4084 | // this is the socket-reading thread: block | ||
| 4085 | // validation can hold cs_main for a long | ||
| 4086 | // time, and every moment spent waiting on | ||
| 4087 | // it here is a moment set_difficulty and | ||
| 4088 | // share responses are not being handled. | ||
| 4089 | // Most notifies in a round are a new job | ||
| 4090 | // on the SAME tip, so the answer is cached | ||
| 4091 | // and re-resolved only when it could come | ||
| 4092 | // out differently: a prevhash we have not | ||
| 4093 | // resolved, or one we could NOT resolve | ||
| 4094 | // last time while the chain has since | ||
| 4095 | // moved (unknown -> known). A block's | ||
| 4096 | // height is fixed once mapBlockIndex knows | ||
| 4097 | // it, so a cached "known" never goes | ||
| 4098 | // stale. nBestHeight is read unlocked on | ||
| 4099 | // purpose -- it only decides whether to | ||
| 4100 | // repeat a lookup, never what gets | ||
| 4101 | // printed, so a stale read costs at most | ||
| 4102 | // one deferred or one extra lookup. | ||
| 4103 | // The line still prints in full for every | ||
| 4104 | // job, cached or not. | ||
| 4105 | uint256 hashPrev; | ||
| 4106 | memcpy(&hashPrev, header + 4, 32); | ||
| 4107 | if (LogAcceptsCategory("worker")) | ||
| 4108 | { | ||
| 4109 | int nBestHeightNow = nBestHeight; | ||
| 4110 | if (!fPrevResolved | ||
| 4111 | || hashPrev != hashPrevResolved | ||
| 4112 | || (nPrevHeight < 0 && nBestHeightNow != nBestHeightResolved)) | ||
| 4113 | { | ||
| 4114 | nPrevHeight = -1; | ||
| 4115 | CRITICAL_BLOCK(cs_main) | ||
| 4116 | { | ||
| 4117 | map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashPrev); | ||
| 4118 | if (mi != mapBlockIndex.end()) | ||
| 4119 | nPrevHeight = (*mi).second->nHeight; | ||
| 4120 | } | ||
| 4121 | hashPrevResolved = hashPrev; | ||
| 4122 | nBestHeightResolved = nBestHeightNow; | ||
| 4123 | fPrevResolved = true; | ||
| 4124 | } | ||
| 4125 | if (nPrevHeight >= 0) | ||
| 4126 | LogPrint("worker", "[pool->worker] new job %s received, prevhash %s (known, job height %d)\n", | ||
| 4127 | jobId.c_str(), hashPrev.GetHex().c_str(), | ||
| 4128 | nPrevHeight + 1); | ||
| 4129 | else | ||
| 4130 | LogPrint("worker", "[pool->worker] new job %s received, prevhash %s (unknown to our chain)\n", | ||
| 4131 | jobId.c_str(), hashPrev.GetHex().c_str()); | ||
| 4132 | } | ||
| 4069 | SetParticipantMiningStatus("hashing job " + jobId); | 4133 | SetParticipantMiningStatus("hashing job " + jobId); |
| 4070 | } | 4134 | } |
| 4071 | } | 4135 | } |