-
Notifications
You must be signed in to change notification settings - Fork 23
Powpeg refactors integration #524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
… supported federation types(mulsisig and p2wsh). Update related tests accordingly
- Rename federation building methods - Standardize key mocking logic in test helpers
…ability and maintainability
…move unused tests
…d exception messages
…mVersion in tests
…nit test method names
96d5c5a to
983829c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request refactors the codebase to remove support for legacy HSM versions (V2 and V4), retaining only V1 and the latest V5. The changes consolidate federation construction logic, simplify test setup, and update references throughout the codebase to use a centralized helper for the latest HSM version.
- Removed HSMVersion V2 and V4 enum values and related version-specific logic
- Introduced
TestUtils.getLatestHsmVersion()helper method to centralize HSM version references in tests - Refactored
FederationProviderFromFederatorSupportto streamline federation construction with clearer error handling
Reviewed changes
Copilot reviewed 27 out of 27 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
TestUtils.java |
Added getLatestHsmVersion() helper and simplified createBlock() method signature |
ReleaseRequirementsEnforcerTest.java |
Updated to use centralized HSM version helper and consolidated test methods |
SignerMessageBuilderFactoryTest.java |
Simplified tests using the latest HSM version helper |
ReleaseCreationInformationGetterTest.java |
Updated block creation calls and HSM version references |
PowHSMSignerMessageTest.java |
Removed parameterized legacy tests and simplified remaining tests |
PowHSMSignerMessageBuilderTest.java |
Updated test names and removed HSMVersion parameters from method calls |
PowHSMSigningClientTest.java |
Updated to use latest HSM version and simplified test setup |
PowHSMSigningClientRskMstTest.java |
Updated version references to use centralized helper |
PowHSMSigningClientBtcTest.java |
Consolidated parameterized tests and removed version-specific logic |
HSMSigningClientV1Test.java |
Updated method name for clarity |
HSMSigningClientProviderTest.java |
Enhanced unsupported version testing with specific version cases |
HSMResponseHandlerBaseTest.java |
Updated test names to reflect PowHSM instead of version-specific references |
HsmBookkeepingClientImplTest.java |
Centralized setup and removed version-specific parameterization |
ConfirmedBlocksProviderTest.java |
Updated test names and removed legacy version comparison logic |
HSMVersionTest.java |
Removed tests for deleted enum values and their related methods |
FederationProviderFromFederatorSupportTest.java |
Major refactoring with new helper methods and improved test structure |
FedNodeRunnerTest.java |
Updated to use latest HSM version and removed legacy version configuration tests |
ReleaseRequirementsEnforcer.java |
Updated log message to refer to "Pow HSM" instead of "Version 2+" |
ReleaseCreationInformationGetter.java |
Renamed method to reflect PowHSM instead of version-specific naming |
PowHSMSignerMessage.java |
Removed version parameter from getMessageToSign() method |
PowHSMSigningClientBtc.java |
Updated to call getMessageToSign() without version parameter |
PowHSMSigningClient.java |
Simplified getPublicKey() logic and removed commented code |
HsmBookkeepingClientImpl.java |
Removed version-specific conditional logic for uncles and blockchain parameters |
ConfirmedBlocksProvider.java |
Removed version-specific uncle difficulty consideration logic |
HSMVersion.java |
Removed V2 and V4 enum values and their related methods |
HSMBlockchainBookkeepingRelatedException.java |
Updated documentation reference from "HSM 2" to "Pow HSM" |
FederationProviderFromFederatorSupport.java |
Refactored federation building logic with improved error handling and logging |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public static Block createBlock(List<Transaction> rskTxs) { | ||
| int blockNumber = 1; | ||
| int parentBlockNumber = 0; |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The createBlock method has been simplified but now hardcodes blockNumber to 1 and parentBlockNumber to 0. This removes flexibility that may be needed in tests requiring different block numbers. Consider keeping the block number as a parameter or document why this hardcoding is acceptable.
| public static Block createBlock(List<Transaction> rskTxs) { | |
| int blockNumber = 1; | |
| int parentBlockNumber = 0; | |
| public static Block createBlock(List<Transaction> rskTxs, int blockNumber, int parentBlockNumber) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, it is only being used with those values. What if we let this happen when the demand for it appears?
| String.format( | ||
| "Cannot determine federation type for federation with address %s. Tried: standard multiSig, and P2SH-P2WSH ERP federations.", | ||
| expectedFederationAddress |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected capitalization of 'multiSig' to 'multisig' for consistency with the codebase terminology.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also being used as multiSig in other places like co.rsk.peg.federation.FederationFactory#buildStandardMultiSigFederation. I think we can discuss it and agree on which one to use, and do the change as part of another task.
| Arguments.of( | ||
| activations, | ||
| createP2shErpFederation() | ||
| createNonStandardErpFederation() |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The method name createNonStandardErpFederation() is ambiguous. Based on the implementation, this appears to create a P2SH ERP federation (non-segwit). Consider renaming to createP2shErpFederationWithNonMatchingAddress() or similar to clarify its purpose in testing invalid federation scenarios.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is also related to this discussion #524 (comment). Let's tackle that there.
|
|
||
| @ParameterizedTest | ||
| @MethodSource("getMessageToSignLegacyArgProvider") | ||
| void getMessageToSign_whenSighashLegacyMode_ok(HSMVersion version, JsonNode expectedMessageToSend) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove these test? We still have the logic to sign legacy transactions, don't we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only for PowHSM. It was named legacy because it was only for HSM 5 prior versions. I removed it because we no longer support any of those versions.
| public Federation getActiveFederation() { | ||
| List<FederationMember> members = new ArrayList<>(); | ||
| int federationSize = federatorSupport.getFederationSize(); | ||
| boolean useTypedPublicKeyGetter = federatorSupport.getConfigForBestBlock().isActive(RSKIP123); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think we need this anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or any other activation check in this class I believe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, if we assume all activations are active, we don't need to check activations.
| ); | ||
| } | ||
|
|
||
| private static IllegalStateException buildInvalidFederationException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this function make sense? Why not trow the exception directly? This is only called in one place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created it to make the functional flow(where the function is being used) more straightforward to follow. But it could be thrown directly.
| private static final FederationConstants federationConstants = FederationMainNetConstants.getInstance(); | ||
| private static final NetworkParameters networkParameters = federationConstants.getBtcParams(); | ||
| private static final Instant creationTime = Instant.ofEpochSecond(5); | ||
| private static ActivationConfig.ForBlock activations; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we remove the need for activations, we should just focus on cases where either the genesis federation is built or a p2wsh. And maybe also federation address not match error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the activations setup from all tests. Now we are checking only Standard(genesis) and P2wsh federation.
The only place where activations is still being used is to create a non-standard ERP federation, using it as an unknown federation (for the federation address not matching error). Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated as discussed. Removed test using old type of federation and refactor border test case when built federatio do not match bridge federation address result
…iderFromFederatorSupport
cc0af43 to
28d9905
Compare
…ederation address
… pegout creation block
…er for clarity in pegout transaction processing
…or clarity in `ReleaseCreationInformationGetter`.
Remove use of local storage for waitingForSignatures pegouts
|



This pull request refactors the logic for determining and constructing federations in
FederationProviderFromFederatorSupport, streamlining the process and improving maintainability. The main changes include consolidating federation construction logic, improving error handling, updating logging, and simplifying the associated tests.Refactoring and logic simplification:
getExpectedFederationmethod with a newbuildFederationmethod that tries to construct the correct federation type (standard multisig or P2SH-P2WSH ERP) and throws a clear exception if neither matches the expected address. Supporting helper methods (tryBuildingStandardMultiSigFederation,tryBuildingP2shP2wshErpFederation) were introduced for clarity and modularity.getActiveFederationandgetRetiringFederationto use the newbuildFederationmethod, and improved debug logging to provide more informative messages.getProposedFederationto always build a P2SH-P2WSH ERP federation, removing conditional logic and the now-unusedbuildProposedFederationmethod.Remove old and unused logic
Remove the use of local storage for waitingForSignatures pegouts. The changes involve deleting the BtcReleaseClientStorageAccessor and BtcReleaseClientStorageSynchronizer classes and all related code, simplifying the pegout signing and release process. Makes the flow easier to follow by removing file-based storage and synchronization checks, making the pegout process depend solely on WaitingForSignature pegout map from the rsk.
Test cleanup and modernization:
FederationProviderFromFederatorSupportTestto use new helper methods (setupActiveFederation,setupActiveFederationKeys) for setting up mocks, removed redundant code, and improved test readability. Also removed unused federation format version constants.These changes make the federation provider code more modular, easier to maintain, and clearer in its intent, while also improving the reliability and clarity of the test suite.
How Has This Been Tested?
Unit tests
Types of changes
Checklist: