ZCash ZEC information - Source


SUBMITTED BY: Hobbyistpool

DATE: Nov. 3, 2016, 5:22 p.m.

FORMAT: Text only

SIZE: 3.4 kB

HITS: 515

  1. ZCASH Info
  2. https://www.worldcoinindex.com/coin/zcash
  3. https://www2.coinmine.pl/zec/index.php?page=dashboard
  4. https://github.com/zcash/zcash
  5. #include "chain.h"
  6. using namespace std;
  7. /**
  8. * CChain implementation
  9. */
  10. void CChain::SetTip(CBlockIndex *pindex) {
  11. if (pindex == NULL) {
  12. vChain.clear();
  13. return;
  14. }
  15. vChain.resize(pindex->nHeight + 1);
  16. while (pindex && vChain[pindex->nHeight] != pindex) {
  17. vChain[pindex->nHeight] = pindex;
  18. pindex = pindex->pprev;
  19. }
  20. }
  21. CBlockLocator CChain::GetLocator(const CBlockIndex *pindex) const {
  22. int nStep = 1;
  23. std::vector<uint256> vHave;
  24. vHave.reserve(32);
  25. if (!pindex)
  26. pindex = Tip();
  27. while (pindex) {
  28. vHave.push_back(pindex->GetBlockHash());
  29. // Stop when we have added the genesis block.
  30. if (pindex->nHeight == 0)
  31. break;
  32. // Exponentially larger steps back, plus the genesis block.
  33. int nHeight = std::max(pindex->nHeight - nStep, 0);
  34. if (Contains(pindex)) {
  35. // Use O(1) CChain index if possible.
  36. pindex = (*this)[nHeight];
  37. } else {
  38. // Otherwise, use O(log n) skiplist.
  39. pindex = pindex->GetAncestor(nHeight);
  40. }
  41. if (vHave.size() > 10)
  42. nStep *= 2;
  43. }
  44. return CBlockLocator(vHave);
  45. }
  46. const CBlockIndex *CChain::FindFork(const CBlockIndex *pindex) const {
  47. if (pindex->nHeight > Height())
  48. pindex = pindex->GetAncestor(Height());
  49. while (pindex && !Contains(pindex))
  50. pindex = pindex->pprev;
  51. return pindex;
  52. }
  53. /** Turn the lowest '1' bit in the binary representation of a number into a '0'. */
  54. int static inline InvertLowestOne(int n) { return n & (n - 1); }
  55. /** Compute what height to jump back to with the CBlockIndex::pskip pointer. */
  56. int static inline GetSkipHeight(int height) {
  57. if (height < 2)
  58. return 0;
  59. // Determine which height to jump back to. Any number strictly lower than height is acceptable,
  60. // but the following expression seems to perform well in simulations (max 110 steps to go back
  61. // up to 2**18 blocks).
  62. return (height & 1) ? InvertLowestOne(InvertLowestOne(height - 1)) + 1 : InvertLowestOne(height);
  63. }
  64. CBlockIndex* CBlockIndex::GetAncestor(int height)
  65. {
  66. if (height > nHeight || height < 0)
  67. return NULL;
  68. CBlockIndex* pindexWalk = this;
  69. int heightWalk = nHeight;
  70. while (heightWalk > height) {
  71. int heightSkip = GetSkipHeight(heightWalk);
  72. int heightSkipPrev = GetSkipHeight(heightWalk - 1);
  73. if (heightSkip == height ||
  74. (heightSkip > height && !(heightSkipPrev < heightSkip - 2 &&
  75. heightSkipPrev >= height))) {
  76. // Only follow pskip if pprev->pskip isn't better than pskip->pprev.
  77. pindexWalk = pindexWalk->pskip;
  78. heightWalk = heightSkip;
  79. } else {
  80. pindexWalk = pindexWalk->pprev;
  81. heightWalk--;
  82. }
  83. }
  84. return pindexWalk;
  85. }
  86. const CBlockIndex* CBlockIndex::GetAncestor(int height) const
  87. {
  88. return const_cast<CBlockIndex*>(this)->GetAncestor(height);
  89. }
  90. void CBlockIndex::BuildSkip()
  91. {
  92. if (pprev)
  93. pskip = pprev->GetAncestor(GetSkipHeight(nHeight));
  94. }

comments powered by Disqus