Skip to content

Consider work instead of height when informing BTC headers to the Bridge - #675

Merged
marcos-iov merged 6 commits into
VETIVER-9.0.4-rcfrom
fix/consider-work-instead-of-height
Sep 3, 2026
Merged

marcos-iov merged 6 commits into
VETIVER-9.0.4-rcfrom
fix/consider-work-instead-of-height

Conversation

@marcos-iov

@marcos-iov marcos-iov commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

This pull request introduces significant improvements to the logic for updating the Bridge's view of the Bitcoin blockchain, ensuring correctness by comparing cumulative work rather than just block height. It also renames several methods and variables for clarity and consistency, and adds new methods to retrieve Bitcoin block headers from the Bridge. The update includes changes to both production and test code, as well as a dependency and version bump.

Bridge Update Logic and Consistency Improvements:

  • Modified the logic in BtcToRskClient to update the Bridge's Bitcoin blockchain only if the federator's chain has more cumulative work than the Bridge's, rather than relying solely on block height. This includes a new method calculateBridgeBitcoinChainWork to calculate the Bridge's cumulative work above the common ancestor. [1] [2]
  • Changed method and variable names for clarity: replaced amountOfHeadersToSend with maxAmountOfHeadersToSend, and renamed various getBtcBlockchain* methods to getBridgeBtcBlockchain* to better reflect their purpose. [1] [2] [3] [4] [5] [6] [7] [8]

Bridge Header Retrieval Enhancements:

  • Added new methods in FederatorSupport to retrieve the Bridge's best block header and parent block header by hash, and updated the logic in BtcToRskClient to use these methods for accurate work calculation. [1] [2]

Testing Improvements:

  • Added comprehensive unit tests for the new header retrieval methods in FederatorSupportTest, ensuring correct behavior for both normal and edge cases.

Dependency and Version Updates:

  • Updated the rskj-core dependency from 9.0.3-VETIVER to 9.0.4-VETIVER in gradle/verification-metadata.xml.
  • Changed the project version in version.properties to 9.0.4.0 VETIVER.

Mock and Test Code Consistency:

  • Updated SimpleFederatorSupport and related test code to match the new method names and logic, ensuring test reliability and clarity. [1] [2] [3]

These changes collectively improve the correctness, maintainability, and clarity of the codebase regarding Bridge synchronization and its interaction with the Bitcoin blockchain.

rit:tbd1000

@marcos-iov
marcos-iov requested a review from a team as a code owner September 2, 2026 21:16
Copilot AI balanced review requested due to automatic review settings September 2, 2026 21:16
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Bridge work traversal is unbounded, and equal-work behavior lacks test coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates Bitcoin header synchronization to compare cumulative chain work rather than block height.

Changes:

  • Adds Bridge header retrieval and work comparison.
  • Renames Bridge-specific APIs and updates tests/mocks.
  • Updates RSKj and project versions to 9.0.4 VETIVER.
File summaries
File Description
src/test/java/co/rsk/federate/mock/SimpleFederatorSupport.java Updates the test support implementation.
src/test/java/co/rsk/federate/log/FederateLoggerTest.java Updates renamed API usage.
src/test/java/co/rsk/federate/FederatorSupportTest.java Tests Bridge header retrieval.
src/test/java/co/rsk/federate/BtcToRskClientTest.java Tests work-based synchronization.
src/main/resources/version.properties Updates the VETIVER version.
src/main/java/co/rsk/federate/log/FederateLogger.java Uses the renamed height API.
src/main/java/co/rsk/federate/FederatorSupport.java Adds Bridge header retrieval APIs.
src/main/java/co/rsk/federate/BtcToRskClient.java Implements work-based header synchronization.
gradle/verification-metadata.xml Updates dependency verification metadata.
build.gradle Updates the RSKj dependency.
Review details

Suppressed comments (1)

src/main/java/co/rsk/federate/BtcToRskClient.java:431

  • This branch also runs when both chains have equal cumulative work, so the warning incorrectly states that the Bridge has more work. Use “at least as much work” to keep operational diagnostics accurate during a tie.
            logger.warn("[updateBridgeBtcBlockchain] Bridge has more work than Federator, so we won't update it.");
  • Files reviewed: 9/10 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

BigInteger bridgeBitcoinChainWork = calculateBridgeBitcoinChainWork(commonAncestor);
BigInteger bitcoinBestChainWork = bitcoinChainHead.getChainWork();
// Compare total cumulative work
boolean shouldUpdateBridge = bitcoinBestChainWork.compareTo(bridgeBitcoinChainWork) > 0;
Comment on lines +472 to +473
byte[] parentPayloadBytes = federatorSupport.getBridgeBtcBlockchainParentBlockHeaderByHash(currentHeader.getHash());
currentHeader = new Block(params, parentPayloadBytes);
@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2026

Copy link
Copy Markdown

@marcos-iov
marcos-iov merged commit 3dc1d16 into VETIVER-9.0.4-rc Sep 3, 2026
13 of 16 checks passed
@marcos-iov
marcos-iov deleted the fix/consider-work-instead-of-height branch September 3, 2026 12:27
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