Skip to content

Dont sign when advancing blockchain - #646

Draft
julia-zack wants to merge 2 commits into
masterfrom
dont-sign-when-advancing-blockchain
Draft

Dont sign when advancing blockchain#646
julia-zack wants to merge 2 commits into
masterfrom
dont-sign-when-advancing-blockchain

Conversation

@julia-zack

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

Copy link
Copy Markdown

Dependency Review

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

Scanned Files

None

@julia-zack
julia-zack force-pushed the dont-sign-when-advancing-blockchain branch from 63bc088 to e9ae098 Compare July 20, 2026 16:06
@rsksmart rsksmart deleted a comment from sonarqubecloud Bot Jul 20, 2026
@marcos-iov
marcos-iov force-pushed the update-blocks-informing-logic branch from 757e8d9 to 20e0c7d Compare July 21, 2026 14:27
Base automatically changed from update-blocks-informing-logic to cleanup-update-bridge-tests July 21, 2026 14:29
Base automatically changed from cleanup-update-bridge-tests to headers-informing-logic-integration July 22, 2026 16:56
@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 force-pushed the dont-sign-when-advancing-blockchain branch 2 times, most recently from 8a6b781 to d6ffdc2 Compare July 22, 2026 22:14
@julia-zack
julia-zack changed the base branch from headers-informing-logic-integration to fix/checkout-sonarqube July 23, 2026 15:18
Base automatically changed from fix/checkout-sonarqube to master July 23, 2026 15:18
@julia-zack
julia-zack force-pushed the dont-sign-when-advancing-blockchain branch from d6ffdc2 to ff76700 Compare July 23, 2026 15:18
@julia-zack
julia-zack force-pushed the dont-sign-when-advancing-blockchain branch from ff76700 to 0120e3e Compare August 10, 2026 16:50
logger.error(message, e);
} catch (HSMClientException | SignerMessageBuilderException | ReleaseRequirementsEnforcerException e) {
} catch (ReleaseRequirementsEnforcerException e) {
logger.info("[signRelease] {}", e.getMessage());

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.

differentiating RRE from log level (info instead of error)

@julia-zack
julia-zack force-pushed the dont-sign-when-advancing-blockchain branch 2 times, most recently from 1526687 to a76b4fb Compare August 10, 2026 17:00
@julia-zack
julia-zack requested a lite review from Copilot August 10, 2026 17:01
@julia-zack
julia-zack force-pushed the dont-sign-when-advancing-blockchain branch from a76b4fb to 73aa655 Compare August 10, 2026 17:02

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 tightens PowHSM release-signing behavior by enforcing “ancestor in position” requirements directly in ReleaseRequirementsEnforcer, and preventing signing when the HSM is busy updating its blockchain bookkeeping state (advance/update in progress). It also simplifies the requirements enforcement flow by removing the separate AncestorBlockUpdater component and renaming the HSM bookkeeping state getter for clarity.

Changes:

  • Refactor release requirements enforcement to use BlockStore + HSMBookkeepingClient directly, including explicit validation for “HSM in progress” and “target block not yet informed”.
  • Update BTC release signing to resolve and cache signer/HSM version during setup(), and to skip signing when requirements enforcement indicates the HSM is busy.
  • Rename HSMBookkeepingClient.getHSMPointer() to getPowHSMState() and update call sites and tests; remove AncestorBlockUpdater and its tests, replacing coverage with expanded ReleaseRequirementsEnforcerTest.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/main/java/co/rsk/federate/signing/hsm/requirements/ReleaseRequirementsEnforcer.java Moves ancestor-update logic and validations into the enforcer; now interacts with BlockStore + HSMBookkeepingClient directly.
src/main/java/co/rsk/federate/signing/hsm/requirements/AncestorBlockUpdater.java Deleted; functionality absorbed into ReleaseRequirementsEnforcer.
src/main/java/co/rsk/federate/signing/hsm/client/HSMBookkeepingClient.java Renames bookkeeping state getter to getPowHSMState().
src/main/java/co/rsk/federate/signing/hsm/advanceblockchain/HsmBookkeepingClientImpl.java Implements getPowHSMState() and updates internal validation to use it.
src/main/java/co/rsk/federate/signing/hsm/advanceblockchain/HSMBookkeepingService.java Switches bookkeeping state reads to getPowHSMState().
src/main/java/co/rsk/federate/signing/hsm/HSMClientException.java Narrows constructor visibility to protected for controlled subclassing.
src/main/java/co/rsk/federate/FedNodeRunner.java Updates wiring to construct ReleaseRequirementsEnforcer without AncestorBlockUpdater.
src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java Caches signer version during setup; skips signing when enforcer blocks due to HSM state; renames pegout readiness helper for inverted logic.
src/test/java/co/rsk/federate/signing/hsm/requirements/ReleaseRequirementsEnforcerTest.java Adds comprehensive tests for multiple PowHSM enforcement scenarios and ancestor update payload behavior.
src/test/java/co/rsk/federate/signing/hsm/requirements/AncestorBlockUpdaterTest.java Deleted along with AncestorBlockUpdater.
src/test/java/co/rsk/federate/signing/hsm/advanceblockchain/HSMBookkeepingServiceTest.java Updates tests to use getPowHSMState().
src/test/java/co/rsk/federate/signing/hsm/advanceblockchain/HsmBookkeepingClientImplTest.java Updates tests to use getPowHSMState().
src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java Adjusts setup stubbing to account for version resolution during BtcReleaseClient.setup().

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

@julia-zack
julia-zack force-pushed the dont-sign-when-advancing-blockchain branch from 73aa655 to b648847 Compare August 10, 2026 17:11
@sonarqubecloud

Copy link
Copy Markdown

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 13 out of 13 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/main/java/co/rsk/federate/signing/hsm/requirements/ReleaseRequirementsEnforcer.java:130

  • getHeadersToUpdateAncestor treats “starting point is current best block” as startingBlockNumber == targetBlockNumber, but that ignores forks at the same height. If the HSM best block is on a different branch with the same height, this will incorrectly send only the target header instead of failing fast (or building a verifiable path), potentially resulting in a bad update attempt and misleading logs.

Consider also requiring startingPoint.getHash().equals(targetBlock.getHash()) for this fast path; otherwise throw an HSMBlockchainBookkeepingRelatedException (chain mismatch) before calling updateAncestorBlock.

        if (startingBlockNumber == targetBlockNumber) {
            logger.trace(
                "[getHeadersToUpdateAncestor] Target block is current best block. " +
                    "Will update ancestor with target block header only"
            );

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.

2 participants