Skip to content
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

Implement getProposedFederation in FederationProviderFromFederatorSupport #329

Open
wants to merge 32 commits into
base: feat/powpeg_validation_protocol-phase4
Choose a base branch
from

Conversation

apancorb
Copy link
Contributor

Summary

This PR includes the implementation of getProposedFederation. As well as bridge RPC methods for specific proposed federation implementations for getFederationSize, getFederatorPublicKeyOfType,getFederationCreationTime, and getFederationCreationBlockNumber.

Motivation and Context

https://github.com/rsksmart/RSKIPs/blob/master/IPs/RSKIP419.md

@apancorb apancorb self-assigned this Oct 25, 2024
@apancorb apancorb marked this pull request as ready for review October 25, 2024 12:50
@apancorb apancorb requested a review from a team as a code owner October 25, 2024 12:50
);

Federation initialFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs);
Federation expectedFederation = getExpectedFederation(initialFederation, proposedFederationAddress.get());
Copy link
Contributor

Choose a reason for hiding this comment

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

I see how getExpectedFederation builds the federation, and I think this method is unsuitable for this case. At the beginning, you have already checked if RSKIP419 is active, so we can be sure that the proposed federation will be a P2shFederation. if not, I would like to understand why you would be a different type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out :) , I have made the changes. Let me know if this looks good now.

* and the retiring federation, if one exists.
*
* @return a {@link List} of live {@link Federation} instances
*/
List<Federation> getLiveFederations();
Copy link
Contributor Author

@apancorb apancorb Oct 30, 2024

Choose a reason for hiding this comment

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

We can probably remove this method, is not being used anywhere at the moment. Maybe in another PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Lets create a task for that

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree

* and the retiring federation, if one exists.
*
* @return a {@link List} of live {@link Federation} instances
*/
List<Federation> getLiveFederations();
Copy link
Contributor

Choose a reason for hiding this comment

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

Agree

src/test/java/co/rsk/federate/FederatorSupportTest.java Outdated Show resolved Hide resolved
Comment on lines +152 to +156
Integer federationSize = federatorSupport.getProposedFederationSize()
.orElse(FEDERATION_NON_EXISTENT.getCode());
if (federationSize == FEDERATION_NON_EXISTENT.getCode()) {
return Optional.empty();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Integer federationSize = federatorSupport.getProposedFederationSize()
.orElse(FEDERATION_NON_EXISTENT.getCode());
if (federationSize == FEDERATION_NON_EXISTENT.getCode()) {
return Optional.empty();
}
Optional<Integer> federationSize = federatorSupport.getProposedFederationSize();
if (federationSize.isEmpty()) {
return Optional.empty();
}

wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would work if the Bridge returned only a null value for the federation size if the proposed fed did not exist. But it can return FEDERATION_NON_EXISTENT which would be present in the optional. We would have to check this before continuing.

Copy link
Contributor

Choose a reason for hiding this comment

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

pretty sure the FEDERATION_NON_EXISTENT code is not being used for the proposed fed, but for the pending and retiring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was implemented here.

Copy link
Contributor

Choose a reason for hiding this comment

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

my bad, you right. But in that case it wont be necessary to have an optional right? Because you are always getting a value from the Bridge

Copy link

sonarcloud bot commented Nov 4, 2024

Comment on lines +373 to +381
@Test
void getProposedFederation_whenRSKIP419IsNotActivated_shouldReturnEmptyOptional() {
// Arrange
ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class);
when(federatorSupportMock.getConfigForBestBlock()).thenReturn(configMock);

// Act & Assert
assertEquals(Optional.empty(), federationProvider.getProposedFederation());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

probably this test can be removed

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.

4 participants