src/kernel.cpp
static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64& nStakeModifier, int& nStakeModifierHeight, int64& nStakeModifierTime, bool fPrintProofOfStake)
{
    nStakeModifier = 0;
    if (!mapBlockIndex.count(hashBlockFrom))
        return error("GetKernelStakeModifier() : block not indexed");
    const CBlockIndex* pindexFrom = mapBlockIndex[hashBlockFrom];
    nStakeModifierHeight = pindexFrom->nHeight;
    nStakeModifierTime = pindexFrom->GetBlockTime();
    int64 nStakeModifierSelectionInterval = GetStakeModifierSelectionInterval();
    const CBlockIndex* pindex = pindexFrom;
    // loop to find the stake modifier later by a selection interval
    while (nStakeModifierTime < pindexFrom->GetBlockTime() + nStakeModifierSelectionInterval)
    {
        if (!pindex->pnext)
        {   // reached best block; may happen if node is behind on block chain
            if (fPrintProofOfStake || (pindex->GetBlockTime() + nStakeMinAge - nStakeModifierSelectionInterval > GetAdjustedTime()))
                return error("GetKernelStakeModifier() : reached best block at height %d from block at hight %d",
                    pindex->nHeight, pindexFrom->nHeight);
            else
                return false;
        }
        pindex = pindex->pnext;
        if (pindex->GeneratedStakeModifier())
        {
            nStakeModifierHeight = pindex->nHeight;
            nStakeModifierTime = pindex->GetBlockTime();
            // printf("GetKernelStakeModifier : nStakeModifierHeight=%d\n", nStakeModifierHeight);
        }
    }
    nStakeModifier = pindex->nStakeModifier;
    return true;
}
// 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
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
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
static bool GetKernelStakeModifier(uint256 hashBlockFrom, uint64& nStakeModifier, int& nStakeModifierHeight, int64& nStakeModifierTime, bool fPrintProofOfStake)
{
    nStakeModifier = 0;
    if (!mapBlockIndex.count(hashBlockFrom))
        return error("GetKernelStakeModifier() : block not indexed");
    const CBlockIndex* pindexFrom = mapBlockIndex[hashBlockFrom];
    nStakeModifierHeight = pindexFrom->nHeight;
    nStakeModifierTime = pindexFrom->GetBlockTime();
    int64 nStakeModifierSelectionInterval = GetStakeModifierSelectionInterval();
    const CBlockIndex* pindex = pindexFrom;
    while (nStakeModifierTime < pindexFrom->GetBlockTime() + nStakeModifierSelectionInterval)
    {
        if (!pindex->pnext)
        {   
            if (fPrintProofOfStake || (pindex->GetBlockTime() + nStakeMinAge - nStakeModifierSelectionInterval > GetAdjustedTime()))
                return error("GetKernelStakeModifier() : reached best block at height %d from block at hight %d",
                    pindex->nHeight, pindexFrom->nHeight);
            else
                return false;
        }
        pindex = pindex->pnext;
        if (pindex->GeneratedStakeModifier())
        {
            nStakeModifierHeight = pindex->nHeight;
            nStakeModifierTime = pindex->GetBlockTime();
        }
    }
    nStakeModifier = pindex->nStakeModifier;
    return true;
}
static bool GetKernelStakeModifier ( uint256 hashBlockFrom , uint64 & nStakeModifier , int & nStakeModifierHeight , int64 & nStakeModifierTime , bool fPrintProofOfStake ) { nStakeModifier = 0 ; if ( ! mapBlockIndex . count ( hashBlockFrom ) ) return error ( " " ) ; const CBlockIndex * pindexFrom = mapBlockIndex [ hashBlockFrom ] ; nStakeModifierHeight = pindexFrom -> nHeight ; nStakeModifierTime = pindexFrom -> GetBlockTime ( ) ; int64 nStakeModifierSelectionInterval = GetStakeModifierSelectionInterval ( ) ; const CBlockIndex * pindex = pindexFrom ; while ( nStakeModifierTime < pindexFrom -> GetBlockTime ( ) + nStakeModifierSelectionInterval ) { if ( ! pindex -> pnext ) { if ( fPrintProofOfStake || ( pindex -> GetBlockTime ( ) + nStakeMinAge - nStakeModifierSelectionInterval > GetAdjustedTime ( ) ) ) return error ( " " , pindex -> nHeight , pindexFrom -> nHeight ) ; else return false ; } pindex = pindex -> pnext ; if ( pindex -> GeneratedStakeModifier ( ) ) { nStakeModifierHeight = pindex -> nHeight ; nStakeModifierTime = pindex -> GetBlockTime ( ) ; } } nStakeModifier = pindex -> nStakeModifier ; return true ; }
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
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
// loop to find the stake modifier later by a selection interval // reached best block; may happen if node is behind on block chain // printf("GetKernelStakeModifier : nStakeModifierHeight=%d\n", nStakeModifierHeight);