Consider work instead of height when informing BTC headers to the Bridge - #675
Merged
Merged
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Contributor
There was a problem hiding this comment.
🟡 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); |
|
julia-zack
approved these changes
Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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:
BtcToRskClientto 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 methodcalculateBridgeBitcoinChainWorkto calculate the Bridge's cumulative work above the common ancestor. [1] [2]amountOfHeadersToSendwithmaxAmountOfHeadersToSend, and renamed variousgetBtcBlockchain*methods togetBridgeBtcBlockchain*to better reflect their purpose. [1] [2] [3] [4] [5] [6] [7] [8]Bridge Header Retrieval Enhancements:
FederatorSupportto retrieve the Bridge's best block header and parent block header by hash, and updated the logic inBtcToRskClientto use these methods for accurate work calculation. [1] [2]Testing Improvements:
FederatorSupportTest, ensuring correct behavior for both normal and edge cases.Dependency and Version Updates:
rskj-coredependency from9.0.3-VETIVERto9.0.4-VETIVERingradle/verification-metadata.xml.version.propertiesto9.0.4.0 VETIVER.Mock and Test Code Consistency:
SimpleFederatorSupportand 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