Skip to content

Conversation

@roman98Z
Copy link

@roman98Z roman98Z commented Dec 21, 2025

Fix issue #548 and improve version validation for issue #597

Summary

This PR addresses two important issues in the midnight-indexer:

  1. Fix Different author values in blocks table when running Indexer on two identical servers #548: Resolves inconsistent block author values when indexers start from different block heights
  2. Improve Is /api/v3/graphql available? Getting 404 on all v3 endpoints, unable to query dustGenerationStatus. #597: Adds version validation and comprehensive documentation to prevent API endpoint 404 errors

Both changes improve reliability and user experience without breaking backward compatibility.


Issue #548: Different Author Values in Blocks Table

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

Issue #597: API v3 Endpoint 404

Problem

Users were getting 404 errors on /api/v3/graphql endpoint due to version incompatibilities when using the latest tag for Docker images. This led to confusion and difficult-to-debug configuration issues.

Root Cause

Using latest tags resulted in:

  • Mismatched versions between Midnight Node and Indexer components
  • Incompatible API schemas (v1 vs v3)
  • No clear indication of what went wrong

Solution

Added comprehensive version validation and documentation:

  1. New Module: indexer-api/src/version_validator.rs

    • Validates component version compatibility
    • Logs detailed version information at startup
    • Warns about mismatches
  2. Documentation: VERSION_COMPATIBILITY.md

    • Explains version requirements
    • Provides correct configuration examples
    • Includes troubleshooting guide
  3. Startup Logging: Modified indexer-api/src/main.rs

    • Displays version information banner
    • Validates versions on startup
    • Warns users about potential issues

Changes

New Files:

  • indexer-api/src/version_validator.rs (252 lines)
  • VERSION_COMPATIBILITY.md (208 lines)

Modified Files:

  • indexer-api/src/lib.rs - Added version_validator module
  • indexer-api/src/main.rs - Integrated version validation

Startup Output

When the API starts, users now see:

╔════════════════════════════════════════════════════════════════════════════╗
║                    Midnight Indexer API Version Info                      ║
╠════════════════════════════════════════════════════════════════════════════╣
║  Indexer API Version:        3.0.0                                        ║
║  Expected Node Version:      0.18.0                                       ║
╠════════════════════════════════════════════════════════════════════════════╣
║  IMPORTANT: All Indexer components must use the SAME version:             ║
║    - chain-indexer:3.0.0                                                  ║
║    - wallet-indexer:3.0.0                                                 ║
║    - indexer-api:3.0.0                                                    ║
║                                                                            ║
║  NEVER use 'latest' tag in production - always specify exact versions!    ║
╚════════════════════════════════════════════════════════════════════════════╝

Impact

Performance

Backward Compatibility

  • ✅ Both changes are fully backward compatible
  • ✅ No database migrations required
  • ✅ No breaking API changes

User Experience

  • ✅ Consistent block author values across all indexers
  • ✅ Clear version information at startup
  • ✅ Better error messages and documentation
  • ✅ Reduced configuration errors

Testing Checklist

  • Code compiles without errors
  • Changes are well-documented in code comments
  • Comprehensive documentation added
  • Tested with indexers starting from different heights (recommended)
  • Tested with version mismatches (recommended)
  • Verified API v3 endpoints are accessible

Related Issues


Additional Notes

For Reviewers

  1. Issue Different author values in blocks table when running Indexer on two identical servers #548: The key change is in make_block() function. Please verify the logic ensures authorities are always fetched from the correct block.

  2. Issue Is /api/v3/graphql available? Getting 404 on all v3 endpoints, unable to query dustGenerationStatus. #597: The version validator module includes unit tests. Consider extending it in the future to query actual component versions.

  3. Documentation: The VERSION_COMPATIBILITY.md file should be linked from the main README for better visibility.

Future Enhancements

  • Add health check endpoint that exposes component versions
  • Implement automatic version querying from connected components
  • Add version compatibility matrix to the API documentation

Commit Message

fix: resolve issue #548 and improve version validation for issue #597

- Fix #548: Always fetch authorities from specific block for consistency
  * Modified chain-indexer/src/infra/subxt_node.rs to fetch authorities
    for each block instead of caching them across sessions
  * This ensures consistent author values regardless of indexer start point
  * Prevents discrepancies when indexers start from different block heights

- Improve #597: Add version validation and documentation
  * Created indexer-api/src/version_validator.rs module
  * Added version compatibility logging at API startup
  * Created VERSION_COMPATIBILITY.md with comprehensive documentation
  * Warns users about version mismatches to prevent 404 errors on v3 endpoints

Both changes are backward compatible and improve reliability.

…or issue midnightntwrk#597

- Fix midnightntwrk#548: Always fetch authorities from specific block for consistency
  * Modified chain-indexer/src/infra/subxt_node.rs to fetch authorities
    for each block instead of caching them across sessions
  * This ensures consistent author values regardless of indexer start point
  * Prevents discrepancies when indexers start from different block heights

- Improve midnightntwrk#597: Add version validation and documentation
  * Created indexer-api/src/version_validator.rs module
  * Added version compatibility logging at API startup
  * Created VERSION_COMPATIBILITY.md with comprehensive documentation
  * Warns users about version mismatches to prevent 404 errors on v3 endpoints

Both changes are backward compatible and improve reliability.
@roman98Z roman98Z requested a review from a team as a code owner December 21, 2025 15:28
@CLAassistant
Copy link

CLAassistant commented Dec 21, 2025

CLA assistant check
All committers have signed the CLA.

@roman98Z
Copy link
Author

Hi team! 👋

This PR fixes issues #548 and #597 as described in the PR description.

Could a maintainer please approve the workflows so the CI checks can run?

Thank you for your time and review! 🙏

@hseeberger
Copy link
Collaborator

Hi @roman98Z, thanks a lot for your contribution. At first glance both look reasonable, but the part for #597 might need some changes, because going forward the Indexer will support multiple Node (and Ledger) versions. Therefore may I suggest to split the PR into two, one for #548 and one for #597?

@roman98Z
Copy link
Author

Hi @hseeberger! 👋

Thank you for the feedback! I've split the PR as suggested:

PR #618 - Fix for issue #548 only (block author consistency)

Thanks again for the review! 🙏

@hseeberger
Copy link
Collaborator

@roman98Z , thanks for splitting! Very much appreciated.
As most of the team in on holiday, this will take some time, but we will certainly get back to you.

@roman98Z
Copy link
Author

@hseeberger Also, if there are any other issues or bugs in the Midnight ecosystem that need attention, I'd be happy to help!

Feel free to point me to:

Other open issues that need fixing
Code areas that need improvement
Documentation that needs updating
Testing or validation work
I'm available to contribute further to the project. Just let me know where I can be most helpful! 🚀

@hseeberger
Copy link
Collaborator

hseeberger commented Dec 23, 2025

The ultimate authority when it comes to version compatibility is the ProtocolVersion and related code in the Chain Indexer wrt Ledger and Node. There we get InvalidProtocolVersion errors which should be enough, no? Maybe together with the compatibility document you started, but with a table that has also ProtocolVersion (as the leading column).

I believe the new validations/log outputs are doomed to quickly outdate, because the only source of truth is ProtocolVersion.

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

3 participants