Skip to content

Commit

Permalink
Do not set last retired fed p2sh script in new commitFederation impl
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-zack committed Nov 13, 2024
1 parent 4083234 commit 6983bb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,8 @@ private FederationChangeResponseCode legacyCommitPendingFederation(PendingFedera
clearPendingFederationVoting();

if (activations.isActive(RSKIP186)) {
preserveFederationChangeInfo(activeFederation);
setNewActiveFederationCreationBlockHeight();
preserveLastRetiredFederationScript();
}

Federation currentOldFederation = provider.getOldFederation(constants, activations);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -443,7 +444,7 @@ void voteCommitFederation_postRSKIP419_whenPendingFederationIsSet_shouldPerformC

assertPendingFederationVotingWasCleaned();

assertFederationChangeInfoWasSet();
assertNewActiveFederationCreationBlockHeightWasSet();

assertLogCommitFederation(activeFederation, proposedFederation.get());

Expand Down Expand Up @@ -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<Long> 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<Script> lastRetiredFederationP2SHScript = storageProvider.getLastRetiredFederationP2SHScript(activations);
assertTrue(lastRetiredFederationP2SHScript.isPresent());
Expand Down

0 comments on commit 6983bb2

Please sign in to comment.