diff --git a/rskj-core/src/main/java/co/rsk/peg/federation/FederationSupportImpl.java b/rskj-core/src/main/java/co/rsk/peg/federation/FederationSupportImpl.java index d17fd155cc..762272cc06 100644 --- a/rskj-core/src/main/java/co/rsk/peg/federation/FederationSupportImpl.java +++ b/rskj-core/src/main/java/co/rsk/peg/federation/FederationSupportImpl.java @@ -702,7 +702,8 @@ private FederationChangeResponseCode legacyCommitPendingFederation(PendingFedera clearPendingFederationVoting(); if (activations.isActive(RSKIP186)) { - preserveFederationChangeInfo(activeFederation); + setNewActiveFederationCreationBlockHeight(); + preserveLastRetiredFederationScript(); } Federation currentOldFederation = provider.getOldFederation(constants, activations); @@ -733,12 +734,11 @@ private FederationChangeResponseCode commitPendingFederation(PendingFederation c // set proposed federation Federation proposedFederation = buildFederationFromPendingFederation(currentPendingFederation); provider.setProposedFederation(proposedFederation); + setNewActiveFederationCreationBlockHeight(); clearPendingFederationVoting(); - Federation activeFederation = getActiveFederation(); - preserveFederationChangeInfo(activeFederation); - logCommitmentWithVotedFederation(eventLogger, activeFederation, proposedFederation); + logCommitmentWithVotedFederation(eventLogger, getActiveFederation(), proposedFederation); return FederationChangeResponseCode.SUCCESSFUL; } @@ -756,13 +756,19 @@ private void clearPendingFederationVoting() { provider.getFederationElection(constants.getFederationChangeAuthorizer()).clear(); } - private void preserveFederationChangeInfo(Federation activeFederation) { - provider.setNextFederationCreationBlockHeight(rskExecutionBlock.getNumber()); - + private void preserveLastRetiredFederationScript() { + Federation activeFederation = getActiveFederation(); Script activeFederationMembersP2SHScript = getFederationMembersP2SHScript(activeFederation); provider.setLastRetiredFederationP2SHScript(activeFederationMembersP2SHScript); } + private void setNewActiveFederationCreationBlockHeight() { + // since we are creating the to-be-active-fed in this block, + // its creation block height is this block number + long newActiveFederationCreationBlockHeight = rskExecutionBlock.getNumber(); + provider.setNextFederationCreationBlockHeight(newActiveFederationCreationBlockHeight); + } + private Script getFederationMembersP2SHScript(Federation federation) { // when the federation is a standard multisig, // the members p2sh script is the p2sh script diff --git a/rskj-core/src/test/java/co/rsk/peg/federation/VoteFederationChangeTest.java b/rskj-core/src/test/java/co/rsk/peg/federation/VoteFederationChangeTest.java index 610720b6bb..a867537669 100644 --- a/rskj-core/src/test/java/co/rsk/peg/federation/VoteFederationChangeTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/federation/VoteFederationChangeTest.java @@ -415,7 +415,8 @@ void voteCommitFederation_postRSKIP186_preRSKIP419_whenPendingFederationIsSet_sh assertPendingFederationVotingWasCleaned(); - assertFederationChangeInfoWasSet(); + assertNewActiveFederationCreationBlockHeightWasSet(); + assertLastRetiredFederationScriptWasSet(); Federation oldFederation = storageProvider.getOldFederation(federationMainnetConstants, activations); Federation newFederation = storageProvider.getNewFederation(federationMainnetConstants, activations); @@ -443,7 +444,7 @@ void voteCommitFederation_postRSKIP419_whenPendingFederationIsSet_shouldPerformC assertPendingFederationVotingWasCleaned(); - assertFederationChangeInfoWasSet(); + assertNewActiveFederationCreationBlockHeightWasSet(); assertLogCommitFederation(activeFederation, proposedFederation.get()); @@ -509,13 +510,13 @@ private void assertPendingFederationVotingWasCleaned() { assertTrue(federationElectionVotes.isEmpty()); } - private void assertFederationChangeInfoWasSet() { - // assert federation creation block height was set correctly + private void assertNewActiveFederationCreationBlockHeightWasSet() { Optional nextFederationCreationBlockHeight = storageProvider.getNextFederationCreationBlockHeight(activations); assertTrue(nextFederationCreationBlockHeight.isPresent()); assertEquals(RSK_EXECUTION_BLOCK_NUMBER, nextFederationCreationBlockHeight.get()); + } - // assert last retired federation p2sh script was set correctly + private void assertLastRetiredFederationScriptWasSet() { Script activeFederationMembersP2SHScript = getFederationMembersP2SHScript(activations, federationSupport.getActiveFederation()); Optional