Skip to content

Decrease sensitivity of retargeting algorithm#3194

Open
raychu86 wants to merge 10 commits intostagingfrom
feat/update-anchor-time
Open

Decrease sensitivity of retargeting algorithm#3194
raychu86 wants to merge 10 commits intostagingfrom
feat/update-anchor-time

Conversation

@raychu86
Copy link
Copy Markdown
Collaborator

@raychu86 raychu86 commented Mar 18, 2026

Motivation

The retargeting algorithm for coinbase_target is sensitive to block time changes. A 30% increase in block time caused the coinbase target to drop abruptly and cascade downward. This PR decreases the sensitivity of the algorithm by increasing the anchor time from 25 to 35 seconds at ConsensusVersion::V14, which will:

  • Reduce the per-block target adjustment magnitude, making the coinbase target less volatile in response to block time fluctuations
  • Increase the half-life, meaning the target takes proportionally longer to halve or double (a sudden crash in prover participation will relieve difficulty pressure more gradually rather than causing a sharp drop)
  • Cause the coinbase_target to trend upward over time when block times are consistently below the anchor, as the larger anchor widens the gap between actual and expected block time

The coinbase reward algorithm does not change and still uses the original anchor time, which is now defined as REWARD_ANCHOR_TIME.

Implementation

This PR replaces N::ANCHOR_TIME with N::ANCHOR_TIMES, a versioned array following the same pattern as MAX_PROGRAM_SIZE and MAX_WRITES. The V15 entry sets the anchor time to 35 seconds (from 25 seconds), activating on ConsensusVersion::V15.

to_next_targets now accepts a ConsensusVersion as its first parameter and looks up the active anchor time to use for retargeting. ANCHOR_HEIGHT is preserved as a hardcoded V1 literal since it is used exclusively by coinbase_reward_v1, which occurs well before ConsensusVersion::V15.

Test Plan

Tests have been added to verify that the coinbase target retargeting direction and magnitude differ between V1 (25s) and V14 (35s) anchor times, that the halving point shifts proportionally, and that doubling takes more blocks under the larger anchor time.

Backwards compatibility

Existing behavior is unchanged before V15. The new anchor time is gated behind ConsensusVersion::V15.

@vicsn vicsn requested a review from ljedrz March 24, 2026 19:58
Comment on lines -405 to 406
N::ANCHOR_TIME,
N::ANCHOR_TIMES[0].1,
N::ANCHOR_HEIGHT,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the N::ANCHOR_HEIGHT be hardcoded instead? the N::ANCHOR_TIME is used in coinbase_reward_v2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention was to keep the rewards/emissions the same and only update the retargeting algorithm.

I agree this is confusing.

N::ANCHOR_HEIGHT shouldn't need changing because it's only relevant in coinbase_reward_v1 which is after the new anchor_time kicks in.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made in 717ad49

next_timestamp,
N::GENESIS_TIMESTAMP,
N::STARTING_SUPPLY,
N::ANCHOR_TIME,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Copy Markdown
Collaborator

@ljedrz ljedrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the other anchor parameter should be hardcoded in the calls to coinbase_reward, as it's the 6th argument that is used in coinbase_reward_v1, and the 5th one (currently hardcoded to the original value) in coinbase_reward_v2.

@raychu86 raychu86 changed the base branch from canary to staging April 3, 2026 21:05
@raychu86 raychu86 marked this pull request as ready for review April 3, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants