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 1 commit
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,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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be done at this point? Shouldn't we set this value after the proposed federation is validated? If the validation fails we'd end up with an invalid value here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we discussed this when developing phase1, the idea was that the activation period remain the same. But yes it makes sense to do it after the validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


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