Skip to content

Make finality update cache for current period#36

Merged
yoshidan merged 10 commits intomainfrom
feature/cache_sync_committee
Feb 10, 2026
Merged

Make finality update cache for current period#36
yoshidan merged 10 commits intomainfrom
feature/cache_sync_committee

Conversation

@yoshidan
Copy link
Copy Markdown
Collaborator

@yoshidan yoshidan commented Feb 8, 2026

Summary

This PR adds period-aware caching for finalized L1 data to ensure consistency between preimage-maker and relayer during sync committee
updates.

Background

The relayer's GetSyncCommitteesFromClaimedToLatest function needs to use the same light client update data that was cached at the time of
derivation. Without this, there's a race condition where:

  1. preimage-maker derives with beacon API data at time T
  2. relayer fetches beacon API data at time T+1 (which may have different data for the current period)
  3. Verification fails due to data inconsistency

Changes

  • Add period field to FinalizedL1Data: Store the signature_slot-based period alongside the cached finality and light client updates
  • Cache light client update for the period: Fetch and store raw_light_client_update for the signature_slot's period via
    /eth/v1/beacon/light_client/updates?start_period={period}&count=1
  • Add period calculation utilities (client/period.rs): Beacon chain period calculation functions supporting both minimal and mainnet
    presets
  • Update BeaconClient trait: Add get_raw_light_client_update(period) and get_genesis() methods

API Response Change

GET /get_finalized_l1 now returns:
{
"raw_finality_update": {...},
"raw_light_client_update": {...},
"period": 1664
}

The relayer uses this period value as latestPeriod in GetSyncCommitteesFromClaimedToLatest and uses the cached raw_light_client_update as
the snapshot for that period.

Naohiro Yoshida added 4 commits February 8, 2026 12:00
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
@yoshidan yoshidan changed the base branch from feature/fixed_distance to main February 8, 2026 07:13
@yoshidan yoshidan changed the base branch from main to feature/fixed_distance February 8, 2026 07:13
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
@yoshidan yoshidan marked this pull request as draft February 8, 2026 23:38
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
@yoshidan yoshidan force-pushed the feature/cache_sync_committee branch from f3b1b1b to 18c23e5 Compare February 9, 2026 01:27
Naohiro Yoshida added 2 commits February 9, 2026 13:16
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
Base automatically changed from feature/fixed_distance to main February 9, 2026 11:43
@yoshidan yoshidan marked this pull request as ready for review February 9, 2026 11:43
Naohiro Yoshida added 2 commits February 9, 2026 20:44
Signed-off-by: Naohiro Yoshida <naohiro.yoshida@datachain.jp>
Comment thread server/src/collector.rs
/// - Failure to fetch or deserialize the finality update.
/// - Delayed finality L1 blocks.
/// - If a valid and up-to-date finalized block is found, it returns the L1 block's hash and raw response.
/// - Fetches the light client update for the period corresponding to the finalized slot.
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.

Suggested change
/// - Fetches the light client update for the period corresponding to the finalized slot.
/// - Fetches the light client update for the period corresponding to the signature slot.

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.

These are same period by #37

Comment on lines +113 to +122
#[derive(Debug, Clone, serde::Deserialize)]
pub struct LightClientUpdateResponse {
pub data: LightClientUpdate,
}

#[derive(Debug, Clone, serde::Deserialize)]
pub struct LightClientUpdate {
pub finalized_header: LightClientHeader,
pub sync_aggregate: SyncAggregate,
}
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.

AI says these structs are dead code, right?

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.

These type are used.

}

/// Computes the slot from a timestamp and genesis time.
/// Returns None if the timestamp is before genesis or not aligned to slot boundaries.
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.

Even for non-aligned timestamp, this implementation returns Some.

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.

Fixed by #37

@yoshidan yoshidan merged commit b1a6cb3 into main Feb 10, 2026
2 checks passed
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.

2 participants