Advertisement
Guest User

BIP 101 Max Block Size

a guest
Sep 2nd, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. uint64_t MaxBlockSize(uint64_t nBlockTimestamp, uint64_t nSizeForkActivationTime);
  5.  
  6. /** Maximum block size parameters */
  7. uint32_t nMaxSizePreFork = 1000*1000;
  8. uint64_t nEarliestSizeForkTime = 1452470400;
  9. uint32_t nSizeDoubleEpoch = 60*60*24*365*2;
  10. uint64_t nMaxSizeBase = 8*1000*1000;
  11. uint8_t nMaxSizeDoublings = 10;
  12. uint64_t nSizeForkGracePeriod = 60*60*24;
  13.  
  14. int main() {
  15. uint64_t blockTime=nEarliestSizeForkTime;
  16.  
  17. printf("blockTime,maxSize\n");
  18. for(int i=1;i<64;i++) {
  19. //MaxBlockSize( blockTime, nEarliestSizeForkTime );
  20. printf( "%llu,%llu\n", blockTime, MaxBlockSize( blockTime, nEarliestSizeForkTime ) );
  21. blockTime=blockTime+2592000; //add 30 days
  22. }
  23.  
  24.  
  25. }
  26.  
  27. uint64_t MaxBlockSize(uint64_t nBlockTimestamp, uint64_t nSizeForkActivationTime) {
  28. if (nBlockTimestamp < nEarliestSizeForkTime || nBlockTimestamp < nSizeForkActivationTime)
  29. return nMaxSizePreFork;
  30. if (nBlockTimestamp >= nEarliestSizeForkTime + nSizeDoubleEpoch * nMaxSizeDoublings)
  31. return nMaxSizeBase << nMaxSizeDoublings;
  32.  
  33. // Piecewise-linear-between-doublings growth. Calculated based on a fixed
  34. // timestamp and not the activation time so the maximum size is
  35. // predictable, and so the activation time can be completely removed in
  36. // a future version of this code after the fork is complete.
  37. uint64_t timeDelta = nBlockTimestamp - nEarliestSizeForkTime;
  38. uint64_t doublings = timeDelta / nSizeDoubleEpoch;
  39. uint64_t remain = timeDelta % nSizeDoubleEpoch;
  40. uint64_t interpolate = (nMaxSizeBase << doublings) * remain / nSizeDoubleEpoch;
  41. uint64_t nMaxSize = (nMaxSizeBase << doublings) + interpolate;
  42. // printf("%llu,%llu,%llu,%llu,%llu\n",timeDelta,doublings,remain,interpolate,nMaxSize);
  43. return nMaxSize;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement