From 407bbddd0e68303ad779c8c996cb4d8220a5f3bf Mon Sep 17 00:00:00 2001 From: julia-zack Date: Fri, 24 Jan 2025 12:49:53 -0300 Subject: [PATCH 1/2] Add activation code check for federation being built from pending one creation time --- .../co/rsk/peg/federation/FederationSupportImpl.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 b32de5c0a8..58fad953ec 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 @@ -767,12 +767,20 @@ private FederationChangeResponseCode commitPendingFederation(PendingFederation c } private Federation buildFederationFromPendingFederation(PendingFederation pendingFederation) { - Instant federationCreationTime = Instant.ofEpochSecond(rskExecutionBlock.getTimestamp()); + Instant federationCreationTime = getFederationCreationTime(rskExecutionBlock.getTimestamp()); long federationCreationBlockNumber = rskExecutionBlock.getNumber(); return pendingFederation.buildFederation(federationCreationTime, federationCreationBlockNumber, constants, activations); } + private Instant getFederationCreationTime(long rskExecutionBlockTimestamp) { + if (!activations.isActive(RSKIP419)) { + return Instant.ofEpochMilli(rskExecutionBlockTimestamp); + } + + return Instant.ofEpochSecond(rskExecutionBlockTimestamp); + } + private static Script getFederationMembersP2SHScript(ActivationConfig.ForBlock activations, Federation federation) { // when the federation is a standard multisig, the members p2sh script is the p2sh script if (!activations.isActive(RSKIP377)) { From 50232947d930fae2a82c5ce557967e9a03b800c3 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Fri, 24 Jan 2025 13:28:24 -0300 Subject: [PATCH 2/2] Fix broken test --- .../federation/VoteFederationChangeTest.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) 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 c067ae2068..551aa0d9aa 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 @@ -379,13 +379,14 @@ void voteCommitFederation_preRSKIP186_whenPendingFederationIsSet_shouldPerformLe voteAndAssertCommitPendingFederation(); // assertions + Federation newFederation = storageProvider.getNewFederation(federationMainnetConstants, activations); + long expectedNewFederationCreationTimeValue = newFederation.getCreationTime().toEpochMilli(); + Instant expectedNewFederationCreationTime = Instant.ofEpochMilli(RSK_EXECUTION_BLOCK_TIMESTAMP); + assertIsTheExpectedFederation(newFederation, expectedNewFederationCreationTimeValue, expectedNewFederationCreationTime); + List utxosToMove = new ArrayList<>(storageProvider.getNewFederationBtcUTXOs(federationMainnetConstants.getBtcParams(), activations)); assertUTXOsWereMovedFromNewToOldFederation(utxosToMove); - Federation federationBuiltFromPendingFederation = - pendingFederationToBe.buildFederation(Instant.ofEpochMilli(RSK_EXECUTION_BLOCK_TIMESTAMP), RSK_EXECUTION_BLOCK_NUMBER, federationMainnetConstants, activations); - assertNewAndOldFederationsWereSet(federationBuiltFromPendingFederation); - // pre rskip186 these values are not being set assertNewActiveFederationCreationBlockHeightWasNotSet(); assertLastRetiredFederationScriptWasNotSet(); @@ -393,7 +394,6 @@ void voteCommitFederation_preRSKIP186_whenPendingFederationIsSet_shouldPerformLe assertPendingFederationVotingWasCleaned(); Federation oldFederation = storageProvider.getOldFederation(federationMainnetConstants, activations); - Federation newFederation = storageProvider.getNewFederation(federationMainnetConstants, activations); assertLogCommitFederation(oldFederation, newFederation); } @@ -417,7 +417,9 @@ void voteCommitFederation_postRSKIP186_preRSKIP419_whenPendingFederationIsSet_sh // assertions Federation newFederation = storageProvider.getNewFederation(federationMainnetConstants, activations); - assertIsTheExpectedFederation(newFederation); + long expectedNewFederationCreationTimeValue = newFederation.getCreationTime().toEpochMilli(); + Instant expectedNewFederationCreationTime = Instant.ofEpochMilli(RSK_EXECUTION_BLOCK_TIMESTAMP); + assertIsTheExpectedFederation(newFederation, expectedNewFederationCreationTimeValue, expectedNewFederationCreationTime); List utxosToMove = List.copyOf(storageProvider.getNewFederationBtcUTXOs(federationMainnetConstants.getBtcParams(), activations)); assertHandoverToNewFederation(utxosToMove, newFederation); @@ -443,23 +445,26 @@ void voteCommitFederation_postRSKIP419_whenPendingFederationIsSet_shouldPerformC // assertions // assert proposed federation was set correctly - Optional proposedFederation = storageProvider.getProposedFederation(federationMainnetConstants, activations); - assertTrue(proposedFederation.isPresent()); - assertIsTheExpectedFederation(proposedFederation.get()); + Optional proposedFederationOpt = storageProvider.getProposedFederation(federationMainnetConstants, activations); + assertTrue(proposedFederationOpt.isPresent()); + Federation proposedFederation = proposedFederationOpt.get(); + long expectedProposedFederationCreationTimeValue = proposedFederation.getCreationTime().getEpochSecond(); + Instant expectedProposedFederationCreationTime = Instant.ofEpochSecond(RSK_EXECUTION_BLOCK_TIMESTAMP); + assertIsTheExpectedFederation(proposedFederation, expectedProposedFederationCreationTimeValue, expectedProposedFederationCreationTime); assertPendingFederationVotingWasCleaned(); - assertLogCommitFederation(activeFederation, proposedFederation.get()); + assertLogCommitFederation(activeFederation, proposedFederation); assertNoHandoverToNewFederation(); } - private void assertIsTheExpectedFederation(Federation federation) { - assertEquals(RSK_EXECUTION_BLOCK_TIMESTAMP, federation.getCreationTime().getEpochSecond()); + private void assertIsTheExpectedFederation(Federation federation, long expectedCreationTimeValue, Instant expectedCreationTime) { + assertEquals(RSK_EXECUTION_BLOCK_TIMESTAMP, expectedCreationTimeValue); assertEquals(RSK_EXECUTION_BLOCK_NUMBER, federation.getCreationBlockNumber()); Federation federationBuiltFromPendingFederation = pendingFederationToBe.buildFederation( - Instant.ofEpochSecond(RSK_EXECUTION_BLOCK_TIMESTAMP), + expectedCreationTime, RSK_EXECUTION_BLOCK_NUMBER, federationMainnetConstants, activations