From 4a992f8784290f0d60f14e062453938cb0dbecde Mon Sep 17 00:00:00 2001 From: Chalito Date: Tue, 5 Dec 2023 17:35:27 -0300 Subject: [PATCH 01/11] Add automatic docker image build and push on release --- .github/workflows/build-push-docker.yml | 51 +++++++++++++++++++++++++ Dockerfile | 37 ++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 .github/workflows/build-push-docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/build-push-docker.yml b/.github/workflows/build-push-docker.yml new file mode 100644 index 000000000..28c4874db --- /dev/null +++ b/.github/workflows/build-push-docker.yml @@ -0,0 +1,51 @@ +name: Docker Image Build and Push +on: + push: + tags: + - '*' + +jobs: + build: + runs-on: ubuntu-22.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Set version + id: vars + run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: | + atarrio/powpeg-node + ghcr.io/atarrio/powpeg-node + tags: | + type=ref,event=tag + type=edge + # This is used for generating IRIS-3 out of IRIS-3.x.y. + type=match,pattern=(\w+-\d+)\.\d+\.\d+.*,group=1 + + - name: DockerHub login + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: GitHub container registry login + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: RSK_RELEASE=${{ steps.vars.outputs.tag }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..55310cedc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,37 @@ +FROM openjdk:11-jdk-slim-buster AS build + +ARG RSK_RELEASE +ENV RSK_VERSION $RSK_RELEASE +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt-get update -y && \ + apt-get install -y git curl gnupg + +RUN useradd -ms /bin/bash rsk +USER rsk + +WORKDIR /home/rsk +COPY --chown=rsk:rsk . ./ + +RUN gpg --keyserver https://secchannel.rsk.co/SUPPORT.asc --recv-keys 1DC9157991323D23FD37BAA7A6DBEAC640C5A14B && \ + gpg --verify --output SHA256SUMS SHA256SUMS.asc && \ + sha256sum --check SHA256SUMS && \ + ./configure.sh && \ + ./gradlew --no-daemon clean build -x test && \ + cp "build/libs/federate-node-$RSK_VERSION-all.jar" rsk.jar + +FROM openjdk:11-jre-slim-buster +LABEL org.opencontainers.image.authors="ops@iovlabs.org" + +RUN useradd -ms /sbin/nologin -d /var/lib/rsk rsk +USER rsk + +WORKDIR /var/lib/rsk +COPY --from=build --chown=rsk:rsk /home/rsk/rsk.jar ./ + +ENV DEFAULT_JVM_OPTS="-Xss4M" +ENV RSKJ_SYS_PROPS="-Dlogback.configurationFile='/etc/rsk/logback.xml' -Drsk.conf.file=/etc/rsk/node.conf" +ENV RSKJ_CLASS=co.rsk.federate.FederateRunner +ENV RSKJ_OPTS="" + +ENTRYPOINT ["/bin/sh", "-c", "java $DEFAULT_JVM_OPTS $RSKJ_SYS_PROPS -cp rsk.jar $RSKJ_CLASS $RSKJ_OPTS \"${@}\"", "--"] From ac84fa5354dac770dc81087689503177e1dfff21 Mon Sep 17 00:00:00 2001 From: Chalito Date: Thu, 1 Feb 2024 11:26:06 -0300 Subject: [PATCH 02/11] TEST --- .github/workflows/build-push-docker.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-push-docker.yml b/.github/workflows/build-push-docker.yml index 28c4874db..0734dfe9f 100644 --- a/.github/workflows/build-push-docker.yml +++ b/.github/workflows/build-push-docker.yml @@ -27,6 +27,20 @@ jobs: type=edge # This is used for generating IRIS-3 out of IRIS-3.x.y. type=match,pattern=(\w+-\d+)\.\d+\.\d+.*,group=1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + driver: docker + + - name: Build Docker Image + uses: docker/build-push-action@v5 + with: + context: . + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: RSK_RELEASE=${{ steps.vars.outputs.tag }} + - name: DockerHub login uses: docker/login-action@v3 @@ -41,11 +55,9 @@ jobs: username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build and push + - name: Push Images uses: docker/build-push-action@v5 with: - context: . push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - build-args: RSK_RELEASE=${{ steps.vars.outputs.tag }} From ac4572d437e51ab5237926ebef46d2d94c79e476 Mon Sep 17 00:00:00 2001 From: Chalito Date: Tue, 5 Dec 2023 17:35:27 -0300 Subject: [PATCH 03/11] Add automatic docker image build and push on release --- .github/workflows/build-push-docker.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-push-docker.yml b/.github/workflows/build-push-docker.yml index 0734dfe9f..c70094976 100644 --- a/.github/workflows/build-push-docker.yml +++ b/.github/workflows/build-push-docker.yml @@ -22,6 +22,8 @@ jobs: images: | atarrio/powpeg-node ghcr.io/atarrio/powpeg-node + #rsk/powpeg-node + #ghcr.io/rsksmart/powpeg-node tags: | type=ref,event=tag type=edge @@ -41,7 +43,6 @@ jobs: labels: ${{ steps.meta.outputs.labels }} build-args: RSK_RELEASE=${{ steps.vars.outputs.tag }} - - name: DockerHub login uses: docker/login-action@v3 with: From 8660c2e67a9dbcb7a5b076299c06cf438d8d602e Mon Sep 17 00:00:00 2001 From: julia zack Date: Tue, 12 Dec 2023 13:09:09 -0300 Subject: [PATCH 04/11] Adapt to rskj changes --- .../java/co/rsk/federate/BtcToRskClient.java | 4 +-- .../java/co/rsk/federate/FedNodeRunner.java | 4 +-- .../co/rsk/federate/FederationProvider.java | 2 +- ...ederationProviderFromFederatorSupport.java | 19 +++++------ .../co/rsk/federate/FederationWatcher.java | 2 +- .../co/rsk/federate/FederatorSupport.java | 4 +-- .../rsk/federate/bitcoin/BitcoinWrapper.java | 2 +- .../federate/bitcoin/BitcoinWrapperImpl.java | 2 +- .../btcreleaseclient/BtcReleaseClient.java | 8 ++--- .../rsk/federate/BtcToRskClientBuilder.java | 2 +- .../co/rsk/federate/BtcToRskClientTest.java | 5 +-- ...ationProviderFromFederatorSupportTest.java | 32 +++++++++---------- .../rsk/federate/FederationWatcherTest.java | 12 +++---- .../bitcoin/BitcoinWrapperImplTest.java | 2 +- .../BtcReleaseClientTest.java | 20 ++++++------ .../federate/mock/SimpleBitcoinWrapper.java | 2 +- .../PowHSMSignerMessageBuilderTest.java | 2 +- .../message/SignerMessageBuilderV1Test.java | 2 +- .../rsk/federate/signing/utils/TestUtils.java | 23 ++++++------- 19 files changed, 72 insertions(+), 77 deletions(-) diff --git a/src/main/java/co/rsk/federate/BtcToRskClient.java b/src/main/java/co/rsk/federate/BtcToRskClient.java index 99edab6af..0653da63a 100644 --- a/src/main/java/co/rsk/federate/BtcToRskClient.java +++ b/src/main/java/co/rsk/federate/BtcToRskClient.java @@ -15,9 +15,9 @@ import co.rsk.net.NodeBlockProcessor; import co.rsk.panic.PanicProcessor; import co.rsk.peg.BridgeUtils; -import co.rsk.peg.Federation; -import co.rsk.peg.FederationMember; import co.rsk.peg.PegUtilsLegacy; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationMember; import co.rsk.peg.PeginInformation; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; diff --git a/src/main/java/co/rsk/federate/FedNodeRunner.java b/src/main/java/co/rsk/federate/FedNodeRunner.java index 5fe611889..529d037b7 100644 --- a/src/main/java/co/rsk/federate/FedNodeRunner.java +++ b/src/main/java/co/rsk/federate/FedNodeRunner.java @@ -47,8 +47,8 @@ import co.rsk.federate.signing.hsm.message.SignerMessageBuilderFactory; import co.rsk.federate.signing.hsm.requirements.AncestorBlockUpdater; import co.rsk.federate.signing.hsm.requirements.ReleaseRequirementsEnforcer; -import co.rsk.peg.Federation; -import co.rsk.peg.FederationMember; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationMember; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; import co.rsk.peg.pegininstructions.PeginInstructionsProvider; import org.bitcoinj.core.Context; diff --git a/src/main/java/co/rsk/federate/FederationProvider.java b/src/main/java/co/rsk/federate/FederationProvider.java index f929a5406..244bf2749 100644 --- a/src/main/java/co/rsk/federate/FederationProvider.java +++ b/src/main/java/co/rsk/federate/FederationProvider.java @@ -19,7 +19,7 @@ package co.rsk.federate; import co.rsk.bitcoinj.core.Address; -import co.rsk.peg.Federation; +import co.rsk.peg.federation.Federation; import java.util.List; import java.util.Optional; diff --git a/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java b/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java index 39e399ccb..135359c6d 100644 --- a/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java +++ b/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java @@ -21,11 +21,9 @@ import co.rsk.bitcoinj.core.Address; import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.config.BridgeConstants; -import co.rsk.peg.Federation; -import co.rsk.peg.StandardMultisigFederation; -import co.rsk.peg.LegacyErpFederation; -import co.rsk.peg.P2shErpFederation; -import co.rsk.peg.FederationMember; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationFactory; +import co.rsk.peg.federation.FederationMember; import org.ethereum.crypto.ECKey; import java.time.Instant; @@ -77,7 +75,7 @@ public Federation getActiveFederation() { Instant creationTime = federatorSupport.getFederationCreationTime(); long creationBlockNumber = federatorSupport.getFederationCreationBlockNumber(); - Federation initialFederation = new StandardMultisigFederation( + Federation initialFederation = FederationFactory.buildStandardMultiSigFederation( members, creationTime, creationBlockNumber, @@ -127,7 +125,7 @@ public Optional getRetiringFederation() { Instant creationTime = federatorSupport.getRetiringFederationCreationTime(); long creationBlockNumber = federatorSupport.getRetiringFederationCreationBlockNumber(); - Federation initialFederation = new StandardMultisigFederation( + Federation initialFederation = FederationFactory.buildStandardMultiSigFederation( members, creationTime, creationBlockNumber, @@ -160,7 +158,7 @@ private Federation getExpectedFederation(Federation initialFederation, Address e } // If addresses do not match build an ERP federation - Federation erpFederation = new LegacyErpFederation( + Federation erpFederation = FederationFactory.buildNonStandardErpFederation( initialFederation.getMembers(), initialFederation.getCreationTime(), initialFederation.getCreationBlockNumber(), @@ -175,14 +173,13 @@ private Federation getExpectedFederation(Federation initialFederation, Address e } // Finally, try building a P2SH ERP federation - return new P2shErpFederation( + return FederationFactory.buildP2shErpFederation( initialFederation.getMembers(), initialFederation.getCreationTime(), initialFederation.getCreationBlockNumber(), federatorSupport.getBtcParams(), bridgeConstants.getErpFedPubKeysList(), - bridgeConstants.getErpFedActivationDelay(), - federatorSupport.getConfigForBestBlock() + bridgeConstants.getErpFedActivationDelay() ); // TODO: what if no federation built matches the expected address? diff --git a/src/main/java/co/rsk/federate/FederationWatcher.java b/src/main/java/co/rsk/federate/FederationWatcher.java index ffae7b4df..7d47379fa 100644 --- a/src/main/java/co/rsk/federate/FederationWatcher.java +++ b/src/main/java/co/rsk/federate/FederationWatcher.java @@ -1,7 +1,7 @@ package co.rsk.federate; import co.rsk.bitcoinj.core.Address; -import co.rsk.peg.Federation; +import co.rsk.peg.federation.Federation; import org.ethereum.core.TransactionReceipt; import org.ethereum.facade.Ethereum; import org.ethereum.listener.EthereumListenerAdapter; diff --git a/src/main/java/co/rsk/federate/FederatorSupport.java b/src/main/java/co/rsk/federate/FederatorSupport.java index 7b952f3f1..bc275c681 100644 --- a/src/main/java/co/rsk/federate/FederatorSupport.java +++ b/src/main/java/co/rsk/federate/FederatorSupport.java @@ -9,15 +9,13 @@ import co.rsk.federate.config.FedNodeSystemProperties; import co.rsk.federate.signing.ECDSASigner; import co.rsk.peg.Bridge; -import co.rsk.peg.BridgeMethods; -import co.rsk.peg.FederationMember; +import co.rsk.peg.federation.FederationMember; import co.rsk.peg.StateForFederator; import org.bitcoinj.core.PartialMerkleTree; import org.bitcoinj.core.PeerAddress; import org.bitcoinj.core.Sha256Hash; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.core.Blockchain; -import org.ethereum.core.CallTransaction; import org.ethereum.crypto.ECKey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/co/rsk/federate/bitcoin/BitcoinWrapper.java b/src/main/java/co/rsk/federate/bitcoin/BitcoinWrapper.java index 8f7ec42d6..845964f0b 100644 --- a/src/main/java/co/rsk/federate/bitcoin/BitcoinWrapper.java +++ b/src/main/java/co/rsk/federate/bitcoin/BitcoinWrapper.java @@ -1,6 +1,6 @@ package co.rsk.federate.bitcoin; -import co.rsk.peg.Federation; +import co.rsk.peg.federation.Federation; import org.bitcoinj.core.*; import org.bitcoinj.core.listeners.NewBestBlockListener; import org.bitcoinj.store.BlockStoreException; diff --git a/src/main/java/co/rsk/federate/bitcoin/BitcoinWrapperImpl.java b/src/main/java/co/rsk/federate/bitcoin/BitcoinWrapperImpl.java index 01f78a7e3..e233694a0 100644 --- a/src/main/java/co/rsk/federate/bitcoin/BitcoinWrapperImpl.java +++ b/src/main/java/co/rsk/federate/bitcoin/BitcoinWrapperImpl.java @@ -6,8 +6,8 @@ import co.rsk.federate.FederatorSupport; import co.rsk.federate.adapter.ThinConverter; import co.rsk.peg.BridgeBtcWallet; -import co.rsk.peg.Federation; import co.rsk.peg.PegUtilsLegacy; +import co.rsk.peg.federation.Federation; import co.rsk.peg.PeginInformation; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; import co.rsk.peg.pegininstructions.PeginInstructionsException; diff --git a/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java b/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java index b6b59d6ce..c8be063ce 100644 --- a/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java +++ b/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java @@ -32,8 +32,8 @@ import co.rsk.peg.Bridge; import co.rsk.peg.BridgeEvents; import co.rsk.peg.BridgeUtils; -import co.rsk.peg.Federation; -import co.rsk.peg.ErpFederation; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.ErpFederation; import co.rsk.peg.StateForFederator; import java.util.ArrayList; import java.util.Arrays; @@ -352,7 +352,7 @@ protected void validateTxCanBeSigned(BtcTransaction btcTx) throws FederatorAlrea observedFederations.stream() .forEach(f -> logger.trace("[validateTxCanBeSigned] federation p2sh redeem script {}", f.getRedeemScript())); List spendingFedFilter = observedFederations.stream() - .filter(f -> (f instanceof ErpFederation ? ((ErpFederation) f).getStandardRedeemScript() : f.getRedeemScript()).equals(standardRedeemScript)).collect(Collectors.toList()); + .filter(f -> (f instanceof ErpFederation ? ((ErpFederation) f).getDefaultRedeemScript() : f.getRedeemScript()).equals(standardRedeemScript)).collect(Collectors.toList()); logger.debug("[validateTxCanBeSigned] spendingFedFilter size {}", spendingFedFilter.size()); if (spendingFedFilter.isEmpty()) { String message = String.format( @@ -464,7 +464,7 @@ protected Federation getSpendingFederation(BtcTransaction btcTx) { Script redeemScript = extractStandardRedeemScript(getRedeemScriptFromInput(firstInput)); List spendingFedFilter = observedFederations.stream() - .filter(f -> (f instanceof ErpFederation ? ((ErpFederation) f).getStandardRedeemScript() : f.getRedeemScript()).equals(redeemScript)).collect(Collectors.toList()); + .filter(f -> (f instanceof ErpFederation ? ((ErpFederation) f).getDefaultRedeemScript() : f.getRedeemScript()).equals(redeemScript)).collect(Collectors.toList()); return spendingFedFilter.get(0); } diff --git a/src/test/java/co/rsk/federate/BtcToRskClientBuilder.java b/src/test/java/co/rsk/federate/BtcToRskClientBuilder.java index 95b7824d0..5bfe703e8 100644 --- a/src/test/java/co/rsk/federate/BtcToRskClientBuilder.java +++ b/src/test/java/co/rsk/federate/BtcToRskClientBuilder.java @@ -10,7 +10,7 @@ import co.rsk.federate.io.BtcToRskClientFileData; import co.rsk.federate.io.BtcToRskClientFileReadResult; import co.rsk.federate.io.BtcToRskClientFileStorage; -import co.rsk.peg.Federation; +import co.rsk.peg.federation.Federation; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; import co.rsk.peg.pegininstructions.PeginInstructionsException; import co.rsk.peg.pegininstructions.PeginInstructionsProvider; diff --git a/src/test/java/co/rsk/federate/BtcToRskClientTest.java b/src/test/java/co/rsk/federate/BtcToRskClientTest.java index 8dc6d6238..1821a3553 100644 --- a/src/test/java/co/rsk/federate/BtcToRskClientTest.java +++ b/src/test/java/co/rsk/federate/BtcToRskClientTest.java @@ -38,9 +38,10 @@ import co.rsk.federate.mock.SimpleBtcTransaction; import co.rsk.federate.mock.SimpleFederatorSupport; import co.rsk.net.NodeBlockProcessor; -import co.rsk.peg.Federation; -import co.rsk.peg.FederationMember; +import co.rsk.peg.BridgeUtils; import co.rsk.peg.PegUtilsLegacy; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationMember; import co.rsk.peg.btcLockSender.BtcLockSender; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; diff --git a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java index 6f4ebff50..6229c7f7e 100644 --- a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java +++ b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java @@ -15,12 +15,7 @@ import co.rsk.bitcoinj.script.Script; import co.rsk.config.BridgeConstants; import co.rsk.config.BridgeTestNetConstants; -import co.rsk.peg.FederationMember; -import co.rsk.peg.Federation; -import co.rsk.peg.StandardMultisigFederation; -import co.rsk.peg.ErpFederation; -import co.rsk.peg.LegacyErpFederation; -import co.rsk.peg.P2shErpFederation; +import co.rsk.peg.federation.*; import java.math.BigInteger; import java.time.Instant; @@ -41,6 +36,10 @@ class FederationProviderFromFederatorSupportTest { private NetworkParameters testnetParams; private Instant creationTime; + private static final int STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION = FederationFormatVersion.STANDARD_MULTISIG_FEDERATION.getFormatVersion(); + private static final int NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION = FederationFormatVersion.NON_STANDARD_ERP_FEDERATION.getFormatVersion(); + private static final int P2SH_ERP_FEDERATION_FORMAT_VERSION = FederationFormatVersion.P2SH_ERP_FEDERATION.getFormatVersion(); + private static final Address HARDCODED_TESTNET_FED_ADDRESS = Address.fromBase58( NetworkParameters.fromID(NetworkParameters.ID_TESTNET), "2Mw6KM642fbkypTzbgFi6DTgTFPRWZUD4BA" @@ -205,7 +204,7 @@ void getActiveFederation_p2sh_erp_federation() { Federation obtainedFederation = federationProvider.getActiveFederation(); - assertTrue(obtainedFederation instanceof P2shErpFederation); + assertEquals(P2SH_ERP_FEDERATION_FORMAT_VERSION, obtainedFederation.getFormatVersion()); assertEquals(expectedFederation, obtainedFederation); assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @@ -361,7 +360,7 @@ void getRetiringFederation_present_p2sh_erp_federation() { Federation obtainedFederation = obtainedFederationOptional.get(); - assertTrue(obtainedFederation instanceof P2shErpFederation); + assertEquals(P2SH_ERP_FEDERATION_FORMAT_VERSION, obtainedFederation.getFormatVersion()); assertEquals(expectedFederation, obtainedFederation); assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @@ -489,7 +488,7 @@ void getLiveFederations_onlyActive_p2sh_erp_federation() { assertEquals(1, liveFederations.size()); Federation activeFederation = liveFederations.get(0); - assertTrue(activeFederation instanceof P2shErpFederation); + assertEquals(P2SH_ERP_FEDERATION_FORMAT_VERSION, activeFederation.getFormatVersion()); assertEquals(expectedActiveFederation, activeFederation); assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); } @@ -745,7 +744,7 @@ void getLiveFederations_retiring_erp_active_p2sh_erp() { assertEquals(2, liveFederations.size()); Federation activeFederation = liveFederations.get(0); - assertTrue(activeFederation instanceof P2shErpFederation); + assertEquals(P2SH_ERP_FEDERATION_FORMAT_VERSION, activeFederation.getFormatVersion()); assertEquals(expectedActiveFederation, activeFederation); assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); @@ -799,18 +798,18 @@ void getLiveFederations_both_p2sh_erp_federations() { assertEquals(2, liveFederations.size()); Federation activeFederation = liveFederations.get(0); - assertTrue(activeFederation instanceof P2shErpFederation); + assertEquals(P2SH_ERP_FEDERATION_FORMAT_VERSION, activeFederation.getFormatVersion()); assertEquals(expectedActiveFederation, activeFederation); assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); Federation retiringFederation = liveFederations.get(1); - assertTrue(retiringFederation instanceof P2shErpFederation); + assertEquals(P2SH_ERP_FEDERATION_FORMAT_VERSION, retiringFederation.getFormatVersion()); assertEquals(expectedRetiringFederation, retiringFederation); assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } private Federation createFederation(List members) { - return new StandardMultisigFederation( + return FederationFactory.buildStandardMultiSigFederation( members, creationTime, 0L, @@ -819,7 +818,7 @@ private Federation createFederation(List members) { } private Federation createErpFederation(List members, ActivationConfig.ForBlock activations) { - return new LegacyErpFederation( + return FederationFactory.buildNonStandardErpFederation( members, creationTime, 0L, @@ -831,14 +830,13 @@ private Federation createErpFederation(List members, Activatio } private Federation createP2shErpFederation(List members, ActivationConfig.ForBlock activations) { - return new P2shErpFederation( + return FederationFactory.buildP2shErpFederation( members, creationTime, 0L, testnetParams, bridgeConstants.getErpFedPubKeysList(), - bridgeConstants.getErpFedActivationDelay(), - activations + bridgeConstants.getErpFedActivationDelay() ); } diff --git a/src/test/java/co/rsk/federate/FederationWatcherTest.java b/src/test/java/co/rsk/federate/FederationWatcherTest.java index 4c3a580cc..c58bdae49 100644 --- a/src/test/java/co/rsk/federate/FederationWatcherTest.java +++ b/src/test/java/co/rsk/federate/FederationWatcherTest.java @@ -13,15 +13,15 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.federate.signing.utils.TestUtils; -import co.rsk.peg.Federation; -import co.rsk.peg.FederationMember; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationFactory; +import co.rsk.peg.federation.FederationMember; import java.math.BigInteger; import java.time.Instant; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import co.rsk.peg.StandardMultisigFederation; import org.ethereum.crypto.ECKey; import org.ethereum.facade.Ethereum; import org.ethereum.listener.EthereumListenerAdapter; @@ -31,21 +31,21 @@ import org.mockito.invocation.InvocationOnMock; class FederationWatcherTest { - private final Federation federation1 = new StandardMultisigFederation( + private final Federation federation1 = FederationFactory.buildStandardMultiSigFederation( getFederationMembersFromPksForBtc(1000, 2000, 3000, 4000), Instant.ofEpochMilli(5005L), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); - private final Federation federation2 = new StandardMultisigFederation( + private final Federation federation2 = FederationFactory.buildStandardMultiSigFederation( getFederationMembersFromPksForBtc(2000, 3000, 4000, 5000, 6000, 7000), Instant.ofEpochMilli(15300L), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); - private final Federation federation3 = new StandardMultisigFederation( + private final Federation federation3 = FederationFactory.buildStandardMultiSigFederation( getFederationMembersFromPksForBtc(5000, 6000, 7000), Instant.ofEpochMilli(7400L), 0L, diff --git a/src/test/java/co/rsk/federate/bitcoin/BitcoinWrapperImplTest.java b/src/test/java/co/rsk/federate/bitcoin/BitcoinWrapperImplTest.java index ad8543643..a3be2f0da 100644 --- a/src/test/java/co/rsk/federate/bitcoin/BitcoinWrapperImplTest.java +++ b/src/test/java/co/rsk/federate/bitcoin/BitcoinWrapperImplTest.java @@ -14,7 +14,7 @@ import co.rsk.config.BridgeRegTestConstants; import co.rsk.federate.FederatorSupport; import co.rsk.federate.adapter.ThinConverter; -import co.rsk.peg.Federation; +import co.rsk.peg.federation.Federation; import co.rsk.peg.btcLockSender.BtcLockSender; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; import co.rsk.peg.pegininstructions.PeginInstructionsException; diff --git a/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java b/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java index b09687c84..64e0dcc8d 100644 --- a/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java +++ b/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java @@ -56,11 +56,8 @@ import co.rsk.federate.signing.hsm.requirements.ReleaseRequirementsEnforcerException; import co.rsk.federate.signing.utils.TestUtils; import co.rsk.net.NodeBlockProcessor; -import co.rsk.peg.Federation; -import co.rsk.peg.StandardMultisigFederation; -import co.rsk.peg.ErpFederation; -import co.rsk.peg.LegacyErpFederation; -import co.rsk.peg.FederationMember; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.ErpFederation; import co.rsk.peg.StateForFederator; import java.math.BigInteger; @@ -74,6 +71,9 @@ import java.util.TreeMap; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; + +import co.rsk.peg.federation.FederationFactory; +import co.rsk.peg.federation.FederationMember; import org.ethereum.config.Constants; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.core.Block; @@ -598,7 +598,7 @@ void validateTxCanBeSigned_fast_bridge_ok() throws Exception { @Test void validateTxCanBeSigned_erp_fed_ok() throws Exception { Federation federation = TestUtils.createFederation(params, 3); - ErpFederation erpFederation = new LegacyErpFederation( + ErpFederation erpFederation = FederationFactory.buildNonStandardErpFederation( federation.getMembers(), federation.getCreationTime(), federation.getCreationBlockNumber(), @@ -622,7 +622,7 @@ void validateTxCanBeSigned_federatorAlreadySigned() throws Exception { // Arrange BtcECKey federator1PrivKey = new BtcECKey(); BtcECKey federator2PrivKey = new BtcECKey(); - Federation federation = new StandardMultisigFederation( + Federation federation = FederationFactory.buildStandardMultiSigFederation( FederationMember.getFederationMembersFromKeys(Arrays.asList(federator1PrivKey, federator2PrivKey)), Instant.now(), 0, @@ -720,7 +720,7 @@ void removeSignaturesFromTransaction() { // Arrange BtcECKey federator1PrivKey = new BtcECKey(); BtcECKey federator2PrivKey = new BtcECKey(); - Federation federation = new StandardMultisigFederation( + Federation federation = FederationFactory.buildStandardMultiSigFederation( FederationMember.getFederationMembersFromKeys(Arrays.asList(federator1PrivKey, federator2PrivKey)), Instant.now(), 0, @@ -798,7 +798,7 @@ void extractStandardRedeemScript_fast_bridge_redeem_script() { void extractStandardRedeemScript_erp_redeem_script() { Federation federation = TestUtils.createFederation(params, 1); - ErpFederation erpFederation = new LegacyErpFederation( + ErpFederation erpFederation = FederationFactory.buildNonStandardErpFederation( federation.getMembers(), federation.getCreationTime(), federation.getCreationBlockNumber(), @@ -1056,7 +1056,7 @@ private Federation createFederation(List btcECKeyList) { new FederationMember(btcECKey, new ECKey(), new ECKey())) ); - return new StandardMultisigFederation( + return FederationFactory.buildStandardMultiSigFederation( federationMembers, Instant.now(), 0L, diff --git a/src/test/java/co/rsk/federate/mock/SimpleBitcoinWrapper.java b/src/test/java/co/rsk/federate/mock/SimpleBitcoinWrapper.java index f8297f8d0..0f342ebcf 100644 --- a/src/test/java/co/rsk/federate/mock/SimpleBitcoinWrapper.java +++ b/src/test/java/co/rsk/federate/mock/SimpleBitcoinWrapper.java @@ -3,7 +3,7 @@ import co.rsk.federate.bitcoin.BitcoinWrapper; import co.rsk.federate.bitcoin.BlockListener; import co.rsk.federate.bitcoin.TransactionListener; -import co.rsk.peg.Federation; +import co.rsk.peg.federation.Federation; import java.util.HashMap; import java.util.HashSet; import java.util.List; diff --git a/src/test/java/co/rsk/federate/signing/hsm/message/PowHSMSignerMessageBuilderTest.java b/src/test/java/co/rsk/federate/signing/hsm/message/PowHSMSignerMessageBuilderTest.java index 1709947ed..fb3d71e21 100644 --- a/src/test/java/co/rsk/federate/signing/hsm/message/PowHSMSignerMessageBuilderTest.java +++ b/src/test/java/co/rsk/federate/signing/hsm/message/PowHSMSignerMessageBuilderTest.java @@ -17,7 +17,7 @@ import co.rsk.config.BridgeRegTestConstants; import co.rsk.core.bc.BlockHashesHelper; import co.rsk.crypto.Keccak256; -import co.rsk.peg.Federation; +import co.rsk.peg.federation.Federation; import co.rsk.trie.Trie; import java.util.Collections; import java.util.List; diff --git a/src/test/java/co/rsk/federate/signing/hsm/message/SignerMessageBuilderV1Test.java b/src/test/java/co/rsk/federate/signing/hsm/message/SignerMessageBuilderV1Test.java index bb6fc68c1..4378a0ba4 100644 --- a/src/test/java/co/rsk/federate/signing/hsm/message/SignerMessageBuilderV1Test.java +++ b/src/test/java/co/rsk/federate/signing/hsm/message/SignerMessageBuilderV1Test.java @@ -10,7 +10,7 @@ import co.rsk.bitcoinj.params.RegTestParams; import co.rsk.bitcoinj.script.Script; import co.rsk.config.BridgeRegTestConstants; -import co.rsk.peg.Federation; +import co.rsk.peg.federation.Federation; import org.junit.jupiter.api.Test; class SignerMessageBuilderV1Test { diff --git a/src/test/java/co/rsk/federate/signing/utils/TestUtils.java b/src/test/java/co/rsk/federate/signing/utils/TestUtils.java index 9b8f660fb..fe4d73083 100644 --- a/src/test/java/co/rsk/federate/signing/utils/TestUtils.java +++ b/src/test/java/co/rsk/federate/signing/utils/TestUtils.java @@ -15,9 +15,13 @@ import co.rsk.bitcoinj.wallet.RedeemData; import co.rsk.core.BlockDifficulty; import co.rsk.crypto.Keccak256; -import co.rsk.peg.Federation; -import co.rsk.peg.FederationMember; -import co.rsk.peg.StandardMultisigFederation; +import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationFactory; +import co.rsk.peg.federation.FederationMember; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.ethereum.core.Block; +import org.ethereum.core.BlockHeader; + import java.lang.reflect.Field; import java.math.BigInteger; import java.security.SecureRandom; @@ -26,9 +30,6 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.ethereum.core.Block; -import org.ethereum.core.BlockHeader; public class TestUtils { @@ -87,11 +88,11 @@ public static Block mockBlockWithUncles(long number, Keccak256 hash, long diffic public static Federation createFederation(NetworkParameters params, int amountOfMembers) { List keys = Stream.generate(BtcECKey::new).limit(amountOfMembers).collect(Collectors.toList()); - return new StandardMultisigFederation( - FederationMember.getFederationMembersFromKeys(keys), - Instant.now(), - 0, - params + return FederationFactory.buildStandardMultiSigFederation( + FederationMember.getFederationMembersFromKeys(keys), + Instant.now(), + 0, + params ); } From b343e35fe5b896fc0239b4ff26abe79c805fd9d9 Mon Sep 17 00:00:00 2001 From: julia zack Date: Tue, 12 Dec 2023 13:25:38 -0300 Subject: [PATCH 05/11] Remove unused standard multisig and non standard feds format versions. Reorganize imports --- ...FederationProviderFromFederatorSupportTest.java | 3 --- .../co/rsk/federate/signing/utils/TestUtils.java | 14 +++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java index 6229c7f7e..9624af00d 100644 --- a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java +++ b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java @@ -35,9 +35,6 @@ class FederationProviderFromFederatorSupportTest { private BridgeConstants bridgeConstants; private NetworkParameters testnetParams; private Instant creationTime; - - private static final int STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION = FederationFormatVersion.STANDARD_MULTISIG_FEDERATION.getFormatVersion(); - private static final int NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION = FederationFormatVersion.NON_STANDARD_ERP_FEDERATION.getFormatVersion(); private static final int P2SH_ERP_FEDERATION_FORMAT_VERSION = FederationFormatVersion.P2SH_ERP_FEDERATION.getFormatVersion(); private static final Address HARDCODED_TESTNET_FED_ADDRESS = Address.fromBase58( diff --git a/src/test/java/co/rsk/federate/signing/utils/TestUtils.java b/src/test/java/co/rsk/federate/signing/utils/TestUtils.java index fe4d73083..67bf1d1de 100644 --- a/src/test/java/co/rsk/federate/signing/utils/TestUtils.java +++ b/src/test/java/co/rsk/federate/signing/utils/TestUtils.java @@ -18,9 +18,6 @@ import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.FederationFactory; import co.rsk.peg.federation.FederationMember; -import org.apache.commons.lang3.reflect.FieldUtils; -import org.ethereum.core.Block; -import org.ethereum.core.BlockHeader; import java.lang.reflect.Field; import java.math.BigInteger; @@ -30,6 +27,9 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.ethereum.core.Block; +import org.ethereum.core.BlockHeader; public class TestUtils { @@ -89,10 +89,10 @@ public static Federation createFederation(NetworkParameters params, int amountOf List keys = Stream.generate(BtcECKey::new).limit(amountOfMembers).collect(Collectors.toList()); return FederationFactory.buildStandardMultiSigFederation( - FederationMember.getFederationMembersFromKeys(keys), - Instant.now(), - 0, - params + FederationMember.getFederationMembersFromKeys(keys), + Instant.now(), + 0, + params ); } From 6a6e4e05e35a42dc1b5d8fd4fff328dcda67531b Mon Sep 17 00:00:00 2001 From: julia zack Date: Tue, 12 Dec 2023 14:50:59 -0300 Subject: [PATCH 06/11] Use fed format version for standard and non-standard feds --- ...ationProviderFromFederatorSupportTest.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java index 9624af00d..06ed6adb4 100644 --- a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java +++ b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java @@ -35,6 +35,9 @@ class FederationProviderFromFederatorSupportTest { private BridgeConstants bridgeConstants; private NetworkParameters testnetParams; private Instant creationTime; + + private static final int STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION = FederationFormatVersion.STANDARD_MULTISIG_FEDERATION.getFormatVersion(); + private static final int NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION = FederationFormatVersion.NON_STANDARD_ERP_FEDERATION.getFormatVersion(); private static final int P2SH_ERP_FEDERATION_FORMAT_VERSION = FederationFormatVersion.P2SH_ERP_FEDERATION.getFormatVersion(); private static final Address HARDCODED_TESTNET_FED_ADDRESS = Address.fromBase58( @@ -79,7 +82,7 @@ void getActiveFederation_beforeMultikey() { Federation obtainedFederation = federationProvider.getActiveFederation(); - assertTrue(obtainedFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, obtainedFederation.getFormatVersion()); assertEquals(expectedFederation, obtainedFederation); assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @@ -108,7 +111,7 @@ void getActiveFederation_afterMultikey() { Federation obtainedFederation = federationProvider.getActiveFederation(); - assertTrue(obtainedFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, obtainedFederation.getFormatVersion()); assertEquals(expectedFederation, obtainedFederation); assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @@ -138,7 +141,7 @@ void getActiveFederation_erp_federation() { Federation obtainedFederation = federationProvider.getActiveFederation(); - assertTrue(obtainedFederation instanceof ErpFederation); + assertEquals(NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION, obtainedFederation.getFormatVersion()); assertEquals(expectedFederation, obtainedFederation); assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @@ -170,7 +173,7 @@ void getActiveFederation_erp_federation_testnet_hardcoded() { Federation obtainedFederation = federationProvider.getActiveFederation(); - assertTrue(obtainedFederation instanceof ErpFederation); + assertEquals(NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION, obtainedFederation.getFormatVersion()); assertEquals(expectedFederation, obtainedFederation); assertEquals(HARDCODED_TESTNET_FED_ADDRESS, obtainedFederation.getAddress()); assertEquals(HARDCODED_TESTNET_FED_REDEEM_SCRIPT, obtainedFederation.getRedeemScript()); @@ -259,7 +262,7 @@ void getRetiringFederation_present_beforeMultikey() { Federation obtainedFederation = obtainedFederationOptional.get(); - assertTrue(obtainedFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, obtainedFederation.getFormatVersion()); assertEquals(expectedFederation, obtainedFederation); assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @@ -291,7 +294,7 @@ void getRetiringFederation_present_afterMultikey() { Federation obtainedFederation = obtainedFederationOptional.get(); - assertTrue(obtainedFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, obtainedFederation.getFormatVersion()); assertEquals(expectedFederation, obtainedFederation); assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @@ -324,7 +327,7 @@ void getRetiringFederation_present_erp_federation() { Federation obtainedFederation = obtainedFederationOptional.get(); - assertTrue(obtainedFederation instanceof ErpFederation); + assertEquals(NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION, obtainedFederation.getFormatVersion()); assertEquals(expectedFederation, obtainedFederation); assertEquals(expectedFederationAddress, obtainedFederation.getAddress()); } @@ -387,7 +390,7 @@ void getLiveFederations_onlyActive_beforeMultikey() { assertEquals(1, liveFederations.size()); Federation activeFederation = liveFederations.get(0); - assertTrue(activeFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, activeFederation.getFormatVersion()); assertEquals(expectedActiveFederation, activeFederation); assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); } @@ -419,7 +422,7 @@ void getLiveFederations_onlyActive_afterMultikey() { assertEquals(1, liveFederations.size()); Federation activeFederation = liveFederations.get(0); - assertTrue(activeFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, activeFederation.getFormatVersion()); assertEquals(expectedActiveFederation, activeFederation); assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); } @@ -452,7 +455,7 @@ void getLiveFederations_onlyActive_erp_federation() { assertEquals(1, liveFederations.size()); Federation activeFederation = liveFederations.get(0); - assertTrue(activeFederation instanceof ErpFederation); + assertEquals(NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION, activeFederation.getFormatVersion()); assertEquals(expectedActiveFederation, activeFederation); assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); } @@ -528,12 +531,12 @@ void getLiveFederations_both_beforeMultikey() { assertEquals(2, liveFederations.size()); Federation activeFederation = liveFederations.get(0); - assertTrue(activeFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, activeFederation.getFormatVersion()); assertEquals(expectedActiveFederation, activeFederation); assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); Federation retiringFederation = liveFederations.get(1); - assertTrue(retiringFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, retiringFederation.getFormatVersion()); assertEquals(expectedRetiringFederation, retiringFederation); assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } @@ -580,12 +583,12 @@ void getLiveFederations_both_afterMultikey() { assertEquals(2, liveFederations.size()); Federation activeFederation = liveFederations.get(0); - assertTrue(activeFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, activeFederation.getFormatVersion()); assertEquals(expectedActiveFederation, activeFederation); assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); Federation retiringFederation = liveFederations.get(1); - assertTrue(retiringFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, retiringFederation.getFormatVersion()); assertEquals(expectedRetiringFederation, retiringFederation); assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } @@ -634,12 +637,12 @@ void getLiveFederations_both_erp_federations() { assertEquals(2, liveFederations.size()); Federation activeFederation = liveFederations.get(0); - assertTrue(activeFederation instanceof ErpFederation); + assertEquals(NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION, activeFederation.getFormatVersion()); assertEquals(expectedActiveFederation, activeFederation); assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); Federation retiringFederation = liveFederations.get(1); - assertTrue(retiringFederation instanceof ErpFederation); + assertEquals(NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION, retiringFederation.getFormatVersion()); assertEquals(expectedRetiringFederation, retiringFederation); assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } @@ -687,12 +690,12 @@ void getLiveFederations_retiring_multikey_active_erp() { assertEquals(2, liveFederations.size()); Federation activeFederation = liveFederations.get(0); - assertTrue(activeFederation instanceof ErpFederation); + assertEquals(NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION, activeFederation.getFormatVersion()); assertEquals(expectedActiveFederation, activeFederation); assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); Federation retiringFederation = liveFederations.get(1); - assertTrue(retiringFederation instanceof Federation); + assertEquals(STANDARD_MULTISIG_FEDERATION_FORMAT_VERSION, retiringFederation.getFormatVersion()); assertEquals(expectedRetiringFederation, retiringFederation); assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } @@ -746,7 +749,7 @@ void getLiveFederations_retiring_erp_active_p2sh_erp() { assertEquals(expectedActiveFederationAddress, activeFederation.getAddress()); Federation retiringFederation = liveFederations.get(1); - assertTrue(retiringFederation instanceof ErpFederation); + assertEquals(NON_STANDARD_ERP_FEDERATION_FORMAT_VERSION, retiringFederation.getFormatVersion()); assertEquals(expectedRetiringFederation, retiringFederation); assertEquals(expectedRetiringFederationAddress, retiringFederation.getAddress()); } From 413c97c79943b2dea6b1c559832c5dc9d0d276c8 Mon Sep 17 00:00:00 2001 From: julia zack Date: Thu, 14 Dec 2023 12:13:08 -0300 Subject: [PATCH 07/11] Create method in BtcReleaseClient to extract default redeem script instead of using instanceof --- .../federate/btcreleaseclient/BtcReleaseClient.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java b/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java index c8be063ce..f8ff3b06e 100644 --- a/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java +++ b/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java @@ -352,7 +352,7 @@ protected void validateTxCanBeSigned(BtcTransaction btcTx) throws FederatorAlrea observedFederations.stream() .forEach(f -> logger.trace("[validateTxCanBeSigned] federation p2sh redeem script {}", f.getRedeemScript())); List spendingFedFilter = observedFederations.stream() - .filter(f -> (f instanceof ErpFederation ? ((ErpFederation) f).getDefaultRedeemScript() : f.getRedeemScript()).equals(standardRedeemScript)).collect(Collectors.toList()); + .filter(f -> (extractDefaultRedeemScript(f)).equals(standardRedeemScript)).collect(Collectors.toList()); logger.debug("[validateTxCanBeSigned] spendingFedFilter size {}", spendingFedFilter.size()); if (spendingFedFilter.isEmpty()) { String message = String.format( @@ -451,6 +451,13 @@ protected Script extractStandardRedeemScript(Script redeemScript) { return parser.extractStandardRedeemScript(); } + protected Script extractDefaultRedeemScript(Federation federation) { + if (federation instanceof ErpFederation) { + return ((ErpFederation) federation).getDefaultRedeemScript(); + } + return federation.getRedeemScript(); + } + protected Script getRedeemScriptFromInput(TransactionInput txInput) { Script inputScript = txInput.getScriptSig(); List chunks = inputScript.getChunks(); @@ -464,7 +471,8 @@ protected Federation getSpendingFederation(BtcTransaction btcTx) { Script redeemScript = extractStandardRedeemScript(getRedeemScriptFromInput(firstInput)); List spendingFedFilter = observedFederations.stream() - .filter(f -> (f instanceof ErpFederation ? ((ErpFederation) f).getDefaultRedeemScript() : f.getRedeemScript()).equals(redeemScript)).collect(Collectors.toList()); + .filter(f -> (extractDefaultRedeemScript(f)).equals(redeemScript)).collect(Collectors.toList()); + return spendingFedFilter.get(0); } From 20796ec98a33920c006da6e1610068fa9661f723 Mon Sep 17 00:00:00 2001 From: julia zack Date: Thu, 14 Dec 2023 20:12:32 -0300 Subject: [PATCH 08/11] Make extractDefaultRedeemScript method private instead of protected --- .../java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java b/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java index f8ff3b06e..ae82ab092 100644 --- a/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java +++ b/src/main/java/co/rsk/federate/btcreleaseclient/BtcReleaseClient.java @@ -451,7 +451,7 @@ protected Script extractStandardRedeemScript(Script redeemScript) { return parser.extractStandardRedeemScript(); } - protected Script extractDefaultRedeemScript(Federation federation) { + private Script extractDefaultRedeemScript(Federation federation) { if (federation instanceof ErpFederation) { return ((ErpFederation) federation).getDefaultRedeemScript(); } From 49fa36cd5a653f959942e57d059e8e98c806cc24 Mon Sep 17 00:00:00 2001 From: julia zack Date: Wed, 10 Jan 2024 14:42:44 -0300 Subject: [PATCH 09/11] Adapt to federation args creation --- ...ederationProviderFromFederatorSupport.java | 63 ++++++++----------- ...ationProviderFromFederatorSupportTest.java | 57 +++++++---------- .../rsk/federate/FederationWatcherTest.java | 38 ++++++----- .../BtcReleaseClientTest.java | 63 ++++++------------- .../rsk/federate/signing/utils/TestUtils.java | 10 ++- 5 files changed, 92 insertions(+), 139 deletions(-) diff --git a/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java b/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java index 135359c6d..371196a4f 100644 --- a/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java +++ b/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java @@ -20,10 +20,10 @@ import co.rsk.bitcoinj.core.Address; import co.rsk.bitcoinj.core.BtcECKey; +import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.config.BridgeConstants; -import co.rsk.peg.federation.Federation; -import co.rsk.peg.federation.FederationFactory; -import co.rsk.peg.federation.FederationMember; +import co.rsk.peg.federation.*; +import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.crypto.ECKey; import java.time.Instant; @@ -74,13 +74,10 @@ public Federation getActiveFederation() { } Instant creationTime = federatorSupport.getFederationCreationTime(); long creationBlockNumber = federatorSupport.getFederationCreationBlockNumber(); + NetworkParameters btcParams = federatorSupport.getBtcParams(); + FederationArgs federationArgs = new FederationArgs(members, creationTime, creationBlockNumber, btcParams); - Federation initialFederation = FederationFactory.buildStandardMultiSigFederation( - members, - creationTime, - creationBlockNumber, - federatorSupport.getBtcParams() - ); + Federation initialFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs); return getExpectedFederation(initialFederation, getActiveFederationAddress()); } @@ -124,13 +121,10 @@ public Optional getRetiringFederation() { Instant creationTime = federatorSupport.getRetiringFederationCreationTime(); long creationBlockNumber = federatorSupport.getRetiringFederationCreationBlockNumber(); + NetworkParameters btcParams = federatorSupport.getBtcParams(); + FederationArgs federationArgs = new FederationArgs(members, creationTime, creationBlockNumber, btcParams); - Federation initialFederation = FederationFactory.buildStandardMultiSigFederation( - members, - creationTime, - creationBlockNumber, - federatorSupport.getBtcParams() - ); + Federation initialFederation = FederationFactory.buildStandardMultiSigFederation(federationArgs); return Optional.of(getExpectedFederation(initialFederation, retiringFederationAddress)); } @@ -156,31 +150,26 @@ private Federation getExpectedFederation(Federation initialFederation, Address e if (initialFederation.getAddress().equals(expectedFederationAddress)) { return initialFederation; } - - // If addresses do not match build an ERP federation - Federation erpFederation = FederationFactory.buildNonStandardErpFederation( - initialFederation.getMembers(), - initialFederation.getCreationTime(), - initialFederation.getCreationBlockNumber(), - federatorSupport.getBtcParams(), - bridgeConstants.getErpFedPubKeysList(), - bridgeConstants.getErpFedActivationDelay(), - federatorSupport.getConfigForBestBlock() - ); - - if (erpFederation.getAddress().equals(expectedFederationAddress)) { - return erpFederation; + List members = initialFederation.getMembers(); + Instant creationTime = initialFederation.getCreationTime(); + long creationBlockNumber = initialFederation.getCreationBlockNumber(); + NetworkParameters btcParams = federatorSupport.getBtcParams(); + List erpPubKeys = bridgeConstants.getErpFedPubKeysList(); + long activationDelay = bridgeConstants.getErpFedActivationDelay(); + ActivationConfig.ForBlock activations = federatorSupport.getConfigForBestBlock(); + + ErpFederationArgs erpFederationArgs = + new ErpFederationArgs(members, creationTime, creationBlockNumber, btcParams, erpPubKeys, activationDelay); + + // If addresses match build a Non-Standard ERP federation + ErpFederation nonStandardErpFederation = FederationFactory.buildNonStandardErpFederation(erpFederationArgs, activations); + + if (nonStandardErpFederation.getAddress().equals(expectedFederationAddress)) { + return nonStandardErpFederation; } // Finally, try building a P2SH ERP federation - return FederationFactory.buildP2shErpFederation( - initialFederation.getMembers(), - initialFederation.getCreationTime(), - initialFederation.getCreationBlockNumber(), - federatorSupport.getBtcParams(), - bridgeConstants.getErpFedPubKeysList(), - bridgeConstants.getErpFedActivationDelay() - ); + return FederationFactory.buildP2shErpFederation(erpFederationArgs); // TODO: what if no federation built matches the expected address? // It could mean that there is a different type of federation in the Bridge that we are not considering here diff --git a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java index 06ed6adb4..2bc829f6e 100644 --- a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java +++ b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java @@ -121,7 +121,7 @@ void getActiveFederation_erp_federation() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); - Federation expectedFederation = createErpFederation( + Federation expectedFederation = createNonStandardErpFederation( getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), configMock ); @@ -152,7 +152,7 @@ void getActiveFederation_erp_federation_testnet_hardcoded() { when(configMock.isActive(RSKIP123)).thenReturn(true); when(configMock.isActive(RSKIP284)).thenReturn(false); - Federation expectedFederation = createErpFederation( + Federation expectedFederation = createNonStandardErpFederation( getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), configMock ); @@ -304,7 +304,7 @@ void getRetiringFederation_present_erp_federation() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); - Federation expectedFederation = createErpFederation( + Federation expectedFederation = createNonStandardErpFederation( getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), configMock ); @@ -432,7 +432,7 @@ void getLiveFederations_onlyActive_erp_federation() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); - Federation expectedActiveFederation = createErpFederation( + Federation expectedActiveFederation = createNonStandardErpFederation( getFederationMembersFromPks(1,1000, 2000, 3000, 4000), configMock ); @@ -598,13 +598,13 @@ void getLiveFederations_both_erp_federations() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); - Federation expectedActiveFederation = createErpFederation( + Federation expectedActiveFederation = createNonStandardErpFederation( getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), configMock ); Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); - Federation expectedRetiringFederation = createErpFederation( + Federation expectedRetiringFederation = createNonStandardErpFederation( getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000), configMock ); @@ -652,7 +652,7 @@ void getLiveFederations_retiring_multikey_active_erp() { ActivationConfig.ForBlock configMock = mock(ActivationConfig.ForBlock.class); when(configMock.isActive(RSKIP123)).thenReturn(true); - Federation expectedActiveFederation = createErpFederation( + Federation expectedActiveFederation = createNonStandardErpFederation( getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), configMock ); @@ -711,7 +711,7 @@ void getLiveFederations_retiring_erp_active_p2sh_erp() { ); Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); - Federation expectedRetiringFederation = createErpFederation( + Federation expectedRetiringFederation = createNonStandardErpFederation( getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000), configMock ); @@ -809,35 +809,26 @@ void getLiveFederations_both_p2sh_erp_federations() { } private Federation createFederation(List members) { - return FederationFactory.buildStandardMultiSigFederation( - members, - creationTime, - 0L, - testnetParams - ); + FederationArgs federationArgs = new FederationArgs(members, creationTime, 0L, testnetParams); + return FederationFactory.buildStandardMultiSigFederation(federationArgs); } - private Federation createErpFederation(List members, ActivationConfig.ForBlock activations) { - return FederationFactory.buildNonStandardErpFederation( - members, - creationTime, - 0L, - testnetParams, - bridgeConstants.getErpFedPubKeysList(), - bridgeConstants.getErpFedActivationDelay(), - activations - ); + private ErpFederation createNonStandardErpFederation(List members, ActivationConfig.ForBlock activations) { + List erpPubKeys = bridgeConstants.getErpFedPubKeysList(); + long activationDelay = bridgeConstants.getErpFedActivationDelay(); + ErpFederationArgs erpFederationArgs = + new ErpFederationArgs(members, creationTime, 0L, testnetParams, erpPubKeys, activationDelay); + + return FederationFactory.buildNonStandardErpFederation(erpFederationArgs, activations); } - private Federation createP2shErpFederation(List members, ActivationConfig.ForBlock activations) { - return FederationFactory.buildP2shErpFederation( - members, - creationTime, - 0L, - testnetParams, - bridgeConstants.getErpFedPubKeysList(), - bridgeConstants.getErpFedActivationDelay() - ); + private ErpFederation createP2shErpFederation(List members, ActivationConfig.ForBlock activations) { + List erpPubKeys = bridgeConstants.getErpFedPubKeysList(); + long activationDelay = bridgeConstants.getErpFedActivationDelay(); + ErpFederationArgs erpFederationArgs = + new ErpFederationArgs(members, creationTime, 0L, testnetParams, erpPubKeys, activationDelay); + + return FederationFactory.buildP2shErpFederation(erpFederationArgs); } private List getFederationMembersFromPks(int offset, Integer... pks) { diff --git a/src/test/java/co/rsk/federate/FederationWatcherTest.java b/src/test/java/co/rsk/federate/FederationWatcherTest.java index c58bdae49..7c9119778 100644 --- a/src/test/java/co/rsk/federate/FederationWatcherTest.java +++ b/src/test/java/co/rsk/federate/FederationWatcherTest.java @@ -14,6 +14,7 @@ import co.rsk.bitcoinj.core.NetworkParameters; import co.rsk.federate.signing.utils.TestUtils; import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationArgs; import co.rsk.peg.federation.FederationFactory; import co.rsk.peg.federation.FederationMember; import java.math.BigInteger; @@ -31,26 +32,23 @@ import org.mockito.invocation.InvocationOnMock; class FederationWatcherTest { - private final Federation federation1 = FederationFactory.buildStandardMultiSigFederation( - getFederationMembersFromPksForBtc(1000, 2000, 3000, 4000), - Instant.ofEpochMilli(5005L), - 0L, - NetworkParameters.fromID(NetworkParameters.ID_REGTEST) - ); - - private final Federation federation2 = FederationFactory.buildStandardMultiSigFederation( - getFederationMembersFromPksForBtc(2000, 3000, 4000, 5000, 6000, 7000), - Instant.ofEpochMilli(15300L), - 0L, - NetworkParameters.fromID(NetworkParameters.ID_REGTEST) - ); - - private final Federation federation3 = FederationFactory.buildStandardMultiSigFederation( - getFederationMembersFromPksForBtc(5000, 6000, 7000), - Instant.ofEpochMilli(7400L), - 0L, - NetworkParameters.fromID(NetworkParameters.ID_REGTEST) - ); + List federation1Members = getFederationMembersFromPksForBtc(1000, 2000, 3000, 4000); + Instant federation1CreationTime = Instant.ofEpochMilli(5005L); + long creationBlockNumber = 0L; + NetworkParameters btcParams = NetworkParameters.fromID(NetworkParameters.ID_REGTEST); + + FederationArgs federation1Args = new FederationArgs(federation1Members, federation1CreationTime, creationBlockNumber, btcParams); + private final Federation federation1 = FederationFactory.buildStandardMultiSigFederation(federation1Args); + + List federation2Members = getFederationMembersFromPksForBtc(2000, 3000, 4000, 5000, 6000, 7000); + Instant federation2CreationTime = Instant.ofEpochMilli(15300L); + FederationArgs federation2Args = new FederationArgs(federation2Members, federation2CreationTime, creationBlockNumber, btcParams); + private final Federation federation2 = FederationFactory.buildStandardMultiSigFederation(federation2Args); + + List federation3Members = getFederationMembersFromPksForBtc(5000, 6000, 7000); + Instant federation3CreationTime = Instant.ofEpochMilli(7400L); + FederationArgs federation3Args = new FederationArgs(federation3Members, federation3CreationTime, creationBlockNumber, btcParams); + private final Federation federation3 = FederationFactory.buildStandardMultiSigFederation(federation3Args); private FederationProvider federationProvider; private Ethereum ethereumMock; diff --git a/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java b/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java index 64e0dcc8d..b34b32c96 100644 --- a/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java +++ b/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java @@ -56,8 +56,7 @@ import co.rsk.federate.signing.hsm.requirements.ReleaseRequirementsEnforcerException; import co.rsk.federate.signing.utils.TestUtils; import co.rsk.net.NodeBlockProcessor; -import co.rsk.peg.federation.Federation; -import co.rsk.peg.federation.ErpFederation; +import co.rsk.peg.federation.*; import co.rsk.peg.StateForFederator; import java.math.BigInteger; @@ -72,8 +71,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; -import co.rsk.peg.federation.FederationFactory; -import co.rsk.peg.federation.FederationMember; import org.ethereum.config.Constants; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.core.Block; @@ -598,23 +595,17 @@ void validateTxCanBeSigned_fast_bridge_ok() throws Exception { @Test void validateTxCanBeSigned_erp_fed_ok() throws Exception { Federation federation = TestUtils.createFederation(params, 3); - ErpFederation erpFederation = FederationFactory.buildNonStandardErpFederation( - federation.getMembers(), - federation.getCreationTime(), - federation.getCreationBlockNumber(), - params, - erpFedKeys, - 5063, - mock(ActivationConfig.ForBlock.class) - ); + FederationArgs federationArgs = federation.getArgs(); + ErpFederationArgs erpFederationArgs = ErpFederationArgs.fromFederationArgs(federationArgs, erpFedKeys, 5063); + ErpFederation nonStandardErpFederation = FederationFactory.buildNonStandardErpFederation(erpFederationArgs, mock(ActivationConfig.ForBlock.class)); // Create a tx from the Fed to a random btc address BtcTransaction releaseTx = createReleaseTxAndAddInput(federation); - BtcECKey fed1Key = erpFederation.getBtcPublicKeys().get(0); + BtcECKey fed1Key = nonStandardErpFederation.getBtcPublicKeys().get(0); ECPublicKey signerPublicKey = new ECPublicKey(fed1Key.getPubKey()); - test_validateTxCanBeSigned(erpFederation, releaseTx, signerPublicKey); + test_validateTxCanBeSigned(nonStandardErpFederation, releaseTx, signerPublicKey); } @Test @@ -622,12 +613,10 @@ void validateTxCanBeSigned_federatorAlreadySigned() throws Exception { // Arrange BtcECKey federator1PrivKey = new BtcECKey(); BtcECKey federator2PrivKey = new BtcECKey(); - Federation federation = FederationFactory.buildStandardMultiSigFederation( - FederationMember.getFederationMembersFromKeys(Arrays.asList(federator1PrivKey, federator2PrivKey)), - Instant.now(), - 0, - params - ); + List fedMembers = FederationMember.getFederationMembersFromKeys(Arrays.asList(federator1PrivKey, federator2PrivKey)); + FederationArgs federationArgs = new FederationArgs(fedMembers, Instant.now(), 0, params); + + Federation federation = FederationFactory.buildStandardMultiSigFederation(federationArgs); // Create a tx from the Fed to a random btc address BtcTransaction releaseTx = new BtcTransaction(params); @@ -720,12 +709,10 @@ void removeSignaturesFromTransaction() { // Arrange BtcECKey federator1PrivKey = new BtcECKey(); BtcECKey federator2PrivKey = new BtcECKey(); - Federation federation = FederationFactory.buildStandardMultiSigFederation( - FederationMember.getFederationMembersFromKeys(Arrays.asList(federator1PrivKey, federator2PrivKey)), - Instant.now(), - 0, - params - ); + List fedMembers = FederationMember.getFederationMembersFromKeys(Arrays.asList(federator1PrivKey, federator2PrivKey)); + FederationArgs federationArgs = new FederationArgs(fedMembers, Instant.now(), 0, params); + + Federation federation = FederationFactory.buildStandardMultiSigFederation(federationArgs); // Create a tx from the Fed to a random btc address BtcTransaction releaseTx = new BtcTransaction(params); @@ -797,18 +784,12 @@ void extractStandardRedeemScript_fast_bridge_redeem_script() { @Test void extractStandardRedeemScript_erp_redeem_script() { Federation federation = TestUtils.createFederation(params, 1); + FederationArgs federationArgs = federation.getArgs(); + ErpFederationArgs erpFederationArgs = ErpFederationArgs.fromFederationArgs(federationArgs, erpFedKeys, 5063); - ErpFederation erpFederation = FederationFactory.buildNonStandardErpFederation( - federation.getMembers(), - federation.getCreationTime(), - federation.getCreationBlockNumber(), - params, - erpFedKeys, - 5063, - mock(ActivationConfig.ForBlock.class) - ); + ErpFederation nonStandardErpFederation = FederationFactory.buildNonStandardErpFederation(erpFederationArgs, mock(ActivationConfig.ForBlock.class)); - test_extractStandardRedeemScript(federation.getRedeemScript(), erpFederation.getRedeemScript()); + test_extractStandardRedeemScript(federation.getRedeemScript(), nonStandardErpFederation.getRedeemScript()); } @Test @@ -1055,12 +1036,8 @@ private Federation createFederation(List btcECKeyList) { btcECKeyList.forEach(btcECKey -> federationMembers.add( new FederationMember(btcECKey, new ECKey(), new ECKey())) ); + FederationArgs federationArgs = new FederationArgs(federationMembers, Instant.now(), 0L, params); - return FederationFactory.buildStandardMultiSigFederation( - federationMembers, - Instant.now(), - 0L, - params - ); + return FederationFactory.buildStandardMultiSigFederation(federationArgs); } } diff --git a/src/test/java/co/rsk/federate/signing/utils/TestUtils.java b/src/test/java/co/rsk/federate/signing/utils/TestUtils.java index 67bf1d1de..eafc1d70b 100644 --- a/src/test/java/co/rsk/federate/signing/utils/TestUtils.java +++ b/src/test/java/co/rsk/federate/signing/utils/TestUtils.java @@ -16,6 +16,7 @@ import co.rsk.core.BlockDifficulty; import co.rsk.crypto.Keccak256; import co.rsk.peg.federation.Federation; +import co.rsk.peg.federation.FederationArgs; import co.rsk.peg.federation.FederationFactory; import co.rsk.peg.federation.FederationMember; @@ -87,13 +88,10 @@ public static Block mockBlockWithUncles(long number, Keccak256 hash, long diffic public static Federation createFederation(NetworkParameters params, int amountOfMembers) { List keys = Stream.generate(BtcECKey::new).limit(amountOfMembers).collect(Collectors.toList()); + List members = FederationMember.getFederationMembersFromKeys(keys); + FederationArgs federationArgs = new FederationArgs(members, Instant.now(), 0, params); - return FederationFactory.buildStandardMultiSigFederation( - FederationMember.getFederationMembersFromKeys(keys), - Instant.now(), - 0, - params - ); + return FederationFactory.buildStandardMultiSigFederation(federationArgs); } public static TransactionInput createTransactionInput( From 6a155511485eab9b56575537bc0ee8085c2e618d Mon Sep 17 00:00:00 2001 From: julia zack Date: Mon, 15 Jan 2024 13:12:00 -0300 Subject: [PATCH 10/11] Adapt to removal of ErpFederationArgs. Remove unused activations field when creating a p2sh fed --- ...ederationProviderFromFederatorSupport.java | 9 +++--- ...ationProviderFromFederatorSupportTest.java | 32 ++++++++----------- .../BtcReleaseClientTest.java | 8 ++--- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java b/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java index 371196a4f..c6acdae59 100644 --- a/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java +++ b/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java @@ -158,18 +158,19 @@ private Federation getExpectedFederation(Federation initialFederation, Address e long activationDelay = bridgeConstants.getErpFedActivationDelay(); ActivationConfig.ForBlock activations = federatorSupport.getConfigForBestBlock(); - ErpFederationArgs erpFederationArgs = - new ErpFederationArgs(members, creationTime, creationBlockNumber, btcParams, erpPubKeys, activationDelay); + FederationArgs federationArgs = + new FederationArgs(members, creationTime, creationBlockNumber, btcParams); // If addresses match build a Non-Standard ERP federation - ErpFederation nonStandardErpFederation = FederationFactory.buildNonStandardErpFederation(erpFederationArgs, activations); + ErpFederation nonStandardErpFederation = + FederationFactory.buildNonStandardErpFederation(federationArgs, erpPubKeys, activationDelay, activations); if (nonStandardErpFederation.getAddress().equals(expectedFederationAddress)) { return nonStandardErpFederation; } // Finally, try building a P2SH ERP federation - return FederationFactory.buildP2shErpFederation(erpFederationArgs); + return FederationFactory.buildP2shErpFederation(federationArgs, erpPubKeys, activationDelay); // TODO: what if no federation built matches the expected address? // It could mean that there is a different type of federation in the Bridge that we are not considering here diff --git a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java index 2bc829f6e..059f76270 100644 --- a/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java +++ b/src/test/java/co/rsk/federate/FederationProviderFromFederatorSupportTest.java @@ -185,8 +185,7 @@ void getActiveFederation_p2sh_erp_federation() { when(configMock.isActive(RSKIP123)).thenReturn(true); Federation expectedFederation = createP2shErpFederation( - getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), - configMock + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000) ); Address expectedFederationAddress = expectedFederation.getAddress(); @@ -338,8 +337,7 @@ void getRetiringFederation_present_p2sh_erp_federation() { when(configMock.isActive(RSKIP123)).thenReturn(true); Federation expectedFederation = createP2shErpFederation( - getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), - configMock + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000) ); Address expectedFederationAddress = expectedFederation.getAddress(); @@ -466,8 +464,7 @@ void getLiveFederations_onlyActive_p2sh_erp_federation() { when(configMock.isActive(RSKIP123)).thenReturn(true); Federation expectedActiveFederation = createP2shErpFederation( - getFederationMembersFromPks(1,1000, 2000, 3000, 4000), - configMock + getFederationMembersFromPks(1,1000, 2000, 3000, 4000) ); Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); @@ -706,8 +703,7 @@ void getLiveFederations_retiring_erp_active_p2sh_erp() { when(configMock.isActive(RSKIP123)).thenReturn(true); Federation expectedActiveFederation = createP2shErpFederation( - getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), - configMock + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000) ); Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); @@ -760,14 +756,12 @@ void getLiveFederations_both_p2sh_erp_federations() { when(configMock.isActive(RSKIP123)).thenReturn(true); Federation expectedActiveFederation = createP2shErpFederation( - getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000), - configMock + getFederationMembersFromPks(1, 1000, 2000, 3000, 4000, 5000) ); Address expectedActiveFederationAddress = expectedActiveFederation.getAddress(); Federation expectedRetiringFederation = createP2shErpFederation( - getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000), - configMock + getFederationMembersFromPks(1,2000, 4000, 6000, 8000, 10000) ); Address expectedRetiringFederationAddress = expectedRetiringFederation.getAddress(); @@ -816,19 +810,19 @@ private Federation createFederation(List members) { private ErpFederation createNonStandardErpFederation(List members, ActivationConfig.ForBlock activations) { List erpPubKeys = bridgeConstants.getErpFedPubKeysList(); long activationDelay = bridgeConstants.getErpFedActivationDelay(); - ErpFederationArgs erpFederationArgs = - new ErpFederationArgs(members, creationTime, 0L, testnetParams, erpPubKeys, activationDelay); + FederationArgs federationArgs = + new FederationArgs(members, creationTime, 0L, testnetParams); - return FederationFactory.buildNonStandardErpFederation(erpFederationArgs, activations); + return FederationFactory.buildNonStandardErpFederation(federationArgs, erpPubKeys, activationDelay, activations); } - private ErpFederation createP2shErpFederation(List members, ActivationConfig.ForBlock activations) { + private ErpFederation createP2shErpFederation(List members) { List erpPubKeys = bridgeConstants.getErpFedPubKeysList(); long activationDelay = bridgeConstants.getErpFedActivationDelay(); - ErpFederationArgs erpFederationArgs = - new ErpFederationArgs(members, creationTime, 0L, testnetParams, erpPubKeys, activationDelay); + FederationArgs federationArgs = + new FederationArgs(members, creationTime, 0L, testnetParams); - return FederationFactory.buildP2shErpFederation(erpFederationArgs); + return FederationFactory.buildP2shErpFederation(federationArgs, erpPubKeys, activationDelay); } private List getFederationMembersFromPks(int offset, Integer... pks) { diff --git a/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java b/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java index b34b32c96..c550a7330 100644 --- a/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java +++ b/src/test/java/co/rsk/federate/btcreleaseclient/BtcReleaseClientTest.java @@ -596,8 +596,8 @@ void validateTxCanBeSigned_fast_bridge_ok() throws Exception { void validateTxCanBeSigned_erp_fed_ok() throws Exception { Federation federation = TestUtils.createFederation(params, 3); FederationArgs federationArgs = federation.getArgs(); - ErpFederationArgs erpFederationArgs = ErpFederationArgs.fromFederationArgs(federationArgs, erpFedKeys, 5063); - ErpFederation nonStandardErpFederation = FederationFactory.buildNonStandardErpFederation(erpFederationArgs, mock(ActivationConfig.ForBlock.class)); + ErpFederation nonStandardErpFederation = + FederationFactory.buildNonStandardErpFederation(federationArgs, erpFedKeys, 5063, mock(ActivationConfig.ForBlock.class)); // Create a tx from the Fed to a random btc address BtcTransaction releaseTx = createReleaseTxAndAddInput(federation); @@ -785,9 +785,9 @@ void extractStandardRedeemScript_fast_bridge_redeem_script() { void extractStandardRedeemScript_erp_redeem_script() { Federation federation = TestUtils.createFederation(params, 1); FederationArgs federationArgs = federation.getArgs(); - ErpFederationArgs erpFederationArgs = ErpFederationArgs.fromFederationArgs(federationArgs, erpFedKeys, 5063); - ErpFederation nonStandardErpFederation = FederationFactory.buildNonStandardErpFederation(erpFederationArgs, mock(ActivationConfig.ForBlock.class)); + ErpFederation nonStandardErpFederation = + FederationFactory.buildNonStandardErpFederation(federationArgs, erpFedKeys, 5063, mock(ActivationConfig.ForBlock.class)); test_extractStandardRedeemScript(federation.getRedeemScript(), nonStandardErpFederation.getRedeemScript()); } From 76703675582649cb062747797697f6b34325a682 Mon Sep 17 00:00:00 2001 From: julia zack Date: Fri, 19 Jan 2024 09:12:25 -0300 Subject: [PATCH 11/11] Remove extra line --- .../co/rsk/federate/FederationProviderFromFederatorSupport.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java b/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java index c6acdae59..6492c8a63 100644 --- a/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java +++ b/src/main/java/co/rsk/federate/FederationProviderFromFederatorSupport.java @@ -30,7 +30,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; - import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP123; /**