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

Do not set last retired fed p2sh script in new commitFederation impl #2842

Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,9 @@ private FederationChangeResponseCode legacyCommitPendingFederation(PendingFedera
clearPendingFederationVoting();

if (activations.isActive(RSKIP186)) {
preserveFederationChangeInfo(activeFederation);
// 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 @@ -736,9 +738,7 @@ private FederationChangeResponseCode commitPendingFederation(PendingFederation c

clearPendingFederationVoting();

Federation activeFederation = getActiveFederation();
preserveFederationChangeInfo(activeFederation);
logCommitmentWithVotedFederation(eventLogger, activeFederation, proposedFederation);
logCommitmentWithVotedFederation(eventLogger, getActiveFederation(), proposedFederation);

return FederationChangeResponseCode.SUCCESSFUL;
}
Expand All @@ -756,9 +756,13 @@ private void clearPendingFederationVoting() {
provider.getFederationElection(constants.getFederationChangeAuthorizer()).clear();
}

private void preserveFederationChangeInfo(Federation activeFederation) {
provider.setNextFederationCreationBlockHeight(rskExecutionBlock.getNumber());
private void saveFederationChangeInfo(long newActiveFederationCreationBlockHeight) {
saveLastRetiredFederationScript();
provider.setNextFederationCreationBlockHeight(newActiveFederationCreationBlockHeight);
}

private void saveLastRetiredFederationScript() {
Federation activeFederation = getActiveFederation();
Script activeFederationMembersP2SHScript = getFederationMembersP2SHScript(activeFederation);
provider.setLastRetiredFederationP2SHScript(activeFederationMembersP2SHScript);
}
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,11 +444,11 @@ void voteCommitFederation_postRSKIP419_whenPendingFederationIsSet_shouldPerformC

assertPendingFederationVotingWasCleaned();

assertFederationChangeInfoWasSet();

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 @@ -509,19 +510,29 @@ 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());
}

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

// 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());
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