Skip to content

Headers informing logic integration - #651

Open
julia-zack wants to merge 15 commits into
masterfrom
headers-informing-logic-integration
Open

Headers informing logic integration#651
julia-zack wants to merge 15 commits into
masterfrom
headers-informing-logic-integration

Conversation

@julia-zack

@julia-zack julia-zack commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Federators inform the RSK Bridge of new BTC block headers via updateBridgeBtcBlockchain(). The old logic always started from the common ancestor and re-sent the first N headers, so it could keep re-submitting headers the Bridge already had and never advance.

Changes:

  • Add findFirstUnknownHeader() — binary search over isBlockHashInformedToBridge — and inform only headers from that index onward.
  • Cleanup: remove duplicate isUpdateBridgeTimerEnabled assignment, drop unused IOException from the signature, logging tweaks.

Testing:

  • Unit tests in BtcToRskClientTest (nested UpdateBridge classes), including successive-informing and fork scenarios.
  • Test restructuring into nested classes + new coverage (successive-call informing until fully synced, long-fork scenario).

@julia-zack
julia-zack requested a review from Copilot July 22, 2026 17:23
@github-actions

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.

Pull request overview

This PR updates the PowPeg node’s BTC-header synchronization logic so the federator informs the Bridge only about BTC block headers that the Bridge does not already have, and refactors/extends the test suite to validate the new behavior (including fork/deep-fork cases and updateBridge flow behavior).

Changes:

  • Update BtcToRskClient.updateBridgeBtcBlockchain() to skip already-known headers by querying the Bridge (isBlockHashInformedToBridge) and sending only the remaining unknown suffix (with a binary search helper).
  • Add mock support for isBlockHashInformedToBridge in SimpleFederatorSupport to model “known to Bridge” headers across both the Bridge-registered chain and previously sendReceiveHeaders-informed headers.
  • Restructure and expand BtcToRskClientTest to reflect the new header-informing behavior and to better isolate updateBridge sub-behaviors (blockchain/coinbase/txs/collections).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/main/java/co/rsk/federate/BtcToRskClient.java Changes header sync to send only headers not already known by the Bridge; adds binary-search helper; removes duplicate config assignment and unused import.
src/test/java/co/rsk/federate/mock/SimpleFederatorSupport.java Implements isBlockHashInformedToBridge for test scenarios by checking Bridge chain hashes and previously informed headers.
src/test/java/co/rsk/federate/BtcToRskClientTest.java Updates expectations for deep-fork header informing, refactors nested tests, and adds/adjusts coverage for updateBridge control-flow and storage failure behavior.

@julia-zack
julia-zack force-pushed the headers-informing-logic-integration branch from d150f84 to d4f5b1e Compare July 22, 2026 22:06
@julia-zack
julia-zack requested a review from Copilot July 22, 2026 22:07

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@julia-zack
julia-zack force-pushed the headers-informing-logic-integration branch from d4f5b1e to 94e53c5 Compare July 23, 2026 15:21
@julia-zack
julia-zack requested a review from Copilot July 23, 2026 15:29

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread src/test/java/co/rsk/federate/BtcToRskClientTest.java Outdated
Comment thread src/test/java/co/rsk/federate/BtcToRskClientTest.java
@julia-zack
julia-zack requested a review from Copilot July 23, 2026 15:38
@julia-zack
julia-zack marked this pull request as ready for review July 23, 2026 15:41
@julia-zack
julia-zack requested a review from a team as a code owner July 23, 2026 15:41

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/test/java/co/rsk/federate/BtcToRskClientTest.java:4055

  • This helper also uses height/array indexes (blocks[depth]) rather than blockchain depth. Renaming parameters/locals to fromHeight/toHeight and height improves readability and prevents mixing up "height" vs "depth" in later test edits.
        private void markHeadersAsInformed(int fromDepth, int toDepth) {
            for (int depth = fromDepth; depth <= toDepth; depth++) {
                Sha256Hash blockHash = blocks[depth].getHeader().getHash();
                when(federatorSupport.isBlockHashInformedToBridge(blockHash)).thenReturn(true);
            }

Comment thread src/main/java/co/rsk/federate/BtcToRskClient.java
Comment thread src/test/java/co/rsk/federate/BtcToRskClientTest.java Outdated
Copilot AI review requested due to automatic review settings July 23, 2026 16:48
@julia-zack
julia-zack force-pushed the headers-informing-logic-integration branch from 052106e to 36be0fe Compare July 23, 2026 16:48
@julia-zack
julia-zack force-pushed the headers-informing-logic-integration branch from 36be0fe to 9ab366b Compare July 23, 2026 16:49

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 23, 2026 16:52

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@sonarqubecloud

Copy link
Copy Markdown

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