The stake modifier used to hash for a stake kernel is chosen as the stake modifier about a selection interval later than the coin generating the kernel
| 338 | // The stake modifier used to hash for a stake kernel is chosen as the stake |
| 339 | // modifier about a selection interval later than the coin generating the kernel |
| 340 | bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64_t& nStakeModifier, int& nStakeModifierHeight, int64_t& nStakeModifierTime, bool fPrintProofOfStake) |
| 341 | { |
| 342 | nStakeModifier = 0; |
| 343 | if (!mapBlockIndex.count(hashBlockFrom)) |
| 344 | return error("GetKernelStakeModifier() : block not indexed"); |
| 345 | |
| 346 | const CBlockIndex* pindexFrom = mapBlockIndex[hashBlockFrom]; |
| 347 | nStakeModifierHeight = pindexFrom->nHeight; |
| 348 | nStakeModifierTime = pindexFrom->GetBlockTime(); |
| 349 | |
| 350 | const int64_t nSelectionTime = GetSelectionTime(); |
| 351 | const CBlockIndex* pindex = pindexFrom; |
| 352 | CBlockIndex* pindexNext = chainActive[pindexFrom->nHeight + 1]; |
| 353 | |
| 354 | // loop to find the stake modifier later by a selection time |
| 355 | while (nStakeModifierTime < pindexFrom->GetBlockTime() + nSelectionTime) { |
| 356 | if (!pindexNext) { |
| 357 | // Should never happen |
| 358 | return error("Null pindexNext\n"); |
| 359 | } |
| 360 | |
| 361 | pindex = pindexNext; |
| 362 | pindexNext = chainActive[pindexNext->nHeight + 1]; |
| 363 | if (pindex->GeneratedStakeModifier()) { |
| 364 | nStakeModifierHeight = pindex->nHeight; |
| 365 | nStakeModifierTime = pindex->GetBlockTime(); |
| 366 | } |
| 367 | } |
| 368 | nStakeModifier = pindex->nStakeModifier; |
| 369 | return true; |
| 370 | } |
| 371 | #endif |
| 372 | |
| 373 | bool MultiplyStakeTarget(uint256& bnTarget, int nModifierHeight, int64_t nModifierTime, int64_t nWeight) { |
no test coverage detected