From 34a0910b8e2c018891aab762f0c2029873f2af00 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Mon, 23 Dec 2024 12:04:06 -0300 Subject: [PATCH 1/2] Remove validationPeriodIsOngoing method --- .../src/main/java/co/rsk/peg/BridgeSupport.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java index 3469465466..6a0ea1249d 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -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; } @@ -1079,13 +1079,12 @@ private void allowFederationElectionAgain() { } private boolean isSvpOngoing() { - return federationSupport.getProposedFederation() - .filter(this::validationPeriodIsOngoing) - .isPresent(); - } + Optional 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; From e32131cbe0074fb1fc10f4a3281c71598f46e227 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Thu, 2 Jan 2025 11:13:15 -0300 Subject: [PATCH 2/2] Make code more functional --- .../src/main/java/co/rsk/peg/BridgeSupport.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java index 6a0ea1249d..34e4216797 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -1079,15 +1079,12 @@ private void allowFederationElectionAgain() { } private boolean isSvpOngoing() { - Optional proposedFederation = federationSupport.getProposedFederation(); - if (proposedFederation.isEmpty()) { - return false; - } - - long validationPeriodEndBlock = proposedFederation.get().getCreationBlockNumber() + - bridgeConstants.getFederationConstants().getValidationPeriodDurationInBlocks(); - - return rskExecutionBlock.getNumber() < validationPeriodEndBlock; + return federationSupport + .getProposedFederation() + .map(proposedFederation -> rskExecutionBlock.getNumber() < proposedFederation.getCreationBlockNumber() + + bridgeConstants.getFederationConstants().getValidationPeriodDurationInBlocks() + ) + .orElse(false); } private void processSvpFundTransactionUnsigned(Keccak256 rskTxHash, Federation proposedFederation) {