PRCYCoin  2.0.0.7rc1
P2P Digital Currency
poa.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2015-2018 The PIVX developers
4 // Copyright (c) 2018-2020 The DAPS Project developers
5 // Copyright (c) 2020-2022 The PRivaCY Coin Developers
6 // Distributed under the MIT/X11 software license, see the accompanying
7 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
8 
9 #include "poa.h"
10 
11 #include "chain.h"
12 #include "chainparams.h"
13 #include "main.h"
14 #include "primitives/block.h"
15 #include "uint256.h"
16 #include "util.h"
17 
18 #include <math.h>
19 
20 unsigned int N_BITS = 0x1e050000;
21 unsigned int N_BITS_SF = 0x1e127ff8; // Params().SoftFork()
22 unsigned int N_BITS_PD = 0x1e02b2dc; // Params().PoANewDiff()
23 
24 unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader* pblock)
25 {
26  if (Params().IsRegTestNet())
27  return pindexLast->nBits;
28 
29  if (N_BITS != 0 && pblock->IsPoABlockByVersion()) {
30  if (pindexLast->nHeight < Params().SoftFork()) {
31  LogPrint(BCLog::POA, "%s: returning N_BITS\n", __func__);
32  return N_BITS;
33  }
34  if (pindexLast->nHeight < Params().PoANewDiff()) {
35  LogPrint(BCLog::POA, "%s: returning N_BITS_SF\n", __func__);
36  return N_BITS_SF;
37  }
38  LogPrint(BCLog::POA, "%s: returning N_BITS_PD\n", __func__);
39  return N_BITS_PD;
40  }
41  /* current difficulty formula, prcycoin - DarkGravity v3, written by Evan Duffield - [email protected] */
42  const CBlockIndex* BlockLastSolved = pindexLast;
43  const CBlockIndex* BlockReading = pindexLast;
44  int64_t nActualTimespan = 0;
45  int64_t LastBlockTime = 0;
46  int64_t PastBlocksMin = 24;
47  int64_t PastBlocksMax = 24;
48  int64_t CountBlocks = 0;
49  uint256 PastDifficultyAverage;
50  uint256 PastDifficultyAveragePrev;
51 
52  if (BlockLastSolved == NULL || BlockLastSolved->nHeight == 0 || BlockLastSolved->nHeight < PastBlocksMin) {
53  return Params().ProofOfWorkLimit().GetCompact();
54  }
55 
56  if (pindexLast->nHeight > Params().LAST_POW_BLOCK()) {
57  uint256 bnTargetLimit = (~UINT256_ZERO >> 24);
58  int64_t nTargetSpacing = 60;
59  int64_t nTargetTimespan = 60 * 40;
60 
61  //finding last PoS block
62  CBlockIndex* pLastPoS = pindexLast->pprev;
63  while (!pLastPoS->IsProofOfStake() && pLastPoS->nHeight > Params().LAST_POW_BLOCK()) {
64  pLastPoS = pLastPoS->pprev;
65  }
66  int64_t nActualSpacing = 0;
67  //ig
68  if (pindexLast->nHeight != 0)
69  nActualSpacing = pindexLast->GetBlockTime() - pLastPoS->GetBlockTime();
70 
71  if (nActualSpacing < 0)
72  nActualSpacing = 1;
73 
74  // ppcoin: target change every block
75  // ppcoin: retarget with exponential moving toward target spacing
76  uint256 bnNew;
77  if (pindexLast->nHeight < Params().SoftFork()) {
78  bnNew.SetCompact(pindexLast->nBits);
79  } else {
80  if (pindexLast->IsProofOfStake()) {
81  bnNew.SetCompact(pindexLast->nBits);
82  } else {
83  bnNew.SetCompact(pLastPoS->nBits);
84  }
85  }
86 
87  int64_t nInterval = nTargetTimespan / nTargetSpacing;
88  bnNew *= ((nInterval - 1) * nTargetSpacing + nActualSpacing + nActualSpacing);
89  bnNew /= ((nInterval + 1) * nTargetSpacing);
90 
91  if (bnNew <= 0 || bnNew > bnTargetLimit)
92  bnNew = bnTargetLimit;
93 
94  return bnNew.GetCompact();
95  }
96 
97  for (unsigned int i = 1; BlockReading && BlockReading->nHeight > 0; i++) {
98  if (PastBlocksMax > 0 && i > PastBlocksMax) {
99  break;
100  }
101  CountBlocks++;
102 
103  if (CountBlocks <= PastBlocksMin) {
104  if (CountBlocks == 1) {
105  PastDifficultyAverage.SetCompact(BlockReading->nBits);
106  } else {
107  PastDifficultyAverage = ((PastDifficultyAveragePrev * CountBlocks) + (uint256().SetCompact(BlockReading->nBits))) / (CountBlocks + 1);
108  }
109  PastDifficultyAveragePrev = PastDifficultyAverage;
110  }
111 
112  if (LastBlockTime > 0) {
113  int64_t Diff = (LastBlockTime - BlockReading->GetBlockTime());
114  nActualTimespan += Diff;
115  }
116  LastBlockTime = BlockReading->GetBlockTime();
117 
118  if (BlockReading->pprev == NULL) {
119  assert(BlockReading);
120  break;
121  }
122  BlockReading = BlockReading->pprev;
123  }
124 
125  uint256 bnNew(PastDifficultyAverage);
126 
127  int64_t _nTargetTimespan = CountBlocks * Params().TargetSpacing();
128 
129  if (nActualTimespan < _nTargetTimespan / 3)
130  nActualTimespan = _nTargetTimespan / 3;
131  if (nActualTimespan > _nTargetTimespan * 3)
132  nActualTimespan = _nTargetTimespan * 3;
133 
134  // Retarget
135  bnNew *= nActualTimespan;
136  bnNew /= _nTargetTimespan;
137 
138  if (bnNew > Params().ProofOfWorkLimit()) {
139  bnNew = Params().ProofOfWorkLimit();
140  }
141 
142  return bnNew.GetCompact();
143 }
144 
145 bool CheckProofOfWork(uint256 hash, unsigned int nBits)
146 {
147  bool fNegative;
148  bool fOverflow;
149  uint256 bnTarget;
150 
151  if (Params().SkipProofOfWorkCheck())
152  return true;
153 
154  bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
155 
156  // Check range
157  if (fNegative || bnTarget.IsNull() || fOverflow || bnTarget > Params().ProofOfWorkLimit())
158  return error("CheckProofOfWork(): nBits below minimum work");
159 
160  // Check proof of work matches claimed amount
161  if (hash > bnTarget) {
162  if (Params().MineBlocksOnDemand())
163  return false;
164  else
165  return error("CheckProofOfWork() : hash doesn't match nBits");
166  }
167 
168  return true;
169 }
170 
172 {
173  uint256 bnTarget;
174  bool fNegative;
175  bool fOverflow;
176  bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow);
177  if (fNegative || fOverflow || bnTarget.IsNull())
178  return UINT256_ZERO;
179  // We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256
180  // as it's too large for a uint256. However, as 2**256 is at least as large
181  // as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1,
182  // or ~bnTarget / (nTarget+1) + 1.
183  return (~bnTarget / (bnTarget + 1)) + 1;
184 }
185 
187  if (!p || !p->pprev) return NULL;
188  return p->pprev->IsProofOfStake()?p->pprev:FindPrevPoSBlock(p->pprev);
189 }
190 
191 //If blockheight = -1, the to-be-checked block is not included yet in the chain, otherwise, that is the height of the poa block
193 {
194  int nHeight;
195  //block.Merkle
196  CBlockIndex* currentTip = mapBlockIndex[block.hashPrevBlock];
197  if (!currentTip) {
198  return error("CheckPoAContainRecentHash(): Previous block not found");
199  }
200  //Find the previous PoA block
201  CBlockIndex* pindex = currentTip;
202  nHeight = pindex->nHeight;
203  while (pindex->nHeight >= Params().START_POA_BLOCK()) {
204  if (pindex->GetBlockHeader().IsPoABlockByVersion()) {
205  break;
206  }
207  pindex = pindex->pprev;
208  }
209  bool ret = true;
210  if (pindex->nHeight <= Params().START_POA_BLOCK()) {
211  //this is the first PoA block ==> check all PoS blocks from LAST_POW_BLOCK up to currentHeight - POA_BLOCK_PERIOD - 1 inclusive
212  int index = 0;
213  for (size_t i = Params().LAST_POW_BLOCK() + 1; i <= Params().LAST_POW_BLOCK() + block.posBlocksAudited.size(); i++) {
214  PoSBlockSummary pos = block.posBlocksAudited.at(index);
215  CBlockIndex* pidxInChain = mapBlockIndex[pos.hash];
216  if (!pidxInChain) {
217  return error("CheckPoAContainRecentHash(): Audited blocks not found");
218  }
219  if (pos.hash != pidxInChain->GetBlockHash() || pos.nTime != pidxInChain->nTime || pos.height != (uint32_t)pidxInChain->nHeight) {
220  ret = false;
221  break;
222  }
223  CBlockIndex* p = mapBlockIndex[pos.hash];
224  bool auditResult = ReVerifyPoSBlock(p);
225  if (!auditResult) {
226  if (pos.nTime) {
227  ret = false;
228  break;
229  }
230  }
231  index++;
232  }
233  } else {
234  if (pindex->nHeight >= Params().START_POA_BLOCK()) {
235  // Bypass bad block
236  if (pindex->nHeight == 17077 || pindex->nHeight == 17154 || pindex->nHeight == 135887 || pindex->nHeight == 311272) {
237  return true;
238  }
239  CBlock prevPoablock;
240  CBlockIndex* pblockindex = pindex;
241  if (!ReadBlockFromDisk(prevPoablock, pblockindex))
242  throw std::runtime_error("Can't read block from disk");
243  PoSBlockSummary lastAuditedPoSBlockInfo = prevPoablock.posBlocksAudited.back();
244  uint256 lastAuditedPoSHash = lastAuditedPoSBlockInfo.hash;
245  if (mapBlockIndex.count(lastAuditedPoSHash) < 1 && !IsWrongAudit(lastAuditedPoSHash.GetHex(), nHeight)) {
246  return error("CheckPoAContainRecentHash(): Audited blocks not found");
247  }
248 
249  uint256 currentFirstPoSAuditedHash = block.posBlocksAudited[0].hash;
250  uint256 currentLastPoSAuditedHash = block.posBlocksAudited.back().hash;
251  if (mapBlockIndex.count(currentFirstPoSAuditedHash) < 1 || mapBlockIndex.count(currentLastPoSAuditedHash) < 1) {
252  return error("CheckPoAContainRecentHash(): Being audited blocks not found");
253  }
254  CBlockIndex* pCurrentFirstPoSAuditedIndex = mapBlockIndex[currentFirstPoSAuditedHash];
255  CBlockIndex* pCurrentLastPoSAuditedIndex = mapBlockIndex[currentLastPoSAuditedHash];
256  uint256 fixedPoSAuditedHash = pCurrentFirstPoSAuditedIndex->GetAncestor(lastAuditedPoSBlockInfo.height)->GetBlockHash();
257  //check lastAuditedPoSHash and currentFirstPoSAuditedHash must be on the same fork
258  //that lastAuditedPoSHash must be parent block of currentFirstPoSAuditedHash
259  if (pCurrentFirstPoSAuditedIndex->GetAncestor(lastAuditedPoSBlockInfo.height)->GetBlockHash() != lastAuditedPoSHash && !IsFixedAudit(fixedPoSAuditedHash.GetHex(), nHeight)) {
260  return error("CheckPoAContainRecentHash(): PoA block is not on the same fork with the previous poa block");
261  }
262 
263  //check there is no pos block between lastAuditedPoSHash and currentFirstPoSAuditedHash
264  CBlockIndex* pIndexLoop = pCurrentFirstPoSAuditedIndex->pprev;
265  while(pIndexLoop && !pIndexLoop->IsProofOfStake()) {
266  pIndexLoop = pIndexLoop->pprev;
267  }
268  if (!pIndexLoop || (pIndexLoop->GetBlockHash() != lastAuditedPoSHash && !IsFixedAudit(fixedPoSAuditedHash.GetHex(), nHeight))) {
269  return error("CheckPoAContainRecentHash(): Some PoS block between %s and %s is not audited\n", lastAuditedPoSHash.GetHex(), currentFirstPoSAuditedHash.GetHex());
270  }
271 
272  //alright, check all pos blocks audited in the block is conseutive in the chain
273  for(size_t i = block.posBlocksAudited.size() - 1; i > 0; i--) {
274  uint256 thisPoSAduditedHash = block.posBlocksAudited[i].hash;
275  if (mapBlockIndex.count(thisPoSAduditedHash) < 1) {
276  return error("CheckPoAContainRecentHash(): PoS block %s not found\n", thisPoSAduditedHash.GetHex());
277  }
278  CBlockIndex* thisPoSAuditedIndex = mapBlockIndex[thisPoSAduditedHash];
279  CBlockIndex* previousPoSIndex = FindPrevPoSBlock(thisPoSAuditedIndex);
280  if (!previousPoSIndex) {
281  return error("CheckPoAContainRecentHash(): Failed to find previous PoS block for block %s\n", thisPoSAduditedHash.GetHex());
282  }
283  PoSBlockSummary previousSummary = block.posBlocksAudited[i - 1];
284  if (previousPoSIndex->GetBlockHash() != previousSummary.hash ||
285  (uint32_t)previousPoSIndex->nHeight != previousSummary.height ||
286  previousPoSIndex->GetBlockTime() != previousSummary.nTime) {
287  return error("CheckPoAContainRecentHash(): PoS block info not matched for %s\n", thisPoSAduditedHash.GetHex());
288  }
289  bool auditResult = ReVerifyPoSBlock(thisPoSAuditedIndex);
290  if (!auditResult) {
291  if (previousSummary.nTime) {
292  ret = false;
293  LogPrintf("%s: Failed to reverify block %s\n", __func__, previousSummary.hash.GetHex());
294  break;
295  }
296  }
297  }
298  if (ret) {
299  bool auditResult = ReVerifyPoSBlock(pCurrentFirstPoSAuditedIndex);
300  if (!auditResult) {
301  if (block.posBlocksAudited[0].nTime) {
302  ret = false;
303  LogPrintf("%s: Failed to reverify block %s\n", __func__, block.posBlocksAudited[0].hash.GetHex());
304  }
305  }
306  }
307  } else {
308  ret = block.hashPrevPoABlock.IsNull();
309  }
310  }
311  return ret;
312 }
313 
314 bool CheckNumberOfAuditedPoSBlocks(const CBlock& block, const CBlockIndex* pindex)
315 {
316  bool ret = true;
317 
318  if (pindex->nHeight > Params().PoAPaddingBlock()){
319  if (block.posBlocksAudited.size() < (size_t)Params().MIN_NUM_POS_BLOCKS_AUDITED() || block.posBlocksAudited.size() > (size_t)Params().MAX_NUM_POS_BLOCKS_AUDITED()) {
320  ret = false;
321  }
322  } else {
323  if (block.posBlocksAudited.size() < (size_t)Params().MIN_NUM_POS_BLOCKS_AUDITED() || block.posBlocksAudited.size() > 120 ) {
324  ret = false;
325  }
326  }
327  return ret;
328 }
329 
330 //Check whether the block is successfully mined and the mined hash satisfy the difficulty
332 {
333  const uint256 minedHash = block.minedHash; //block.ComputeMinedHash();
334  if (minedHash == block.minedHash) {
335  //Check minedHash satisfy difficulty based on nbits
336  bool fNegative;
337  bool fOverflow;
338  uint256 bnTarget;
339 
340  //As of now, there is no PoA miner, this will let all emulated PoA blocks bypass the check
341  if (Params().SkipProofOfWorkCheck() || Params().NetworkID() == CBaseChainParams::TESTNET)
342  return true;
343 
344  bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow);
345  LogPrintf("Target: %s, minedHash: %s\n", bnTarget.GetHex(), minedHash.GetHex());
346 
347  // Check proof of work matches claimed amount
348  if (minedHash > bnTarget) {
349  LogPrintf("Block mined hash not satisfied\n");
350  return error("CheckPoABlockMinedHash(): hash doesn't match nBits");
351  }
352 
353  return true;
354  }
355  return false;
356 }
357 
358 //A PoA block should contains previous PoA block hash
360 {
361  CBlockIndex* currentTip = mapBlockIndex[block.hashPrevBlock];
362  if (!currentTip) {
363  return error("CheckPrevPoABlockHash(): Previous block not found");
364  }
365  //Find the previous PoA block
366  CBlockIndex* pindex = currentTip;
367  while (pindex->nHeight > Params().START_POA_BLOCK()) {
368  if (pindex->GetBlockHeader().IsPoABlockByVersion()) {
369  break;
370  }
371  pindex = pindex->pprev;
372  }
373  bool ret = false;
374 
375  if (pindex->nHeight > Params().START_POA_BLOCK()) {
376  CBlockHeader header = pindex->GetBlockHeader();
377  uint256 poaBlockHash = header.GetHash();
378  if (poaBlockHash == block.hashPrevPoABlock) {
379  ret = true;
380  }
381  } else {
382  //This is the first poa block ==> previous poa hash = 0
383  ret = block.hashPrevPoABlock.IsNull();
384  }
385 
386  return ret;
387 }
388 
389 //Check whether the poa merkle root is correctly computed
390 bool CheckPoAMerkleRoot(const CBlock& block, bool* fMutate)
391 {
392  uint256 expected = block.ComputePoAMerkleTree(fMutate);
393  if (expected == block.hashPoAMerkleRoot) {
394  return true;
395  }
396  return false;
397 }
398 
399 //A PoA block cannot contain information of any PoA block information (hash, height, timestamp)
401 {
402  // Bypass bad block
403  if (pindex->nHeight == 17154 || pindex->nHeight == 135948 || pindex->nHeight == 311332) {
404  return true;
405  }
406  uint32_t numOfPoSBlocks = block.posBlocksAudited.size();
407  for (uint32_t i = 0; i < numOfPoSBlocks; i++) {
408  PoSBlockSummary pos = block.posBlocksAudited.at(i);
409  uint256 hash = pos.hash;
410  if (mapBlockIndex.count(hash) == 0) {
411  return false;
412  }
413  CBlockIndex* pblockindex = mapBlockIndex[hash];
414  CBlockHeader header = pblockindex->GetBlockHeader();
415  if (header.IsPoABlockByVersion()) {
416  return false;
417  }
418  }
419  return true;
420 }
421 
422 bool CheckPoAblockTime(const CBlock& block)
423 {
424  bool ret = false;
425 
426  if (block.hashPrevPoABlock.IsNull()) {
427  ret = true;
428  } else {
429  LogPrint(BCLog::POA, "%s: Previous PoA block hash %s\n", __func__, block.hashPrevPoABlock.GetHex());
430  if (mapBlockIndex.count(block.hashPrevPoABlock) != 0) {
431  CBlockIndex* pindex = mapBlockIndex[block.hashPrevPoABlock];
432  uint32_t prevPoATime = pindex->nTime;
433  if (block.nTime > prevPoATime && (block.nTime - pindex->nTime >= (uint32_t)Params().POA_BLOCK_TIME())) {
434  ret = true;
435  }
436  LogPrint(BCLog::POA, "%s: PoA Block time: %d, Previous: %d, Current: %d, Distance: %d\n", __func__,
437  Params().POA_BLOCK_TIME(), prevPoATime, block.nTime, block.nTime - pindex->nTime);
438  } else {
439  LogPrint(BCLog::POA, "%s: Cannot find block hash %s\n", __func__, block.hashPrevPoABlock.GetHex());
440  }
441  }
442  return ret;
443 }
444 
446 {
447  bool ret = false;
448 
449  if (block.hashPrevPoABlock.IsNull()) {
450  //First PoA block
451  LogPrint(BCLog::POA, "%s: First PoA Block Hash: %s\n", __func__, block.GetHash().GetHex());
452  ret = true;
453  } else {
454  if (mapBlockIndex.count(block.hashPrevPoABlock) != 0) {
455  CBlockIndex* pPrevPoAIndex = mapBlockIndex[block.hashPrevPoABlock];
456  CBlock prevPoablock;
457  if (!ReadBlockFromDisk(prevPoablock, pPrevPoAIndex))
458  throw std::runtime_error("Can't read block from disk");
459  ret = true;
460  for (size_t i = 0; i < block.posBlocksAudited.size(); i++) {
461  bool isAlreadyAudited = false;
462  for (size_t j = 0; j < prevPoablock.posBlocksAudited.size(); j++) {
463  if (prevPoablock.posBlocksAudited[j].hash == block.posBlocksAudited[i].hash && prevPoablock.posBlocksAudited[j].nTime == block.posBlocksAudited[i].nTime && prevPoablock.posBlocksAudited[j].height == block.posBlocksAudited[i].height) {
464  isAlreadyAudited = true;
465  LogPrint(BCLog::POA, "%s: PoA Block Hash: %s, is already auditted by Block %s\n", __func__,
466  block.posBlocksAudited[i].hash.GetHex(),
467  prevPoablock.GetHash().GetHex());
468  break;
469  }
470  }
471 
472  if (isAlreadyAudited) {
473  ret = false;
474  break;
475  }
476  }
477  }
478  }
479 
480  return ret;
481 }
482 
483 bool CheckPoABlockRewardAmount(const CBlock& block, const CBlockIndex* pindex)
484 {
485  bool ret = false;
486  CAmount nReward;
487  if (pindex->nHeight >= Params().HardFork()) {
488  nReward = 0.25 * COIN;
489  } else {
490  nReward = 0.5 * COIN;
491  }
492  ret = block.vtx.size() == 1;
493  ret = ret && block.vtx[0].vout.size() == 1;
494  ret = ret && block.vtx[0].vout[0].nValue == block.posBlocksAudited.size() * nReward;
495  ret = ret && VerifyZeroBlindCommitment(block.vtx[0].vout[0]);
496 
497  return ret;
498 }
499 
500 bool CheckPoABlockPaddingAmount(const CBlock& block, const CBlockIndex* pindex)
501 {
502  bool ret = true;
503 
504  int nHeight = pindex->nHeight;
505  int prevPoAHeight = 0;
506  int lastPoSHeight = 0;
507  int padding = 0;
508 
509  if (nHeight >= Params().HardFork()) {
510  ret = false;
511  if (mapBlockIndex.count(block.hashPrevPoABlock) != 0) {
512  CBlockIndex* pPrevPoAIndex = mapBlockIndex[block.hashPrevPoABlock];
513  CBlock prevPoablock;
514  if (!ReadBlockFromDisk(prevPoablock, pPrevPoAIndex))
515  throw std::runtime_error("Can't read block from disk");
516  prevPoAHeight = pPrevPoAIndex->nHeight;
517  for (size_t i = 0; i < block.posBlocksAudited.size(); i++) {
518  lastPoSHeight = block.posBlocksAudited[i].height;
519  }
520  }
521  padding = (nHeight - lastPoSHeight);
522  if (padding >= Params().PoAPadding()){
523  ret = true;
524  }
525  LogPrint(BCLog::POA, "%s: nHeight: %d, prevPoAHeight: %d, lastPoSHeight: %d, padding: %d\n", __func__, nHeight, prevPoAHeight, lastPoSHeight, padding);
526  }
527  return ret;
528 }
529 
530 // The functions below are workarounds for incorrectly audited blocks.
531 // Without them, PoA mining can not continue as these values are expected.
532 // To determine them, check the last 1-5 audited blocks of the raw data of
533 // the PoA block where the issue occurred. Compare to the real blocks/txids.
534 bool IsFixedAudit(std::string txid, int nHeight) {
535  LogPrint(BCLog::POA, "%s: block %d passed in as nHeight\n", __func__, nHeight);
536  // Correct TXIDs for Block 17152, Block 135946, Block 311330 and Block 311331
537  return (txid == "9965850037f14dcb4abf1168016e9f96f53692322714e7fac92a2b8838544135" || txid == "dd3d1dccf8f39a220e3a83cfabaf1b567b6696af877073ec580d09af6198f098" || txid =="e8aafd0513a8b2da536d55d9efd788956d03c6a0baa8acc4251f8dc0f3f03e87" || txid == "2666169b99521f12b6c69454f66e23af465c63e4a4807a5a8ed45467846ebe93");
538 }
539 
540 bool IsWrongAudit(std::string txid, int nHeight) {
541  LogPrint(BCLog::POA, "%s: block %d passed in as nHeight\n", __func__, nHeight);
542  // Orphan TXIDs for Block 135946, Block 311330 and Block 311331
543  return (txid == "ef99f7882a681a075ebd51fa83be01685257ca66ccb736950fefc037f00e1538" || txid == "6514be1fad4d956a059924d5185a6f9db20a62f2f99e3e9b79257d6d3ca36065" || txid == "fd5a19a7a7df25774a6a030295f01bae6395be4229ebe2caf4974d536432e0dd");
544 }
CBlockIndex::GetBlockTime
int64_t GetBlockTime() const
Definition: chain.h:364
block.h
CBlockHeader::hashPoAMerkleRoot
uint256 hashPoAMerkleRoot
Definition: block.h:75
UINT256_ZERO
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:129
CheckPrevPoABlockHash
bool CheckPrevPoABlockHash(const CBlockHeader &block)
Definition: poa.cpp:359
CBlockIndex::IsProofOfStake
bool IsProofOfStake() const
Definition: chain.h:390
CBlockIndex::GetAncestor
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
Definition: main.cpp:4856
IsWrongAudit
bool IsWrongAudit(std::string txid, int nHeight)
Definition: poa.cpp:540
N_BITS_PD
unsigned int N_BITS_PD
Definition: poa.cpp:22
CBlockHeader::nBits
uint32_t nBits
Definition: block.h:65
CBlockHeader
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:52
PoSBlockSummary::nTime
uint32_t nTime
Definition: block.h:20
base_uint::GetHex
std::string GetHex() const
Definition: arith_uint256.cpp:155
CBlock::ComputePoAMerkleTree
uint256 ComputePoAMerkleTree(bool *mutated=NULL) const
Definition: block.cpp:122
N_BITS_SF
unsigned int N_BITS_SF
Definition: poa.cpp:21
CheckPoABlockRewardAmount
bool CheckPoABlockRewardAmount(const CBlock &block, const CBlockIndex *pindex)
Definition: poa.cpp:483
CChainParams::ProofOfWorkLimit
const uint256 & ProofOfWorkLimit() const
Definition: chainparams.h:57
uint256.h
CBlockIndex::pprev
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:169
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:181
uint256::SetCompact
uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=nullptr, bool *pfOverflow=nullptr)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
Definition: uint256.cpp:14
CBlockHeader::IsPoABlockByVersion
bool IsPoABlockByVersion() const
Definition: block.h:105
CBlockIndex::nBits
unsigned int nBits
Definition: chain.h:229
chainparams.h
uint256::GetCompact
uint32_t GetCompact(bool fNegative=false) const
Definition: uint256.cpp:34
CBlockHeader::GetHash
uint256 GetHash() const
Definition: block.cpp:80
CheckPoABlockNotContainingPoABlockInfo
bool CheckPoABlockNotContainingPoABlockInfo(const CBlock &block, const CBlockIndex *pindex)
Definition: poa.cpp:400
CBlockIndex::nTime
unsigned int nTime
Definition: chain.h:228
VerifyZeroBlindCommitment
bool VerifyZeroBlindCommitment(const CTxOut &out)
Definition: main.cpp:2540
CBlockIndex::GetBlockHeader
CBlockHeader GetBlockHeader() const
Definition: chain.h:340
ReVerifyPoSBlock
bool ReVerifyPoSBlock(CBlockIndex *pindex)
Definition: main.cpp:621
BCLog::POA
@ POA
Definition: logging.h:65
CheckPoABlockPaddingAmount
bool CheckPoABlockPaddingAmount(const CBlock &block, const CBlockIndex *pindex)
Definition: poa.cpp:500
CheckPoAMerkleRoot
bool CheckPoAMerkleRoot(const CBlock &block, bool *fMutate)
Definition: poa.cpp:390
CChainParams::LAST_POW_BLOCK
int LAST_POW_BLOCK() const
Definition: chainparams.h:111
N_BITS
unsigned int N_BITS
Definition: poa.cpp:20
CAmount
int64_t CAmount
Amount in PRCY (Can be negative)
Definition: amount.h:17
LogPrintf
#define LogPrintf(...)
Definition: logging.h:147
CBlockHeader::minedHash
uint256 minedHash
Definition: block.h:79
CBlockHeader::nTime
uint32_t nTime
Definition: block.h:64
CheckPoABlockMinedHash
bool CheckPoABlockMinedHash(const CBlockHeader &block)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
Definition: poa.cpp:331
CChainParams::PoAPadding
int PoAPadding() const
Definition: chainparams.h:117
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
IsFixedAudit
bool IsFixedAudit(std::string txid, int nHeight)
Definition: poa.cpp:534
LogPrint
#define LogPrint(category,...)
Definition: logging.h:162
base_uint::IsNull
bool IsNull() const
Definition: arith_uint256.h:312
chain.h
CBaseChainParams::TESTNET
@ TESTNET
Definition: chainparamsbase.h:20
CheckProofOfWork
bool CheckProofOfWork(uint256 hash, unsigned int nBits)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
Definition: poa.cpp:145
CBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:359
PoSBlockSummary
Definition: block.h:17
CheckPoAblockTime
bool CheckPoAblockTime(const CBlock &block)
Definition: poa.cpp:422
poa.h
CBlockHeader::hashPrevBlock
uint256 hashPrevBlock
Definition: block.h:61
CBlock::vtx
std::vector< CTransaction > vtx
Definition: block.h:146
CBlock
Definition: block.h:142
GetBlockProof
uint256 GetBlockProof(const CBlockIndex &block)
Definition: poa.cpp:171
PoSBlockSummary::height
uint32_t height
Definition: block.h:21
main.h
GetNextWorkRequired
unsigned int GetNextWorkRequired(const CBlockIndex *pindexLast, const CBlockHeader *pblock)
Definition: poa.cpp:24
ReadBlockFromDisk
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos)
Definition: main.cpp:2101
PoSBlockSummary::hash
uint256 hash
Definition: block.h:19
CheckNumberOfAuditedPoSBlocks
bool CheckNumberOfAuditedPoSBlocks(const CBlock &block, const CBlockIndex *pindex)
Definition: poa.cpp:314
CBlockHeader::hashPrevPoABlock
uint256 hashPrevPoABlock
Definition: block.h:73
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:463
FindPrevPoSBlock
CBlockIndex * FindPrevPoSBlock(CBlockIndex *p)
Definition: poa.cpp:186
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:162
util.h
CheckPoABlockNotAuditingOverlap
bool CheckPoABlockNotAuditingOverlap(const CBlock &block)
Definition: poa.cpp:445
CheckPoAContainRecentHash
bool CheckPoAContainRecentHash(const CBlock &block)
Definition: poa.cpp:192
error
bool error(const char *fmt, const Args &... args)
Definition: util.h:61
CBlock::posBlocksAudited
std::vector< PoSBlockSummary > posBlocksAudited
Definition: block.h:149
mapBlockIndex
BlockMap mapBlockIndex
Definition: main.cpp:67
CChainParams::TargetSpacing
int64_t TargetSpacing() const
Definition: chainparams.h:83
CChainParams::SoftFork
int SoftFork() const
Definition: chainparams.h:113