Skip to content

Commit

Permalink
Do not set active federation creation block height before validation
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-zack committed Nov 19, 2024
1 parent 6983bb2 commit 80b0d63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,9 @@ private FederationChangeResponseCode legacyCommitPendingFederation(PendingFedera
clearPendingFederationVoting();

if (activations.isActive(RSKIP186)) {
setNewActiveFederationCreationBlockHeight();
preserveLastRetiredFederationScript();
// since we are creating the to-be-active-fed in this block,
// its creation block height is this block number
saveFederationChangeInfo(rskExecutionBlock.getNumber());
}

Federation currentOldFederation = provider.getOldFederation(constants, activations);
Expand Down Expand Up @@ -734,7 +735,6 @@ private FederationChangeResponseCode commitPendingFederation(PendingFederation c
// set proposed federation
Federation proposedFederation = buildFederationFromPendingFederation(currentPendingFederation);
provider.setProposedFederation(proposedFederation);
setNewActiveFederationCreationBlockHeight();

clearPendingFederationVoting();

Expand All @@ -756,19 +756,17 @@ private void clearPendingFederationVoting() {
provider.getFederationElection(constants.getFederationChangeAuthorizer()).clear();
}

private void preserveLastRetiredFederationScript() {
private void saveFederationChangeInfo(long newActiveFederationCreationBlockHeight) {
saveLastRetiredFederationScript();
provider.setNextFederationCreationBlockHeight(newActiveFederationCreationBlockHeight);
}

private void saveLastRetiredFederationScript() {
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 @@ -444,11 +444,11 @@ void voteCommitFederation_postRSKIP419_whenPendingFederationIsSet_shouldPerformC

assertPendingFederationVotingWasCleaned();

assertNewActiveFederationCreationBlockHeightWasSet();

assertLogCommitFederation(activeFederation, proposedFederation.get());

// assert new and old federation were not set and utxos were not moved
// assert some values were not set
assertNewActiveFederationCreationBlockHeightWasNotSet();
assertLastRetiredFederationScriptWasNotSet();
assertNewAndOldFederationsWereNotSet();
assertUTXOsWereNotMovedFromNewToOldFederation();
}
Expand Down Expand Up @@ -516,13 +516,23 @@ private void assertNewActiveFederationCreationBlockHeightWasSet() {
assertEquals(RSK_EXECUTION_BLOCK_NUMBER, nextFederationCreationBlockHeight.get());
}

private void assertNewActiveFederationCreationBlockHeightWasNotSet() {
Optional<Long> nextFederationCreationBlockHeight = storageProvider.getNextFederationCreationBlockHeight(activations);
assertFalse(nextFederationCreationBlockHeight.isPresent());
}

private void assertLastRetiredFederationScriptWasSet() {
Script activeFederationMembersP2SHScript = getFederationMembersP2SHScript(activations, federationSupport.getActiveFederation());
Optional<Script> lastRetiredFederationP2SHScript = storageProvider.getLastRetiredFederationP2SHScript(activations);
assertTrue(lastRetiredFederationP2SHScript.isPresent());
assertEquals(activeFederationMembersP2SHScript, lastRetiredFederationP2SHScript.get());
}

private void assertLastRetiredFederationScriptWasNotSet() {
Optional<Script> lastRetiredFederationP2SHScript = storageProvider.getLastRetiredFederationP2SHScript(activations);
assertFalse(lastRetiredFederationP2SHScript.isPresent());
}

private Script getFederationMembersP2SHScript(ActivationConfig.ForBlock activations, Federation federation) {
// when the federation is a standard multisig,
// the members p2sh script is the p2sh script
Expand Down

0 comments on commit 80b0d63

Please sign in to comment.