doc: Improve versionbits.h documentation #16587

pull ariard wants to merge 1 commits into bitcoin:master from ariard:2019-08-docs-versionbits changing 2 files +22 −7
  1. ariard commented at 1:58 PM on August 12, 2019: member

    While reviewing burying of BIP 9 deployments, seen that versionbits.h wasn't that much documented. This is an attempt to improve it. It can be useful, given after burying this code isn't going to be used anymore and isn't straightforward at first sight.

  2. fanquake added the label Docs on Aug 12, 2019
  3. emilengler commented at 7:22 PM on August 12, 2019: contributor

    I like it but I NACK about the change in the header file. Why do you remove this comment?

  4. ariard commented at 9:57 PM on August 12, 2019: member

    @emilengler "Note that the functions below take a pindexPrev as input: they compute information for block B based on its parent." you mean this one ? I've tried to incorporate it in both GetStateFor and GetStateSinceHeightFor ones but should I make it clearer?

  5. in src/versionbits.h:65 in bcc2a0f45c outdated
      61 | @@ -50,12 +62,17 @@ class AbstractThresholdConditionChecker {
      62 |      virtual int Threshold(const Consensus::Params& params) const =0;
      63 |  
      64 |  public:
      65 | +    /** Returns the numerical statistics of an in-progess BIP9 softfork in the current period */
    


    practicalswift commented at 7:36 AM on August 14, 2019:

    Should be "in-progress" :-)

  6. fanquake added the label Waiting for author on Aug 14, 2019
  7. in src/versionbits.h:26 in bcc2a0f45c outdated
      27 | -    DEFINED,
      28 | -    STARTED,
      29 | -    LOCKED_IN,
      30 | -    ACTIVE,
      31 | -    FAILED,
      32 | +    DEFINED,   // First state that each softfork starts out as. The genesis block is by definition in this state for each deployment.
    


    fanquake commented at 8:52 AM on August 14, 2019:

    These match the States definitions in BIP9 👍

  8. in src/versionbits.h:74 in bcc2a0f45c outdated
      70 |      ThresholdState GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
      71 | +    /** Returns the height since when the ThresholdState has started for pindex A based on parent pindexPrev B, all blocks of a period share the same */
      72 |      int GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const;
      73 |  };
      74 |  
      75 | +/** BIP 9 allows multiple softforks being deployed in parallel. We cache per-period state for every one of them
    


    fanquake commented at 8:53 AM on August 14, 2019:
    /** BIP 9 allows multiple softforks to be deployed in parallel. We cache per-period state for every one of them
    
  9. fanquake commented at 8:55 AM on August 14, 2019: member

    Concept ACK. Thanks for writing more documentation. @jnewbery or @ajtowns might want to take a look here, given they have been recently doing some BIP9 related stuff.

  10. laanwj commented at 12:48 PM on August 14, 2019: member

    ACK, thanks for adding documentation

    Why do you remove this comment?

    The comment is moved from the cpp to the header file, where it should be. Public functions should be documented at declaration and not at the implementation as this keeps the API documentation better together.

  11. in src/versionbits.h:21 in bcc2a0f45c outdated
      16 | @@ -17,24 +17,36 @@ static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
      17 |  /** Total bits available for versionbits */
      18 |  static const int32_t VERSIONBITS_NUM_BITS = 29;
      19 |  
      20 | +/** BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
      21 | + *  It relies on the chain being a monotonic clock to start or timeout the
    


    jnewbery commented at 2:30 PM on August 14, 2019:

    nit: drop the part about 'a monotonic clock', since it's confusing. The chain is not monotonic (timestamps of blocks may precede their ancestors' timestamps). Besides, BIP 9 doesn't have any dependence on clock time.


    ariard commented at 5:57 PM on August 14, 2019:

    Sorry was thinking in MTP. "The expression GetMedianTimePast(block.parent) is referred to as MTP in the diagram above, and is treated as a monotonic clock defined by the chain." In the context of Median-Time-Past, I think BIP 9 envision the chain as a monotonic counter. Further, softfork timeout doesn't rely on it ? (dropped it anyway, maybe too much)

  12. in src/versionbits.h:68 in bcc2a0f45c outdated
      61 | @@ -50,12 +62,17 @@ class AbstractThresholdConditionChecker {
      62 |      virtual int Threshold(const Consensus::Params& params) const =0;
      63 |  
      64 |  public:
      65 | +    /** Returns the numerical statistics of an in-progess BIP9 softfork in the current period */
      66 |      BIP9Stats GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const;
      67 | -    // Note that the functions below take a pindexPrev as input: they compute information for block B based on its parent.
      68 | +    /** Returns the state for pindex A based on parent pindexPrev B. Applies any state transition if conditions are present.
      69 | +     *  Caches state for first block of period. */
    


    jnewbery commented at 2:31 PM on August 14, 2019:

    s/Caches state for/Caches state from/

  13. jnewbery commented at 2:32 PM on August 14, 2019: member

    Concept ACK. Thanks for adding documentation.

    A couple of nits inline.

  14. ariard force-pushed on Aug 14, 2019
  15. ariard commented at 5:58 PM on August 14, 2019: member

    Updated at 001b58b with typos and corrections, thanks all for reviews

  16. in src/versionbits.h:30 in 001b58b204 outdated
      30 | -    FAILED,
      31 | +    DEFINED,   // First state that each softfork starts out as. The genesis block is by definition in this state for each deployment.
      32 | +    STARTED,   // For blocks past the starttime.
      33 | +    LOCKED_IN, // For one retarget period after the first retarget period with STARTED blocks of which at least threshold have the associated bit set in nVersion.
      34 | +    ACTIVE,    // For all blocks after the LOCKED_IN retarget period (final state)
      35 | +    FAILED,    // For one retarget period past the timeout time, if LOCKED_IN was not reached (final state)
    


    ajtowns commented at 8:57 AM on August 15, 2019:

    The FAILED description there is verbatim from BIP-9 but it's nevertheless not accurate -- it'll be all blocks once the first retarget period after the timeout time is reached, if LOCKED_IN wasn't already reached.

  17. ajtowns commented at 9:00 AM on August 15, 2019: member

    This seems mostly fine to me

  18. jnewbery commented at 2:23 PM on August 15, 2019: member

    ACK 001b58b20413f692166aca19c8f21cab64b2a09a after @ajtowns's nit is addressed.

  19. doc: Improve versionbits.h documentation 6576a8765f
  20. ariard force-pushed on Aug 15, 2019
  21. ariard commented at 3:05 PM on August 15, 2019: member

    Updated at 6576a87 with @ajtowns comment addressed.

  22. jnewbery commented at 3:25 PM on August 15, 2019: member

    ACK 6576a8765f67716aa6b87a2f0296fbac5956bec0

  23. fanquake removed the label Waiting for author on Aug 16, 2019
  24. ajtowns commented at 2:45 AM on August 16, 2019: member

    ACK 6576a8765f67716aa6b87a2f0296fbac5956bec0

  25. fanquake approved
  26. fanquake commented at 2:51 AM on August 16, 2019: member

    ACK 6576a8765f67716aa6b87a2f0296fbac5956bec0

    Thanks for following up @ajtowns and @jnewbery.

    This is a doc only change, and the Travis failures here are unrelated.

  27. fanquake merged this on Aug 16, 2019
  28. fanquake closed this on Aug 16, 2019

  29. fanquake referenced this in commit 95a5918c90 on Aug 16, 2019
  30. vijaydasmp referenced this in commit a26c281600 on Oct 27, 2021
  31. vijaydasmp referenced this in commit f4e1cd7b84 on Oct 28, 2021
  32. vijaydasmp referenced this in commit 7c8065e80c on Oct 29, 2021
  33. vijaydasmp referenced this in commit ee10392e33 on Oct 30, 2021
  34. vijaydasmp referenced this in commit 6d467c2961 on Nov 2, 2021
  35. vijaydasmp referenced this in commit ff8c57ab8d on Nov 7, 2021
  36. vijaydasmp referenced this in commit bbe16c5ccd on Nov 11, 2021
  37. vijaydasmp referenced this in commit 73416a54fb on Nov 12, 2021
  38. vijaydasmp referenced this in commit 69117a978f on Nov 13, 2021
  39. vijaydasmp referenced this in commit 218b4563d9 on Nov 14, 2021
  40. vijaydasmp referenced this in commit df47d96104 on Nov 14, 2021
  41. vijaydasmp referenced this in commit 4bf93d833e on Nov 16, 2021
  42. DrahtBot locked this on Dec 16, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 18:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me