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

Remove validationPeriodIsOngoing method #2903

Open
wants to merge 2 commits into
base: use_enum_fed_change_functions_for_voting
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ private void updateSvpState(Transaction rskTx) {
// if the proposed federation exists and the validation period ended,
// we can conclude that the svp failed
Federation proposedFederation = proposedFederationOpt.get();
if (!validationPeriodIsOngoing(proposedFederation)) {
if (!isSvpOngoing()) {
processSvpFailure(proposedFederation);
return;
}
Expand Down Expand Up @@ -1079,13 +1079,12 @@ private void allowFederationElectionAgain() {
}

private boolean isSvpOngoing() {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to make it more functional:

private boolean isSvpOngoing() {
    return federationSupport
            .getProposedFederation()
            .map(proposedFederation -> 
                rskExecutionBlock.getNumber() <
                proposedFederation.getCreationBlockNumber() +
                bridgeConstants.getFederationConstants().getValidationPeriodDurationInBlocks()
            )
            .orElse(false);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

very nice! Updated

return federationSupport.getProposedFederation()
.filter(this::validationPeriodIsOngoing)
.isPresent();
}
Optional<Federation> proposedFederation = federationSupport.getProposedFederation();
if (proposedFederation.isEmpty()) {
return false;
}

private boolean validationPeriodIsOngoing(Federation proposedFederation) {
long validationPeriodEndBlock = proposedFederation.getCreationBlockNumber() +
long validationPeriodEndBlock = proposedFederation.get().getCreationBlockNumber() +
bridgeConstants.getFederationConstants().getValidationPeriodDurationInBlocks();

return rskExecutionBlock.getNumber() < validationPeriodEndBlock;
Expand Down
Loading