Skip to content

Conversation

@roman98Z
Copy link

Fix issue #548: Ensure consistent block author values

Summary

This PR fixes issue #548 where two indexers with identical configurations but starting from different block heights would produce different author values in the blocks table for the same blocks.

Fixes #548

Problem

When running two indexers with identical configurations but starting from different block heights, the author field in the blocks table would differ for the same blocks. This was caused by the indexer fetching authorities only when they were None, which meant indexers starting from different points would use different authority sets.

Root Cause

The indexer was caching authorities and only fetching them:

  • Initially (for the first block after the highest stored block)
  • On receiving a NewSession event

If Indexer A started from genesis and Indexer B started from block 250, they would fetch different initial authority sets, leading to different author calculations for the same blocks.

Solution

Modified chain-indexer/src/infra/subxt_node.rs to always fetch authorities from the specific block being indexed, ensuring that:

  • Each block uses the correct authorities for its session
  • Author values are consistent regardless of the indexer's starting point
  • The cache is still updated for optimization during real-time indexing

Changes

File: chain-indexer/src/infra/subxt_node.rs (lines 231-249)

// FIX #548: Always fetch authorities from the specific block to ensure consistency.
let block_authorities = runtimes::fetch_authorities(hash, protocol_version, online_client).await?;

let author = block_authorities
    .as_ref()
    .map(|authorities| extract_block_author(block.header(), authorities, protocol_version))
    .transpose()?
    .flatten();

// Update cached authorities if None (for optimization in real-time indexing)
if authorities.is_none() {
    *authorities = block_authorities;
}

Testing

To verify the fix:

  1. Run one indexer from genesis block
  2. Run another indexer from block 250
  3. Compare author values in the blocks table
  4. Values should now be identical

Impact

Performance

Minimal impact. Authorities are cached in the Node and fetched only when sessions change (~every 200 blocks).

Backward Compatibility

✅ Fully backward compatible
✅ No database migrations required
✅ No breaking API changes

User Experience

✅ Consistent block author values across all indexers
✅ Reliable data regardless of indexer starting point

Related Issues

… values

- Fix midnightntwrk#548: Always fetch authorities from specific block for consistency
- Ensures author values are identical regardless of indexer starting point
- Maintains cache optimization for real-time indexing
- Backward compatible, no breaking changes
@roman98Z roman98Z requested a review from a team as a code owner December 22, 2025 20:54
roman98Z added a commit to roman98Z/midnight-indexer that referenced this pull request Dec 22, 2025
@hseeberger
Copy link
Collaborator

Thanks, @roman98Z. Before diving into the details, please let me know if you could reproduce the issue with the current version of the Indexer? There was an issue some months/weeks ago that got fixed and now the authors should be correct. Notice that we (Indexer team) were told that the authorities from which the author is selected remain stable until a NewSession event and hence the current approach should be correct and seems preferrable over making an RPC call for each block.

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.

Different author values in blocks table when running Indexer on two identical servers

2 participants