@@ -3165,54 +3165,50 @@ bool ResetBlockFailureFlags(CBlockIndex *pindex) {
3165
3165
return true ;
3166
3166
}
3167
3167
3168
- static void AcceptProofOfStakeBlock (const CBlock &block, CBlockIndex *pindexNew )
3168
+ bool AcceptProofOfStakeBlock (const CBlock &block, CBlockIndex *pindex )
3169
3169
{
3170
- if (!pindexNew )
3171
- return ;
3170
+ if (!pindex )
3171
+ return false ;
3172
3172
3173
3173
if (block.IsProofOfStake ()) {
3174
- pindexNew ->SetProofOfStake ();
3175
- pindexNew ->prevoutStake = block.vtx [1 ]->vin [0 ].prevout ;
3176
- pindexNew ->nStakeTime = block.nTime ;
3174
+ pindex ->SetProofOfStake ();
3175
+ pindex ->prevoutStake = block.vtx [1 ]->vin [0 ].prevout ;
3176
+ pindex ->nStakeTime = block.nTime ;
3177
3177
} else {
3178
- pindexNew ->prevoutStake .SetNull ();
3179
- pindexNew ->nStakeTime = 0 ;
3178
+ pindex ->prevoutStake .SetNull ();
3179
+ pindex ->nStakeTime = 0 ;
3180
3180
}
3181
3181
3182
- // update previous block pointer
3183
- // pindexNew->pprev->pnext = pindexNew;
3184
-
3185
3182
// ppcoin: compute chain trust score
3186
- pindexNew ->bnChainTrust = (pindexNew ->pprev ? pindexNew ->pprev ->bnChainTrust : ArithToUint256 (0 + pindexNew ->GetBlockTrust ()));
3183
+ pindex ->bnChainTrust = (pindex ->pprev ? pindex ->pprev ->bnChainTrust : ArithToUint256 (0 + pindex ->GetBlockTrust ()));
3187
3184
3188
3185
// ppcoin: compute stake entropy bit for stake modifier
3189
- if (!pindexNew ->SetStakeEntropyBit (pindexNew ->GetStakeEntropyBit ()))
3186
+ if (!pindex ->SetStakeEntropyBit (pindex ->GetStakeEntropyBit ()))
3190
3187
LogPrintf (" AcceptProofOfStakeBlock() : SetStakeEntropyBit() failed \n " );
3191
3188
3192
- uint256 hash = block.GetHash ();
3193
-
3194
3189
// ppcoin: record proof-of-stake hash value
3195
- if (pindexNew->IsProofOfStake ()) {
3190
+ if (pindex->IsProofOfStake ()) {
3191
+ uint256 hash = block.GetHash ();
3196
3192
if (!mapProofOfStake.count (hash))
3197
3193
LogPrintf (" AcceptProofOfStakeBlock() : hashProofOfStake not found in map \n " );
3198
- pindexNew ->hashProofOfStake = mapProofOfStake[hash];
3194
+ pindex ->hashProofOfStake = mapProofOfStake[hash];
3199
3195
}
3200
3196
3201
3197
// ppcoin: compute stake modifier
3202
3198
uint64_t nStakeModifier = 0 ;
3203
3199
bool fGeneratedStakeModifier = false ;
3204
- if (!ComputeNextStakeModifier (pindexNew , nStakeModifier, fGeneratedStakeModifier ))
3200
+ if (!ComputeNextStakeModifier (pindex , nStakeModifier, fGeneratedStakeModifier ))
3205
3201
LogPrintf (" AcceptProofOfStakeBlock() : ComputeNextStakeModifier() failed \n " );
3206
- pindexNew->SetStakeModifier (nStakeModifier, fGeneratedStakeModifier );
3207
- pindexNew->nStakeModifierChecksum = GetStakeModifierChecksum (pindexNew);
3208
- if (!CheckStakeModifierCheckpoints (pindexNew->nHeight , pindexNew->nStakeModifierChecksum )) {
3209
- LogPrintf (" AcceptProofOfStakeBlock() : Rejected by stake modifier checkpoint height=%d, modifier=%s \n " , pindexNew->nHeight , std::to_string (nStakeModifier));
3210
- LogPrintf (" pindexNew->nStakeModifierChecksum = %08x\n " , pindexNew->nStakeModifierChecksum );
3211
- } else {
3212
- LogPrintf (" AcceptProofOfStakeBlock() : Accepted stake modifier - checksum %08x\n " , pindexNew->nStakeModifierChecksum );
3202
+ pindex->SetStakeModifier (nStakeModifier, fGeneratedStakeModifier );
3203
+ pindex->nStakeModifierChecksum = GetStakeModifierChecksum (pindex);
3204
+ if (!CheckStakeModifierCheckpoints (pindex->nHeight , pindex->nStakeModifierChecksum )) {
3205
+ LogPrintf (" AcceptProofOfStakeBlock() : Rejected by stake modifier checkpoint height=%d, modifier=0x%016llx, checksum=0x%08x\n " ,
3206
+ pindex->nHeight , nStakeModifier, pindex->nStakeModifierChecksum );
3207
+ return false ;
3213
3208
}
3214
3209
3215
- setDirtyBlockIndex.insert (pindexNew);
3210
+ setDirtyBlockIndex.insert (pindex);
3211
+ return true ;
3216
3212
}
3217
3213
3218
3214
CBlockIndex* AddToBlockIndex (const CBlockHeader& block, enum BlockStatus nStatus = BLOCK_VALID_TREE)
@@ -3794,7 +3790,8 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
3794
3790
return error (" %s: %s" , __func__, FormatStateMessage (state));
3795
3791
}
3796
3792
3797
- AcceptProofOfStakeBlock (block, pindex);
3793
+ if (!AcceptProofOfStakeBlock (block, pindex))
3794
+ return false ;
3798
3795
3799
3796
// Header is valid/has work, merkle tree is good...RELAY NOW
3800
3797
// (but if it does not build on our best tip, let the SendMessages loop relay it)
@@ -4427,7 +4424,8 @@ static bool AddGenesisBlock(const CChainParams& chainparams, const CBlock& block
4427
4424
if (!WriteBlockToDisk (block, blockPos, chainparams.MessageStart ()))
4428
4425
return error (" %s: writing genesis block to disk failed" , __func__);
4429
4426
CBlockIndex *pindex = AddToBlockIndex (block);
4430
- AcceptProofOfStakeBlock (block, pindex);
4427
+ if (!AcceptProofOfStakeBlock (block, pindex))
4428
+ return error (" %s: genesis block not accepted" , __func__);
4431
4429
if (!ReceivedBlockTransactions (block, state, pindex, blockPos))
4432
4430
return error (" %s: genesis block not accepted" , __func__);
4433
4431
return true ;
0 commit comments