Skip to content

Update blocks informing logic - #638

Merged
marcos-iov merged 6 commits into
cleanup-update-bridge-testsfrom
update-blocks-informing-logic
Jul 21, 2026
Merged

marcos-iov merged 6 commits into
cleanup-update-bridge-testsfrom
update-blocks-informing-logic

Conversation

@julia-zack

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

github-actions Bot commented Jul 16, 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.

Pull request overview

This PR updates the PowPeg node’s “inform BTC headers to the Bridge” flow so that subsequent receiveHeaders calls avoid re-sending headers the Bridge already knows, improving behavior across forks and repeated update cycles.

Changes:

  • Adjust BtcToRskClient.updateBridgeBtcBlockchain() to skip headers already known by the Bridge (via isBlockHashInformedToBridge) and send only the next missing batch.
  • Extend test mocks (SimpleFederatorSupport) to track “known” headers via both the registered chain and prior sendReceiveHeaders calls.
  • Update/extend tests to validate deep-fork behavior and successive update calls that progressively inform the remaining headers.

Reviewed changes

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

File Description
src/main/java/co/rsk/federate/BtcToRskClient.java Adds logic to find the first unknown header and only inform missing headers to the Bridge.
src/test/java/co/rsk/federate/BtcToRskClientTest.java Updates deep-fork expectations and adds a test covering repeated calls informing headers in batches.
src/test/java/co/rsk/federate/mock/SimpleFederatorSupport.java Implements isBlockHashInformedToBridge in the test support to reflect Bridge-known header behavior.

@julia-zack
julia-zack force-pushed the update-blocks-informing-logic branch from 83aba1d to fcde92e Compare July 16, 2026 19:18
@julia-zack
julia-zack changed the base branch from VETIVER-9.0.3-rc to master July 16, 2026 19:19
@julia-zack
julia-zack changed the base branch from master to headers-informing-logic-integration July 16, 2026 19:25
@julia-zack
julia-zack marked this pull request as ready for review July 16, 2026 19:25
@julia-zack
julia-zack requested a review from a team as a code owner July 16, 2026 19:25
Copilot AI review requested due to automatic review settings July 16, 2026 19:25

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.

Copilot AI review requested due to automatic review settings July 16, 2026 19:35
@julia-zack
julia-zack force-pushed the update-blocks-informing-logic branch from 62ae86c to a20b483 Compare July 16, 2026 19:35

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.


boolean shouldUpdateBridge = federatorBtcBlockchainBestChainHeight > bridgeBtcBlockchainBestChainHeight;
if (!shouldUpdateBridge) {
return 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe log here? "Bridge is already up to date with BTC best chain {}", height

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Or even better, move the log from below to before this if

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good one, added: 2c360dd

totalHeadersToSendToBridge.add(currentBlockHeader);
currentBlock = bitcoinWrapper.getBlock(currentBlockHeader.getPrevBlockHash());
}
if (totalHeadersToSendToBridge.isEmpty()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I understand this could never happen, it was already checked above. As long as we have a test that covers the case where there are no blocks to inform to the Bridge it's probably safe to remove this.

// Only send the headers that are not already known to the Bridge
int startIndex = findFirstUnknownHeader(totalHeadersToSendToBridge);
int totalHeadersToSendToBridgeCount = totalHeadersToSendToBridge.size();
if (startIndex == totalHeadersToSendToBridgeCount) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same here I believe, or is there a case I'm missing?

Copilot AI review requested due to automatic review settings July 16, 2026 21:44

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 1 comment.

Comment on lines +3939 to +3947
Federation federation = TestUtils.createP2shP2wshErpFederation(MAINNET_BTC_PARAMS, 20);
setUpActiveFedClient(federation);

// the Bridge has maxAmountOfHeadersToSend headers informed past the common ancestor,
// meaning we have chainHeight - lastInformedHeader = 130 headers to inform.
markHeadersAsInformed(1, lastInformedHeader);
int firstCallFirstHeaderToSend = lastInformedHeader + 1;
markHeadersAsNotInformed(firstCallFirstHeaderToSend, chainHeight);

Copilot AI review requested due to automatic review settings July 17, 2026 14:46
@julia-zack
julia-zack force-pushed the update-blocks-informing-logic branch from 2c360dd to 8c9b243 Compare July 17, 2026 14:46
@julia-zack
julia-zack changed the base branch from headers-informing-logic-integration to cleanup-update-bridge-tests July 17, 2026 14:46

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.

Copilot AI review requested due to automatic review settings July 17, 2026 14:58
@julia-zack
julia-zack force-pushed the update-blocks-informing-logic branch from 8c9b243 to c3db5d0 Compare July 17, 2026 14:58
Comment on lines +3886 to +3889
private CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) throws IOException {
return btcToRskActiveFedClientFileStorage.read(MAINNET_PARAMS).getData().getCoinbaseInformationMap().get(blockHash);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

just moved from below

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 1 comment.

Copilot AI review requested due to automatic review settings July 17, 2026 16:02
@julia-zack
julia-zack force-pushed the update-blocks-informing-logic branch from 1f41c29 to b1d8ae7 Compare July 17, 2026 16:02
@julia-zack
julia-zack force-pushed the update-blocks-informing-logic branch from b1d8ae7 to 2f008dd Compare July 17, 2026 16:05

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 1 comment.

Comment on lines +3920 to +3925
// the Bridge has maxAmountOfHeadersToSend headers informed past the common ancestor,
// meaning we have chainHeight - lastInformedHeader = 130 headers to inform.
markHeadersAsInformed(1, lastInformedHeader);
int firstCallFirstHeaderToSend = lastInformedHeader + 1;
markHeadersAsNotInformed(firstCallFirstHeaderToSend, chainHeight);

Copilot AI review requested due to automatic review settings July 17, 2026 16:06

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 1 comment.

Comment on lines +3909 to +3911
int chainHeight = 230;
int maxAmountOfHeadersToSend = 100; // builder default
int lastInformedHeader = 100;
Copilot AI review requested due to automatic review settings July 17, 2026 16:55

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 1 comment.


// setup fed best chain
int chainHeight = 230;
int maxAmountOfHeadersToSend = 100; // builder default
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI review requested due to automatic review settings July 21, 2026 14:27
@marcos-iov
marcos-iov force-pushed the update-blocks-informing-logic branch 2 times, most recently from 757e8d9 to 20e0c7d Compare July 21, 2026 14:27
@marcos-iov
marcos-iov merged commit 014bcf4 into cleanup-update-bridge-tests Jul 21, 2026
5 checks passed
@marcos-iov
marcos-iov deleted the update-blocks-informing-logic branch July 21, 2026 14: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 no new comments.

Comments suppressed due to low confidence (1)

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

  • amountOfHeadersToSend is read directly from config with no validation. If it is configured as 0 (or negative), to becomes from, resulting in an empty headersToSendToBridge list. That leads to calling sendReceiveHeaders with an empty array (which dereferences headers[0] in FederatorSupport.sendReceiveHeaders) and also throws here when logging headersToSendToBridge.get(0)/get(size-1).
        int to = Math.min(from + amountOfHeadersToSend, totalHeadersToSendToBridge.size());
        List<Block> headersToSendToBridge = totalHeadersToSendToBridge.subList(from, to);
        federatorSupport.sendReceiveHeaders(headersToSendToBridge.toArray(new Block[]{}));

@julia-zack
julia-zack restored the update-blocks-informing-logic branch July 22, 2026 18:15
@julia-zack
julia-zack deleted the update-blocks-informing-logic branch July 22, 2026 22:16
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