Skip to content

fix: use sequential sub_dag_index instead of nonce for LeaderSchedule#520

Open
TanguyDeTaxis wants to merge 1 commit intoTelcoin-Association:mainfrom
TanguyDeTaxis:fix/subdag-index-epoch-persistence
Open

fix: use sequential sub_dag_index instead of nonce for LeaderSchedule#520
TanguyDeTaxis wants to merge 1 commit intoTelcoin-Association:mainfrom
TanguyDeTaxis:fix/subdag-index-epoch-persistence

Conversation

@TanguyDeTaxis
Copy link
Contributor

This commit fixes issue #472 where the LeaderSchedule was using the Certificate's nonce (epoch << 32 | round) instead of a sequential subdag index for reputation score calculations.

Changes:

  • Add sub_dag_index field to CommittedSubDag for sequential tracking
  • Replace leader.nonce() with state.next_sub_dag_index() in Bullshark
  • Remove the /2 division hack that was compensating for round-based indices
  • Persist sub_dag_index across epoch boundaries by recovering it from the global latest subdag before filtering by current epoch
  • Add test sub_dag_index_persists_across_epochs to verify the fix

The sequential index ensures that:

  • ReputationScores are recalculated at consistent intervals (every 60 commits)
  • final_of_schedule is triggered correctly regardless of epoch changes
  • LeaderSwapTable updates happen predictably

This commit fixes issue Telcoin-Association#472 where the LeaderSchedule was using the
Certificate's nonce (epoch << 32 | round) instead of a sequential
subdag index for reputation score calculations.

Changes:
- Add `sub_dag_index` field to CommittedSubDag for sequential tracking
- Replace `leader.nonce()` with `state.next_sub_dag_index()` in Bullshark
- Remove the `/2` division hack that was compensating for round-based indices
- Persist sub_dag_index across epoch boundaries by recovering it from the
  global latest subdag before filtering by current epoch
- Add test `sub_dag_index_persists_across_epochs` to verify the fix

The sequential index ensures that:
- ReputationScores are recalculated at consistent intervals (every 60 commits)
- final_of_schedule is triggered correctly regardless of epoch changes
- LeaderSwapTable updates happen predictably
Copy link
Contributor

@sstanfield sstanfield left a comment

Choose a reason for hiding this comment

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

I want to go over this one with Grant. That ticket was actually something we were not in total agreement on but had shelved (sorry, should have had a note in the issue). I removed the original sub dag index and just used the nonce since it was one less data field in the consensus "chain" and I think the nonce is good enough. Anyway now that you have implemented this that may resolve it... I also may be wrong about the nonce being good enough but it does grow per round it just will have large gaps per epoch.

/// Sequential index of this committed subdag (monotonically increasing).
/// This is a counter that increments by 1 for each commit, regardless of
/// which rounds are committed or skipped.
#[serde(default)] // Backward compatibility: 0 if absent
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fine but we have other changes coming that will be data incompatible so you probably don't need this. The next reset of devnet will likely not have compatible data. There are some small changes and some big ones, I am implementing static/pack file for the consensus data right now that cause the DB access to change at it's core.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries if this doesn't end up being the right approach - just close it if needed.

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.

bug: LeaderSchedule based on Certificate nonce instead of subdag index

2 participants