From d755081e2093c6b3f36806a0986a81c2957d901c Mon Sep 17 00:00:00 2001 From: julia-zack Date: Mon, 22 Apr 2024 11:59:40 +0200 Subject: [PATCH 01/12] Move ABI related classes to new /abi package. --- rskj-core/src/main/java/co/rsk/peg/Bridge.java | 1 + .../src/main/java/co/rsk/peg/BridgeSerializationUtils.java | 2 ++ rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java | 1 + rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java | 3 +++ .../src/main/java/co/rsk/peg/{ => abi}/ABICallElection.java | 3 ++- rskj-core/src/main/java/co/rsk/peg/{ => abi}/ABICallSpec.java | 2 +- .../src/main/java/co/rsk/peg/{ => abi}/ABICallVoteResult.java | 2 +- .../src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java | 2 ++ .../src/test/java/co/rsk/peg/BridgeStorageProviderTest.java | 2 ++ rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java | 1 + .../src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java | 2 ++ rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java | 1 + rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java | 1 + .../test/java/co/rsk/peg/{ => abi}/ABICallElectionTest.java | 3 ++- .../src/test/java/co/rsk/peg/{ => abi}/ABICallSpecTest.java | 2 +- .../test/java/co/rsk/peg/performance/FederationChangeTest.java | 2 ++ 16 files changed, 25 insertions(+), 5 deletions(-) rename rskj-core/src/main/java/co/rsk/peg/{ => abi}/ABICallElection.java (98%) rename rskj-core/src/main/java/co/rsk/peg/{ => abi}/ABICallSpec.java (99%) rename rskj-core/src/main/java/co/rsk/peg/{ => abi}/ABICallVoteResult.java (98%) rename rskj-core/src/test/java/co/rsk/peg/{ => abi}/ABICallElectionTest.java (99%) rename rskj-core/src/test/java/co/rsk/peg/{ => abi}/ABICallSpecTest.java (99%) diff --git a/rskj-core/src/main/java/co/rsk/peg/Bridge.java b/rskj-core/src/main/java/co/rsk/peg/Bridge.java index 68f9e4d5cba..a17dd804c7d 100644 --- a/rskj-core/src/main/java/co/rsk/peg/Bridge.java +++ b/rskj-core/src/main/java/co/rsk/peg/Bridge.java @@ -27,6 +27,7 @@ import co.rsk.crypto.Keccak256; import co.rsk.panic.PanicProcessor; import co.rsk.peg.BridgeMethods.BridgeMethodExecutor; +import co.rsk.peg.abi.ABICallSpec; import co.rsk.peg.bitcoin.MerkleBranch; import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.FederationMember; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java index 2faf18dcaea..3c8734e4054 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java @@ -23,6 +23,8 @@ import co.rsk.config.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; +import co.rsk.peg.abi.ABICallElection; +import co.rsk.peg.abi.ABICallSpec; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.federation.*; import co.rsk.peg.flyover.FlyoverFederationInformation; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java b/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java index e1891e4850b..5be247b46ab 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java @@ -23,6 +23,7 @@ import co.rsk.config.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; +import co.rsk.peg.abi.ABICallElection; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.PendingFederation; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java index 9a037612fc2..a5c1ebf2671 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -58,6 +58,9 @@ import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.panic.PanicProcessor; +import co.rsk.peg.abi.ABICallElection; +import co.rsk.peg.abi.ABICallSpec; +import co.rsk.peg.abi.ABICallVoteResult; import co.rsk.peg.bitcoin.BitcoinUtils; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.bitcoin.MerkleBranch; diff --git a/rskj-core/src/main/java/co/rsk/peg/ABICallElection.java b/rskj-core/src/main/java/co/rsk/peg/abi/ABICallElection.java similarity index 98% rename from rskj-core/src/main/java/co/rsk/peg/ABICallElection.java rename to rskj-core/src/main/java/co/rsk/peg/abi/ABICallElection.java index 1916c85fa7d..c25b36a8dd7 100644 --- a/rskj-core/src/main/java/co/rsk/peg/ABICallElection.java +++ b/rskj-core/src/main/java/co/rsk/peg/abi/ABICallElection.java @@ -16,9 +16,10 @@ * along with this program. If not, see . */ -package co.rsk.peg; +package co.rsk.peg.abi; import co.rsk.core.RskAddress; +import co.rsk.peg.AddressBasedAuthorizer; import java.util.*; diff --git a/rskj-core/src/main/java/co/rsk/peg/ABICallSpec.java b/rskj-core/src/main/java/co/rsk/peg/abi/ABICallSpec.java similarity index 99% rename from rskj-core/src/main/java/co/rsk/peg/ABICallSpec.java rename to rskj-core/src/main/java/co/rsk/peg/abi/ABICallSpec.java index a52ed9dde71..c3d70e6e824 100644 --- a/rskj-core/src/main/java/co/rsk/peg/ABICallSpec.java +++ b/rskj-core/src/main/java/co/rsk/peg/abi/ABICallSpec.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package co.rsk.peg; +package co.rsk.peg.abi; import com.google.common.primitives.SignedBytes; diff --git a/rskj-core/src/main/java/co/rsk/peg/ABICallVoteResult.java b/rskj-core/src/main/java/co/rsk/peg/abi/ABICallVoteResult.java similarity index 98% rename from rskj-core/src/main/java/co/rsk/peg/ABICallVoteResult.java rename to rskj-core/src/main/java/co/rsk/peg/abi/ABICallVoteResult.java index fda1416f98d..ec6dc44277d 100644 --- a/rskj-core/src/main/java/co/rsk/peg/ABICallVoteResult.java +++ b/rskj-core/src/main/java/co/rsk/peg/abi/ABICallVoteResult.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package co.rsk.peg; +package co.rsk.peg.abi; /** * Immutable representation of the result of a vote diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java index 1c1a1c8aa1d..893be75a520 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java @@ -25,6 +25,8 @@ import co.rsk.config.BridgeMainNetConstants; import co.rsk.config.BridgeTestNetConstants; import co.rsk.core.RskAddress; +import co.rsk.peg.abi.ABICallElection; +import co.rsk.peg.abi.ABICallSpec; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.federation.*; import co.rsk.peg.resources.TestConstants; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java index e26affbfeab..ac2c9181b46 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java @@ -27,6 +27,8 @@ import co.rsk.crypto.Keccak256; import co.rsk.db.MutableTrieCache; import co.rsk.db.MutableTrieImpl; +import co.rsk.peg.abi.ABICallElection; +import co.rsk.peg.abi.ABICallSpec; import co.rsk.peg.bitcoin.*; import co.rsk.peg.federation.*; import co.rsk.peg.flyover.FlyoverFederationInformation; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java index b15b588f6e4..88d4e709506 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java @@ -30,6 +30,7 @@ import co.rsk.config.BridgeTestNetConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; +import co.rsk.peg.abi.ABICallElection; import co.rsk.peg.bitcoin.BitcoinTestUtils; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.bitcoin.MerkleBranch; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java index b0af957e074..5ee19699353 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java @@ -64,6 +64,8 @@ import co.rsk.crypto.Keccak256; import co.rsk.db.MutableTrieCache; import co.rsk.db.MutableTrieImpl; +import co.rsk.peg.abi.ABICallElection; +import co.rsk.peg.abi.ABICallSpec; import co.rsk.peg.bitcoin.MerkleBranch; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; import co.rsk.peg.federation.*; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java b/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java index 384f8d354fb..81d7aee1d43 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java @@ -50,6 +50,7 @@ import java.util.Set; import java.util.function.BiFunction; +import co.rsk.peg.abi.ABICallSpec; import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.FederationMember; import co.rsk.test.builders.BlockChainBuilder; diff --git a/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java b/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java index 77d9b07f412..c56fe6ef731 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java @@ -10,6 +10,7 @@ import co.rsk.crypto.Keccak256; import co.rsk.db.MutableTrieCache; import co.rsk.db.MutableTrieImpl; +import co.rsk.peg.abi.ABICallSpec; import co.rsk.peg.bitcoin.BitcoinUtils; import co.rsk.peg.bitcoin.NonStandardErpRedeemScriptBuilder; import co.rsk.peg.bitcoin.P2shErpRedeemScriptBuilder; diff --git a/rskj-core/src/test/java/co/rsk/peg/ABICallElectionTest.java b/rskj-core/src/test/java/co/rsk/peg/abi/ABICallElectionTest.java similarity index 99% rename from rskj-core/src/test/java/co/rsk/peg/ABICallElectionTest.java rename to rskj-core/src/test/java/co/rsk/peg/abi/ABICallElectionTest.java index 47a30f21dcb..fe02a6645a4 100644 --- a/rskj-core/src/test/java/co/rsk/peg/ABICallElectionTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/abi/ABICallElectionTest.java @@ -16,9 +16,10 @@ * along with this program. If not, see . */ -package co.rsk.peg; +package co.rsk.peg.abi; import co.rsk.core.RskAddress; +import co.rsk.peg.AddressBasedAuthorizer; import org.bouncycastle.util.encoders.Hex; import org.ethereum.TestUtils; import org.ethereum.crypto.ECKey; diff --git a/rskj-core/src/test/java/co/rsk/peg/ABICallSpecTest.java b/rskj-core/src/test/java/co/rsk/peg/abi/ABICallSpecTest.java similarity index 99% rename from rskj-core/src/test/java/co/rsk/peg/ABICallSpecTest.java rename to rskj-core/src/test/java/co/rsk/peg/abi/ABICallSpecTest.java index 9bf2eba6f75..74bd818885f 100644 --- a/rskj-core/src/test/java/co/rsk/peg/ABICallSpecTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/abi/ABICallSpecTest.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package co.rsk.peg; +package co.rsk.peg.abi; import org.bouncycastle.util.encoders.Hex; import org.ethereum.TestUtils; diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/FederationChangeTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/FederationChangeTest.java index ff444375388..12052fdf5a9 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/FederationChangeTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/FederationChangeTest.java @@ -22,6 +22,8 @@ import co.rsk.bitcoinj.store.BtcBlockStore; import co.rsk.core.RskAddress; import co.rsk.peg.*; +import co.rsk.peg.abi.ABICallElection; +import co.rsk.peg.abi.ABICallSpec; import co.rsk.peg.federation.FederationMember; import co.rsk.peg.federation.PendingFederation; import org.ethereum.core.Repository; From f8644f6592f9ac88a9bcf0a0eef8da9f1de674be Mon Sep 17 00:00:00 2001 From: julia-zack Date: Mon, 22 Apr 2024 12:33:55 +0200 Subject: [PATCH 02/12] Refactor methods to make them mode readable. Make fields final. --- .../main/java/co/rsk/peg/abi/ABICallSpec.java | 22 +++++++++---------- .../co/rsk/peg/abi/ABICallVoteResult.java | 4 ++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/peg/abi/ABICallSpec.java b/rskj-core/src/main/java/co/rsk/peg/abi/ABICallSpec.java index c3d70e6e824..ba43d04cce1 100644 --- a/rskj-core/src/main/java/co/rsk/peg/abi/ABICallSpec.java +++ b/rskj-core/src/main/java/co/rsk/peg/abi/ABICallSpec.java @@ -34,18 +34,11 @@ * @author Ariel Mendelzon */ public final class ABICallSpec { - public static final Comparator byBytesComparator = new Comparator() { - @Override - public int compare(ABICallSpec specA, ABICallSpec specB) { - return SignedBytes.lexicographicalComparator().compare( - specA.getEncoded(), - specB.getEncoded() - ); - } - }; + public static final Comparator byBytesComparator = (specA, specB) + -> SignedBytes.lexicographicalComparator().compare(specA.getEncoded(), specB.getEncoded()); - private String function; - private byte[][] arguments; + private final String function; + private final byte[][] arguments; public ABICallSpec(String function, byte[][] arguments) { this.function = function; @@ -100,7 +93,12 @@ public boolean equals(Object other) { @Override public int hashCode() { - int[] argumentsHashes = Arrays.stream(arguments).map(argument -> Arrays.hashCode(argument)).mapToInt(Integer::intValue).toArray(); + int[] argumentsHashes = Arrays + .stream(arguments) + .map(Arrays::hashCode) + .mapToInt(Integer::intValue) + .toArray(); + return Objects.hash(function, Arrays.hashCode(argumentsHashes)); } diff --git a/rskj-core/src/main/java/co/rsk/peg/abi/ABICallVoteResult.java b/rskj-core/src/main/java/co/rsk/peg/abi/ABICallVoteResult.java index ec6dc44277d..ef2b4d381a8 100644 --- a/rskj-core/src/main/java/co/rsk/peg/abi/ABICallVoteResult.java +++ b/rskj-core/src/main/java/co/rsk/peg/abi/ABICallVoteResult.java @@ -27,8 +27,8 @@ * @author Ariel Mendelzon */ public final class ABICallVoteResult { - private boolean successful; - private Object result; + private final boolean successful; + private final Object result; public ABICallVoteResult(boolean successful, Object result) { this.successful = successful; From 6e550d89a8b16113878c66365152c55e4f0ed06d Mon Sep 17 00:00:00 2001 From: julia-zack Date: Mon, 22 Apr 2024 12:44:16 +0200 Subject: [PATCH 03/12] Refactor with lambda expression. --- .../src/main/java/co/rsk/peg/AddressBasedAuthorizer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/peg/AddressBasedAuthorizer.java b/rskj-core/src/main/java/co/rsk/peg/AddressBasedAuthorizer.java index 3ef1101b0ce..8c0884a501c 100644 --- a/rskj-core/src/main/java/co/rsk/peg/AddressBasedAuthorizer.java +++ b/rskj-core/src/main/java/co/rsk/peg/AddressBasedAuthorizer.java @@ -33,13 +33,13 @@ * @author Ariel Mendelzon */ public class AddressBasedAuthorizer { - public enum MinimumRequiredCalculation { ONE, MAJORITY, ALL }; + public enum MinimumRequiredCalculation { ONE, MAJORITY, ALL } protected List authorizedAddresses; protected MinimumRequiredCalculation requiredCalculation; public AddressBasedAuthorizer(List authorizedKeys, MinimumRequiredCalculation requiredCalculation) { - this.authorizedAddresses = authorizedKeys.stream().map(key -> key.getAddress()).collect(Collectors.toList()); + this.authorizedAddresses = authorizedKeys.stream().map(ECKey::getAddress).collect(Collectors.toList()); this.requiredCalculation = requiredCalculation; } From 532bcecd0c355cd07c6621371d48ffb36190d0f6 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Wed, 24 Apr 2024 13:25:56 +0200 Subject: [PATCH 04/12] Rename /abi to /vote, and add AddressBasedAuthorizer class to /vote as discussed. Fix test. --- .../main/java/co/rsk/config/BridgeConstants.java | 2 +- .../co/rsk/config/BridgeDevNetConstants.java | 2 +- .../co/rsk/config/BridgeMainNetConstants.java | 2 +- .../co/rsk/config/BridgeRegTestConstants.java | 2 +- .../co/rsk/config/BridgeTestNetConstants.java | 2 +- rskj-core/src/main/java/co/rsk/peg/Bridge.java | 2 +- .../co/rsk/peg/BridgeSerializationUtils.java | 5 +++-- .../java/co/rsk/peg/BridgeStorageProvider.java | 3 ++- .../src/main/java/co/rsk/peg/BridgeSupport.java | 7 ++++--- .../src/main/java/co/rsk/peg/BridgeUtils.java | 1 + .../rsk/peg/{abi => vote}/ABICallElection.java | 3 +-- .../co/rsk/peg/{abi => vote}/ABICallSpec.java | 2 +- .../rsk/peg/{abi => vote}/ABICallVoteResult.java | 2 +- .../peg/{ => vote}/AddressBasedAuthorizer.java | 2 +- .../co/rsk/peg/BridgeSerializationUtilsTest.java | 5 +++-- .../co/rsk/peg/BridgeStorageProviderTest.java | 5 +++-- .../test/java/co/rsk/peg/BridgeSupportTest.java | 3 ++- .../co/rsk/peg/BridgeSupportTestIntegration.java | 5 +++-- .../java/co/rsk/peg/BridgeTestIntegration.java | 2 +- .../java/co/rsk/peg/PowpegMigrationTest.java | 16 ++++++++-------- .../peg/performance/FederationChangeTest.java | 4 ++-- .../peg/{abi => vote}/ABICallElectionTest.java | 3 +-- .../rsk/peg/{abi => vote}/ABICallSpecTest.java | 2 +- .../{ => vote}/AddressBasedAuthorizerTest.java | 2 +- 24 files changed, 45 insertions(+), 39 deletions(-) rename rskj-core/src/main/java/co/rsk/peg/{abi => vote}/ABICallElection.java (98%) rename rskj-core/src/main/java/co/rsk/peg/{abi => vote}/ABICallSpec.java (99%) rename rskj-core/src/main/java/co/rsk/peg/{abi => vote}/ABICallVoteResult.java (98%) rename rskj-core/src/main/java/co/rsk/peg/{ => vote}/AddressBasedAuthorizer.java (98%) rename rskj-core/src/test/java/co/rsk/peg/{abi => vote}/ABICallElectionTest.java (99%) rename rskj-core/src/test/java/co/rsk/peg/{abi => vote}/ABICallSpecTest.java (99%) rename rskj-core/src/test/java/co/rsk/peg/{ => vote}/AddressBasedAuthorizerTest.java (99%) diff --git a/rskj-core/src/main/java/co/rsk/config/BridgeConstants.java b/rskj-core/src/main/java/co/rsk/config/BridgeConstants.java index 8b8046b18dc..554c6dbd268 100644 --- a/rskj-core/src/main/java/co/rsk/config/BridgeConstants.java +++ b/rskj-core/src/main/java/co/rsk/config/BridgeConstants.java @@ -21,7 +21,7 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.peg.AddressBasedAuthorizer; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.federation.Federation; import java.util.List; diff --git a/rskj-core/src/main/java/co/rsk/config/BridgeDevNetConstants.java b/rskj-core/src/main/java/co/rsk/config/BridgeDevNetConstants.java index f7fbf2ac168..f5843e8cded 100644 --- a/rskj-core/src/main/java/co/rsk/config/BridgeDevNetConstants.java +++ b/rskj-core/src/main/java/co/rsk/config/BridgeDevNetConstants.java @@ -21,7 +21,7 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.peg.AddressBasedAuthorizer; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.federation.FederationArgs; import co.rsk.peg.federation.FederationMember; import co.rsk.peg.federation.FederationFactory; diff --git a/rskj-core/src/main/java/co/rsk/config/BridgeMainNetConstants.java b/rskj-core/src/main/java/co/rsk/config/BridgeMainNetConstants.java index 95e3e981219..c8e90640141 100644 --- a/rskj-core/src/main/java/co/rsk/config/BridgeMainNetConstants.java +++ b/rskj-core/src/main/java/co/rsk/config/BridgeMainNetConstants.java @@ -3,7 +3,7 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.peg.AddressBasedAuthorizer; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.federation.FederationArgs; import co.rsk.peg.federation.FederationMember; import co.rsk.peg.federation.FederationFactory; diff --git a/rskj-core/src/main/java/co/rsk/config/BridgeRegTestConstants.java b/rskj-core/src/main/java/co/rsk/config/BridgeRegTestConstants.java index 211f7dbdd6d..43edf91c11f 100644 --- a/rskj-core/src/main/java/co/rsk/config/BridgeRegTestConstants.java +++ b/rskj-core/src/main/java/co/rsk/config/BridgeRegTestConstants.java @@ -21,7 +21,7 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.peg.AddressBasedAuthorizer; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.federation.FederationArgs; import co.rsk.peg.federation.FederationMember; import co.rsk.peg.federation.FederationFactory; diff --git a/rskj-core/src/main/java/co/rsk/config/BridgeTestNetConstants.java b/rskj-core/src/main/java/co/rsk/config/BridgeTestNetConstants.java index 19fbc10b12e..86447a5cebf 100644 --- a/rskj-core/src/main/java/co/rsk/config/BridgeTestNetConstants.java +++ b/rskj-core/src/main/java/co/rsk/config/BridgeTestNetConstants.java @@ -21,7 +21,7 @@ import co.rsk.bitcoinj.core.BtcECKey; import co.rsk.bitcoinj.core.Coin; import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.peg.AddressBasedAuthorizer; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.federation.FederationArgs; import co.rsk.peg.federation.FederationMember; import co.rsk.peg.federation.FederationFactory; diff --git a/rskj-core/src/main/java/co/rsk/peg/Bridge.java b/rskj-core/src/main/java/co/rsk/peg/Bridge.java index a17dd804c7d..0e2d73266a5 100644 --- a/rskj-core/src/main/java/co/rsk/peg/Bridge.java +++ b/rskj-core/src/main/java/co/rsk/peg/Bridge.java @@ -27,7 +27,7 @@ import co.rsk.crypto.Keccak256; import co.rsk.panic.PanicProcessor; import co.rsk.peg.BridgeMethods.BridgeMethodExecutor; -import co.rsk.peg.abi.ABICallSpec; +import co.rsk.peg.vote.ABICallSpec; import co.rsk.peg.bitcoin.MerkleBranch; import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.FederationMember; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java index 3c8734e4054..e055c9b84af 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSerializationUtils.java @@ -23,11 +23,12 @@ import co.rsk.config.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; -import co.rsk.peg.abi.ABICallElection; -import co.rsk.peg.abi.ABICallSpec; +import co.rsk.peg.vote.ABICallElection; +import co.rsk.peg.vote.ABICallSpec; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.federation.*; import co.rsk.peg.flyover.FlyoverFederationInformation; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.whitelist.OneOffWhiteListEntry; import co.rsk.peg.whitelist.UnlimitedWhiteListEntry; import org.apache.commons.lang3.tuple.Pair; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java b/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java index 5be247b46ab..2962e83ece8 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java @@ -23,11 +23,12 @@ import co.rsk.config.BridgeConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; -import co.rsk.peg.abi.ABICallElection; +import co.rsk.peg.vote.ABICallElection; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.PendingFederation; import co.rsk.peg.flyover.FlyoverFederationInformation; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.whitelist.LockWhitelist; import co.rsk.peg.whitelist.LockWhitelistEntry; import co.rsk.peg.whitelist.OneOffWhiteListEntry; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java index a5c1ebf2671..accf28e7d73 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -58,9 +58,9 @@ import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.panic.PanicProcessor; -import co.rsk.peg.abi.ABICallElection; -import co.rsk.peg.abi.ABICallSpec; -import co.rsk.peg.abi.ABICallVoteResult; +import co.rsk.peg.vote.ABICallElection; +import co.rsk.peg.vote.ABICallSpec; +import co.rsk.peg.vote.ABICallVoteResult; import co.rsk.peg.bitcoin.BitcoinUtils; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.bitcoin.MerkleBranch; @@ -80,6 +80,7 @@ import co.rsk.peg.utils.PartialMerkleTreeFormatUtils; import co.rsk.peg.utils.RejectedPegoutReason; import co.rsk.peg.utils.UnrefundablePeginReason; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.whitelist.LockWhitelist; import co.rsk.peg.whitelist.LockWhitelistEntry; import co.rsk.peg.whitelist.OneOffWhiteListEntry; diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java b/rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java index 9ded4b80afc..acd39675783 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeUtils.java @@ -32,6 +32,7 @@ import co.rsk.peg.federation.Federation; import co.rsk.peg.flyover.FlyoverTxResponseCodes; import co.rsk.peg.utils.BtcTransactionFormatUtils; +import co.rsk.peg.vote.AddressBasedAuthorizer; import org.ethereum.config.Constants; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; diff --git a/rskj-core/src/main/java/co/rsk/peg/abi/ABICallElection.java b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java similarity index 98% rename from rskj-core/src/main/java/co/rsk/peg/abi/ABICallElection.java rename to rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java index c25b36a8dd7..afb2eeb3363 100644 --- a/rskj-core/src/main/java/co/rsk/peg/abi/ABICallElection.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java @@ -16,10 +16,9 @@ * along with this program. If not, see . */ -package co.rsk.peg.abi; +package co.rsk.peg.vote; import co.rsk.core.RskAddress; -import co.rsk.peg.AddressBasedAuthorizer; import java.util.*; diff --git a/rskj-core/src/main/java/co/rsk/peg/abi/ABICallSpec.java b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallSpec.java similarity index 99% rename from rskj-core/src/main/java/co/rsk/peg/abi/ABICallSpec.java rename to rskj-core/src/main/java/co/rsk/peg/vote/ABICallSpec.java index ba43d04cce1..facc0067a13 100644 --- a/rskj-core/src/main/java/co/rsk/peg/abi/ABICallSpec.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallSpec.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package co.rsk.peg.abi; +package co.rsk.peg.vote; import com.google.common.primitives.SignedBytes; diff --git a/rskj-core/src/main/java/co/rsk/peg/abi/ABICallVoteResult.java b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallVoteResult.java similarity index 98% rename from rskj-core/src/main/java/co/rsk/peg/abi/ABICallVoteResult.java rename to rskj-core/src/main/java/co/rsk/peg/vote/ABICallVoteResult.java index ef2b4d381a8..0693028a316 100644 --- a/rskj-core/src/main/java/co/rsk/peg/abi/ABICallVoteResult.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallVoteResult.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package co.rsk.peg.abi; +package co.rsk.peg.vote; /** * Immutable representation of the result of a vote diff --git a/rskj-core/src/main/java/co/rsk/peg/AddressBasedAuthorizer.java b/rskj-core/src/main/java/co/rsk/peg/vote/AddressBasedAuthorizer.java similarity index 98% rename from rskj-core/src/main/java/co/rsk/peg/AddressBasedAuthorizer.java rename to rskj-core/src/main/java/co/rsk/peg/vote/AddressBasedAuthorizer.java index 8c0884a501c..5333e94e7e3 100644 --- a/rskj-core/src/main/java/co/rsk/peg/AddressBasedAuthorizer.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/AddressBasedAuthorizer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ -package co.rsk.peg; +package co.rsk.peg.vote; import co.rsk.core.RskAddress; import org.ethereum.core.SignatureCache; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java index 893be75a520..345c0f70401 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSerializationUtilsTest.java @@ -25,13 +25,14 @@ import co.rsk.config.BridgeMainNetConstants; import co.rsk.config.BridgeTestNetConstants; import co.rsk.core.RskAddress; -import co.rsk.peg.abi.ABICallElection; -import co.rsk.peg.abi.ABICallSpec; +import co.rsk.peg.vote.ABICallElection; +import co.rsk.peg.vote.ABICallSpec; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.federation.*; import co.rsk.peg.resources.TestConstants; import co.rsk.peg.utils.MerkleTreeUtils; import co.rsk.peg.flyover.FlyoverFederationInformation; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.whitelist.LockWhitelist; import co.rsk.peg.whitelist.LockWhitelistEntry; import co.rsk.peg.whitelist.OneOffWhiteListEntry; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java index ac2c9181b46..1f0628f5cb5 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java @@ -27,11 +27,12 @@ import co.rsk.crypto.Keccak256; import co.rsk.db.MutableTrieCache; import co.rsk.db.MutableTrieImpl; -import co.rsk.peg.abi.ABICallElection; -import co.rsk.peg.abi.ABICallSpec; +import co.rsk.peg.vote.ABICallElection; +import co.rsk.peg.vote.ABICallSpec; import co.rsk.peg.bitcoin.*; import co.rsk.peg.federation.*; import co.rsk.peg.flyover.FlyoverFederationInformation; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.whitelist.LockWhitelist; import co.rsk.peg.whitelist.LockWhitelistEntry; import co.rsk.peg.whitelist.OneOffWhiteListEntry; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java index 88d4e709506..b0d30abd04b 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTest.java @@ -30,7 +30,7 @@ import co.rsk.config.BridgeTestNetConstants; import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; -import co.rsk.peg.abi.ABICallElection; +import co.rsk.peg.vote.ABICallElection; import co.rsk.peg.bitcoin.BitcoinTestUtils; import co.rsk.peg.bitcoin.CoinbaseInformation; import co.rsk.peg.bitcoin.MerkleBranch; @@ -46,6 +46,7 @@ import co.rsk.peg.utils.MerkleTreeUtils; import co.rsk.peg.pegin.RejectedPeginReason; import co.rsk.peg.utils.UnrefundablePeginReason; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.whitelist.LockWhitelist; import co.rsk.peg.whitelist.OneOffWhiteListEntry; import co.rsk.test.builders.BridgeSupportBuilder; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java index 5ee19699353..42f284f645d 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java @@ -64,14 +64,15 @@ import co.rsk.crypto.Keccak256; import co.rsk.db.MutableTrieCache; import co.rsk.db.MutableTrieImpl; -import co.rsk.peg.abi.ABICallElection; -import co.rsk.peg.abi.ABICallSpec; +import co.rsk.peg.vote.ABICallElection; +import co.rsk.peg.vote.ABICallSpec; import co.rsk.peg.bitcoin.MerkleBranch; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; import co.rsk.peg.federation.*; import co.rsk.peg.pegininstructions.PeginInstructionsProvider; import co.rsk.peg.simples.SimpleBlockChain; import co.rsk.peg.utils.BridgeEventLogger; +import co.rsk.peg.vote.AddressBasedAuthorizer; import co.rsk.peg.whitelist.LockWhitelist; import co.rsk.peg.whitelist.LockWhitelistEntry; import co.rsk.peg.whitelist.OneOffWhiteListEntry; diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java b/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java index 81d7aee1d43..2a06c2cd3f5 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java @@ -50,7 +50,7 @@ import java.util.Set; import java.util.function.BiFunction; -import co.rsk.peg.abi.ABICallSpec; +import co.rsk.peg.vote.ABICallSpec; import co.rsk.peg.federation.Federation; import co.rsk.peg.federation.FederationMember; import co.rsk.test.builders.BlockChainBuilder; diff --git a/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java b/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java index c56fe6ef731..66750a928a0 100644 --- a/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/PowpegMigrationTest.java @@ -10,7 +10,7 @@ import co.rsk.crypto.Keccak256; import co.rsk.db.MutableTrieCache; import co.rsk.db.MutableTrieImpl; -import co.rsk.peg.abi.ABICallSpec; +import co.rsk.peg.vote.ABICallSpec; import co.rsk.peg.bitcoin.BitcoinUtils; import co.rsk.peg.bitcoin.NonStandardErpRedeemScriptBuilder; import co.rsk.peg.bitcoin.P2shErpRedeemScriptBuilder; @@ -222,7 +222,7 @@ private void testChangePowpeg( // Trying to create a new powpeg again should fail // -2 corresponds to a new powpeg was elected and the Bridge is waiting for this new powpeg to activate - attemptToCreateNewFederation(bridgeSupport, bridgeConstants, -2); + attemptToCreateNewFederation(bridgeSupport, -2); // No change in active powpeg assertEquals(oldPowPegAddress, bridgeSupport.getFederationAddress()); @@ -334,7 +334,7 @@ private void testChangePowpeg( // Trying to create a new powpeg again should fail // -3 corresponds to a new powpeg was elected and the Bridge is waiting for this new powpeg to migrate - attemptToCreateNewFederation(bridgeSupport, bridgeConstants, -3); + attemptToCreateNewFederation(bridgeSupport, -3); // peg-in after new fed activates testPegins( @@ -387,7 +387,7 @@ private void testChangePowpeg( // Trying to create a new powpeg again should fail // -3 corresponds to a new powpeg was elected and the Bridge is waiting for this new powpeg to migrate - attemptToCreateNewFederation(bridgeSupport, bridgeConstants, -3); + attemptToCreateNewFederation(bridgeSupport, -3); // Migration should start ! assertTrue(bridgeStorageProvider.getPegoutsWaitingForConfirmations().getEntries().isEmpty()); @@ -876,14 +876,14 @@ private void testPegins( private void attemptToCreateNewFederation( BridgeSupport bridgeSupport, - BridgeConstants bridgeConstants, int expectedResult) throws BridgeIllegalArgumentException { ABICallSpec createSpec = new ABICallSpec("create", new byte[][]{}); Transaction voteTx = mock(Transaction.class); - RskAddress federationChangeAuthorizer = new RskAddress( - bridgeConstants.getFederationChangeAuthorizer().authorizedAddresses.get(0) - ); + + // Known authorized address to vote the federation change + RskAddress federationChangeAuthorizer = new RskAddress("56bc5087ac97bc85a877bd20dfef910b78b1dc5a"); + when(voteTx.getSender(any())).thenReturn(federationChangeAuthorizer); int federationChangeResult = bridgeSupport.voteFederationChange(voteTx, createSpec); diff --git a/rskj-core/src/test/java/co/rsk/peg/performance/FederationChangeTest.java b/rskj-core/src/test/java/co/rsk/peg/performance/FederationChangeTest.java index 12052fdf5a9..b51089b30b9 100644 --- a/rskj-core/src/test/java/co/rsk/peg/performance/FederationChangeTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/performance/FederationChangeTest.java @@ -22,8 +22,8 @@ import co.rsk.bitcoinj.store.BtcBlockStore; import co.rsk.core.RskAddress; import co.rsk.peg.*; -import co.rsk.peg.abi.ABICallElection; -import co.rsk.peg.abi.ABICallSpec; +import co.rsk.peg.vote.ABICallElection; +import co.rsk.peg.vote.ABICallSpec; import co.rsk.peg.federation.FederationMember; import co.rsk.peg.federation.PendingFederation; import org.ethereum.core.Repository; diff --git a/rskj-core/src/test/java/co/rsk/peg/abi/ABICallElectionTest.java b/rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java similarity index 99% rename from rskj-core/src/test/java/co/rsk/peg/abi/ABICallElectionTest.java rename to rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java index fe02a6645a4..f5d7cd9f88f 100644 --- a/rskj-core/src/test/java/co/rsk/peg/abi/ABICallElectionTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java @@ -16,10 +16,9 @@ * along with this program. If not, see . */ -package co.rsk.peg.abi; +package co.rsk.peg.vote; import co.rsk.core.RskAddress; -import co.rsk.peg.AddressBasedAuthorizer; import org.bouncycastle.util.encoders.Hex; import org.ethereum.TestUtils; import org.ethereum.crypto.ECKey; diff --git a/rskj-core/src/test/java/co/rsk/peg/abi/ABICallSpecTest.java b/rskj-core/src/test/java/co/rsk/peg/vote/ABICallSpecTest.java similarity index 99% rename from rskj-core/src/test/java/co/rsk/peg/abi/ABICallSpecTest.java rename to rskj-core/src/test/java/co/rsk/peg/vote/ABICallSpecTest.java index 74bd818885f..3527197f153 100644 --- a/rskj-core/src/test/java/co/rsk/peg/abi/ABICallSpecTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/vote/ABICallSpecTest.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package co.rsk.peg.abi; +package co.rsk.peg.vote; import org.bouncycastle.util.encoders.Hex; import org.ethereum.TestUtils; diff --git a/rskj-core/src/test/java/co/rsk/peg/AddressBasedAuthorizerTest.java b/rskj-core/src/test/java/co/rsk/peg/vote/AddressBasedAuthorizerTest.java similarity index 99% rename from rskj-core/src/test/java/co/rsk/peg/AddressBasedAuthorizerTest.java rename to rskj-core/src/test/java/co/rsk/peg/vote/AddressBasedAuthorizerTest.java index 4909b4e1d0a..761a506f024 100644 --- a/rskj-core/src/test/java/co/rsk/peg/AddressBasedAuthorizerTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/vote/AddressBasedAuthorizerTest.java @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -package co.rsk.peg; +package co.rsk.peg.vote; import co.rsk.core.RskAddress; import org.ethereum.core.BlockTxSignatureCache; From 8438e2160956cbc342517033d99a720a0d811572 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Mon, 22 Apr 2024 11:51:27 +0200 Subject: [PATCH 05/12] Move ABICallElection to new /abi package. Make getWinner return Optional instead of null. Add logs to ABICallElection. Make validate method throw a new UnauthorizedVoterException. --- .../main/java/co/rsk/peg/BridgeSupport.java | 10 +++-- .../rsk/peg/UnauthorizedVoterException.java | 7 ++++ .../java/co/rsk/peg/vote/ABICallElection.java | 37 +++++++++++++------ .../co/rsk/peg/vote/ABICallElectionTest.java | 16 ++++---- 4 files changed, 46 insertions(+), 24 deletions(-) create mode 100644 rskj-core/src/main/java/co/rsk/peg/UnauthorizedVoterException.java diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java index accf28e7d73..6d87ed90a19 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -2302,8 +2302,9 @@ public Integer voteFederationChange(Transaction tx, ABICallSpec callSpec) throws } // If enough votes have been reached, then actually execute the function - ABICallSpec winnerSpec = election.getWinner(); - if (winnerSpec != null) { + Optional winnerSpecOptional = election.getWinner(); + if (winnerSpecOptional.isPresent()) { + ABICallSpec winnerSpec = winnerSpecOptional.get(); try { result = executeVoteFederationChangeFunction(false, winnerSpec); } catch (IOException e) { @@ -2605,12 +2606,13 @@ public Integer voteFeePerKbChange(Transaction tx, Coin feePerKb) { return -1; } - ABICallSpec winner = feePerKbElection.getWinner(); - if (winner == null) { + Optional winnerOptional = feePerKbElection.getWinner(); + if (!winnerOptional.isPresent()) { logger.info("Successful fee per kb vote for {}", feePerKb); return 1; } + ABICallSpec winner = winnerOptional.get(); Coin winnerFee; try { winnerFee = BridgeSerializationUtils.deserializeCoin(winner.getArguments()[0]); diff --git a/rskj-core/src/main/java/co/rsk/peg/UnauthorizedVoterException.java b/rskj-core/src/main/java/co/rsk/peg/UnauthorizedVoterException.java new file mode 100644 index 00000000000..2a895339ceb --- /dev/null +++ b/rskj-core/src/main/java/co/rsk/peg/UnauthorizedVoterException.java @@ -0,0 +1,7 @@ +package co.rsk.peg; + +public class UnauthorizedVoterException extends RuntimeException { + + public UnauthorizedVoterException(String message) { super(message); } + +} diff --git a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java index afb2eeb3363..e0408e4f470 100644 --- a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java @@ -22,6 +22,10 @@ import java.util.*; +import co.rsk.peg.UnauthorizedVoterException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Representation of a given state of the election * of an ABI function call by a series of known @@ -30,7 +34,8 @@ * @author Ariel Mendelzon */ public class ABICallElection { - private AddressBasedAuthorizer authorizer; + private static final Logger logger = LoggerFactory.getLogger(ABICallElection.class); + private final AddressBasedAuthorizer authorizer; private Map> votes; public ABICallElection(AddressBasedAuthorizer authorizer, Map> votes) { @@ -60,20 +65,20 @@ public void clear() { */ public boolean vote(ABICallSpec callSpec, RskAddress voter) { if (!authorizer.isAuthorized(voter)) { + logger.info("[vote] Voter is not authorized."); return false; } - if (!votes.containsKey(callSpec)) { - votes.put(callSpec, new ArrayList<>()); - } - + votes.computeIfAbsent(callSpec, k -> new ArrayList<>()); List callVoters = votes.get(callSpec); if (callVoters.contains(voter)) { + logger.info("[vote] Vote has already been registered."); return false; } callVoters.add(voter); + logger.info("[vote] Vote registered successfully."); return true; } @@ -84,22 +89,30 @@ public boolean vote(ABICallSpec callSpec, RskAddress voter) { * conforms a win * @return the winner abi call spec */ - public ABICallSpec getWinner() { + public Optional getWinner() { for (Map.Entry> specVotes : votes.entrySet()) { - if (specVotes.getValue().size() >= authorizer.getRequiredAuthorizedKeys()) { - return specVotes.getKey(); + int votesSize = specVotes.getValue().size(); + if (areEnoughVotes(votesSize)) { + ABICallSpec winner = specVotes.getKey(); + logger.info("[getWinner] Winner is {} ", winner); + return Optional.of(winner); } } - return null; + return Optional.empty(); + } + + private boolean areEnoughVotes(int votesSize) { + return votesSize >= authorizer.getRequiredAuthorizedKeys(); } /** * Removes the entry votes for the current winner of the election */ public void clearWinners() { - ABICallSpec winner = getWinner(); - if (winner != null) { + Optional winnerOptional = getWinner(); + if (winnerOptional.isPresent()) { + ABICallSpec winner = winnerOptional.get(); votes.remove(winner); } } @@ -109,7 +122,7 @@ private void validate() { for (Map.Entry> specVotes : votes.entrySet()) { for (RskAddress vote : specVotes.getValue()) { if (!authorizer.isAuthorized(vote)) { - throw new RuntimeException("Unauthorized voter"); + throw new UnauthorizedVoterException("Unauthorized voter"); } } } diff --git a/rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java b/rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java index f5d7cd9f88f..eee3f9b5a5c 100644 --- a/rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java @@ -126,13 +126,13 @@ void vote_existingFn() { @Test void getWinnerAndClearWinners_existingFn() { - Assertions.assertNull(election.getWinner()); + Assertions.assertFalse(election.getWinner().isPresent()); Assertions.assertTrue(election.vote(spec_fnb, createVoter("ee"))); - Assertions.assertEquals(spec_fnb, election.getWinner()); + Assertions.assertEquals(spec_fnb, election.getWinner().get()); election.clearWinners(); - Assertions.assertNull(election.getWinner()); + Assertions.assertFalse(election.getWinner().isPresent()); Assertions.assertEquals(1, election.getVotes().size()); Assertions.assertEquals(Collections.emptyList(), election.getVotes().get(spec_fna)); } @@ -140,17 +140,17 @@ void getWinnerAndClearWinners_existingFn() { @Test void getWinnerAndClearWinners_newFn() { ABICallSpec spec_fnc = new ABICallSpec("fn-c", new byte[][]{ Hex.decode("44") }); - Assertions.assertNull(election.getWinner()); + Assertions.assertFalse(election.getWinner().isPresent()); Assertions.assertTrue(election.vote(spec_fnc, createVoter("ee"))); - Assertions.assertNull(election.getWinner()); + Assertions.assertFalse(election.getWinner().isPresent()); Assertions.assertTrue(election.vote(spec_fnc, createVoter("cc"))); - Assertions.assertNull(election.getWinner()); + Assertions.assertFalse(election.getWinner().isPresent()); Assertions.assertTrue(election.vote(spec_fnc, createVoter("aa"))); - Assertions.assertEquals(spec_fnc, election.getWinner()); + Assertions.assertEquals(spec_fnc, election.getWinner().get()); election.clearWinners(); - Assertions.assertNull(election.getWinner()); + Assertions.assertFalse(election.getWinner().isPresent()); Assertions.assertEquals(2, election.getVotes().size()); Assertions.assertEquals(Collections.emptyList(), election.getVotes().get(spec_fna)); Assertions.assertEquals(Arrays.asList(createVoter("aa"), createVoter("bb")), election.getVotes().get(spec_fnb)); From c22e89f88128c048013732ccc0a6522b2558f101 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Mon, 22 Apr 2024 14:42:40 +0200 Subject: [PATCH 06/12] Fix BridgeStorageProviderTest --- .../src/test/java/co/rsk/peg/BridgeStorageProviderTest.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java index 1f0628f5cb5..072ebd8a2a7 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeStorageProviderTest.java @@ -71,7 +71,6 @@ import static co.rsk.peg.federation.FederationFormatVersion.*; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import static co.rsk.peg.BridgeStorageIndexKey.*; @@ -1850,7 +1849,7 @@ void getFeePerKbElection_emptyVotes() { ABICallElection result = storageProvider.getFeePerKbElection(authorizerMock); MatcherAssert.assertThat(result.getVotes().isEmpty(), is(true)); - MatcherAssert.assertThat(result.getWinner(), nullValue()); + Assertions.assertFalse(result.getWinner().isPresent()); } @Test @@ -1882,7 +1881,7 @@ void getFeePerKbElection_withVotes() { ABICallElection result = storageProvider.getFeePerKbElection(authorizerMock); MatcherAssert.assertThat(result.getVotes(), is(electionVotes)); - MatcherAssert.assertThat(result.getWinner(), is(expectedWinner)); + Assertions.assertEquals(expectedWinner, result.getWinner().get()); } @Test From 08fe273919568c49d9538fae683e24d6bb179149 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Mon, 22 Apr 2024 16:07:53 +0200 Subject: [PATCH 07/12] Fix BridgeSupportTestIntegration --- .../java/co/rsk/peg/vote/ABICallElection.java | 4 +-- .../rsk/peg/BridgeSupportTestIntegration.java | 25 ++++++++----------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java index e0408e4f470..9c333cdb8ee 100644 --- a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java @@ -83,11 +83,11 @@ public boolean vote(ABICallSpec callSpec, RskAddress voter) { } /** - * Returns the election winner abi call spec, or null if there's none + * Returns the election winner abi call spec, or empty if there's none * The vote authorizer determines the number of participants, * whereas this class determines the number of votes that * conforms a win - * @return the winner abi call spec + * @return the (optional) winner abi call spec */ public Optional getWinner() { for (Map.Entry> specVotes : votes.entrySet()) { diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java index 42f284f645d..5f84e1f873b 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportTestIntegration.java @@ -22,16 +22,7 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; import static org.hamcrest.core.Is.is; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyBoolean; -import static org.mockito.Mockito.anyInt; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import co.rsk.bitcoinj.core.Address; import co.rsk.bitcoinj.core.AddressFormatException; @@ -2168,8 +2159,12 @@ public Transaction getTx() { return tx; } - public ABICallSpec getWinner() { - return winner; + public Optional getWinner() { + if (winner == null) { + return Optional.empty(); + } + + return Optional.of(winner); } public void setWinner(ABICallSpec winner) { @@ -3990,15 +3985,15 @@ public void setFederationElection(ABICallElection federationElection) { return holder.getFederationElection(); }); - Mockito.doAnswer((InvocationOnMock m) -> { + doAnswer((InvocationOnMock m) -> { holder.setActiveFederation(m.getArgument(0)); return null; }).when(providerMock).setNewFederation(any()); - Mockito.doAnswer((InvocationOnMock m) -> { + doAnswer((InvocationOnMock m) -> { holder.setRetiringFederation(m.getArgument(0)); return null; }).when(providerMock).setOldFederation(any()); - Mockito.doAnswer((InvocationOnMock m) -> { + doAnswer((InvocationOnMock m) -> { holder.setPendingFederation(m.getArgument(0)); return null; }).when(providerMock).setPendingFederation(any()); From 1670c01f750b4ebc0081e7c01edb02384fd5fbc6 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Tue, 23 Apr 2024 08:48:16 +0200 Subject: [PATCH 08/12] Add log --- rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java index 9c333cdb8ee..c3565401381 100644 --- a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java @@ -64,6 +64,8 @@ public void clear() { * @return whether the voting succeeded */ public boolean vote(ABICallSpec callSpec, RskAddress voter) { + logger.info("[vote] Trying to register voter's {} vote ", voter); + if (!authorizer.isAuthorized(voter)) { logger.info("[vote] Voter is not authorized."); return false; From 18dacbb6f4b17cd336ff479f64a0683046e75a98 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Wed, 24 Apr 2024 13:32:49 +0200 Subject: [PATCH 09/12] Add UnauthorizedVoterException to /vote package --- rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java | 1 - .../java/co/rsk/peg/{ => vote}/UnauthorizedVoterException.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) rename rskj-core/src/main/java/co/rsk/peg/{ => vote}/UnauthorizedVoterException.java (85%) diff --git a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java index c3565401381..3759c0efc6a 100644 --- a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java @@ -22,7 +22,6 @@ import java.util.*; -import co.rsk.peg.UnauthorizedVoterException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/rskj-core/src/main/java/co/rsk/peg/UnauthorizedVoterException.java b/rskj-core/src/main/java/co/rsk/peg/vote/UnauthorizedVoterException.java similarity index 85% rename from rskj-core/src/main/java/co/rsk/peg/UnauthorizedVoterException.java rename to rskj-core/src/main/java/co/rsk/peg/vote/UnauthorizedVoterException.java index 2a895339ceb..20c1a9a7e38 100644 --- a/rskj-core/src/main/java/co/rsk/peg/UnauthorizedVoterException.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/UnauthorizedVoterException.java @@ -1,4 +1,4 @@ -package co.rsk.peg; +package co.rsk.peg.vote; public class UnauthorizedVoterException extends RuntimeException { From 810de076387ff8904a5bed390dfeb2d97938d1b6 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Wed, 24 Apr 2024 14:31:31 +0200 Subject: [PATCH 10/12] Make votes an unmodifiable map to fix code smell --- .../java/co/rsk/peg/vote/ABICallElection.java | 10 ++++++-- .../co/rsk/peg/vote/ABICallElectionTest.java | 25 +++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java index 3759c0efc6a..e431f966974 100644 --- a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java @@ -21,6 +21,7 @@ import co.rsk.core.RskAddress; import java.util.*; +import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,17 +40,22 @@ public class ABICallElection { public ABICallElection(AddressBasedAuthorizer authorizer, Map> votes) { this.authorizer = authorizer; - this.votes = votes; + this.votes = clone(votes); validate(); } + private Map> clone(Map> originalMap) { + return originalMap.entrySet().stream() + .collect(Collectors.toMap(Map.Entry::getKey, e -> new ArrayList<>(e.getValue()))); + } + public ABICallElection(AddressBasedAuthorizer authorizer) { this.authorizer = authorizer; this.votes = new HashMap<>(); } public Map> getVotes() { - return votes; + return clone(votes); } public void clear() { diff --git a/rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java b/rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java index eee3f9b5a5c..c61259ced0b 100644 --- a/rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/vote/ABICallElectionTest.java @@ -27,6 +27,7 @@ import org.junit.jupiter.api.Test; import java.util.*; +import java.util.stream.Collectors; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -73,8 +74,28 @@ void emptyVotesConstructor() { } @Test - void getVotes() { - Assertions.assertSame(votes, election.getVotes()); + void getVotes_shouldNotBeSame_ButEqual_votes() { + Assertions.assertNotSame(votes, election.getVotes()); + Assertions.assertEquals(votes, election.getVotes()); + } + + @Test + void modify_votes_shouldNotChange_electionVotes() { + votes.put( + spec_fnb, + new ArrayList<>(Arrays.asList( + createVoter("cc"), + createVoter("dd") + )) + ); + + Assertions.assertNotEquals(votes, election.getVotes()); + } + + @Test + void clear_electionVotes_shouldNotChange_votes() { + election.clear(); + Assertions.assertNotEquals(votes, election.getVotes()); } @Test From 6760f23b3bff750823f0c6e5c38e327f1029fb6c Mon Sep 17 00:00:00 2001 From: Marcos Date: Wed, 24 Apr 2024 18:17:55 -0300 Subject: [PATCH 11/12] Move constructor --- .../src/main/java/co/rsk/peg/vote/ABICallElection.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java index e431f966974..c6e8f802ea7 100644 --- a/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java +++ b/rskj-core/src/main/java/co/rsk/peg/vote/ABICallElection.java @@ -38,6 +38,11 @@ public class ABICallElection { private final AddressBasedAuthorizer authorizer; private Map> votes; + public ABICallElection(AddressBasedAuthorizer authorizer) { + this.authorizer = authorizer; + this.votes = new HashMap<>(); + } + public ABICallElection(AddressBasedAuthorizer authorizer, Map> votes) { this.authorizer = authorizer; this.votes = clone(votes); @@ -49,11 +54,6 @@ private Map> clone(Map new ArrayList<>(e.getValue()))); } - public ABICallElection(AddressBasedAuthorizer authorizer) { - this.authorizer = authorizer; - this.votes = new HashMap<>(); - } - public Map> getVotes() { return clone(votes); } From f03f097893ab26016f61edd4de96941b909adcda Mon Sep 17 00:00:00 2001 From: Marcos Date: Wed, 24 Apr 2024 18:18:19 -0300 Subject: [PATCH 12/12] Optimize imports in BridgeSupport --- .../main/java/co/rsk/peg/BridgeSupport.java | 74 +++---------------- 1 file changed, 12 insertions(+), 62 deletions(-) diff --git a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java index 6d87ed90a19..cee4baf5ca6 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -20,37 +20,11 @@ import static co.rsk.peg.BridgeUtils.getRegularPegoutTxSize; import static co.rsk.peg.ReleaseTransactionBuilder.BTC_TX_VERSION_2; import static co.rsk.peg.pegin.RejectedPeginReason.INVALID_AMOUNT; -import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP186; -import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP219; -import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP271; -import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP293; -import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP294; -import static org.ethereum.config.blockchain.upgrades.ConsensusRule.RSKIP377; - -import co.rsk.bitcoinj.core.Address; -import co.rsk.bitcoinj.core.AddressFormatException; -import co.rsk.bitcoinj.core.BtcBlock; -import co.rsk.bitcoinj.core.BtcBlockChain; -import co.rsk.bitcoinj.core.BtcECKey; -import co.rsk.bitcoinj.core.BtcTransaction; -import co.rsk.bitcoinj.core.CheckpointManager; -import co.rsk.bitcoinj.core.Coin; -import co.rsk.bitcoinj.core.Context; -import co.rsk.bitcoinj.core.InsufficientMoneyException; -import co.rsk.bitcoinj.core.NetworkParameters; -import co.rsk.bitcoinj.core.PartialMerkleTree; -import co.rsk.bitcoinj.core.Sha256Hash; -import co.rsk.bitcoinj.core.StoredBlock; -import co.rsk.bitcoinj.core.TransactionInput; -import co.rsk.bitcoinj.core.TransactionOutput; -import co.rsk.bitcoinj.core.UTXO; -import co.rsk.bitcoinj.core.UTXOProviderException; -import co.rsk.bitcoinj.core.VerificationException; +import static org.ethereum.config.blockchain.upgrades.ConsensusRule.*; + +import co.rsk.bitcoinj.core.*; import co.rsk.bitcoinj.crypto.TransactionSignature; -import co.rsk.bitcoinj.script.FastBridgeRedeemScriptParser; -import co.rsk.bitcoinj.script.Script; -import co.rsk.bitcoinj.script.ScriptBuilder; -import co.rsk.bitcoinj.script.ScriptChunk; +import co.rsk.bitcoinj.script.*; import co.rsk.bitcoinj.store.BlockStoreException; import co.rsk.bitcoinj.wallet.SendRequest; import co.rsk.bitcoinj.wallet.Wallet; @@ -58,33 +32,18 @@ import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.panic.PanicProcessor; -import co.rsk.peg.vote.ABICallElection; -import co.rsk.peg.vote.ABICallSpec; -import co.rsk.peg.vote.ABICallVoteResult; -import co.rsk.peg.bitcoin.BitcoinUtils; -import co.rsk.peg.bitcoin.CoinbaseInformation; -import co.rsk.peg.bitcoin.MerkleBranch; -import co.rsk.peg.bitcoin.RskAllowUnconfirmedCoinSelector; +import co.rsk.peg.bitcoin.*; import co.rsk.peg.btcLockSender.BtcLockSender.TxSenderAddressType; import co.rsk.peg.btcLockSender.BtcLockSenderProvider; import co.rsk.peg.federation.*; import co.rsk.peg.flyover.FlyoverFederationInformation; import co.rsk.peg.flyover.FlyoverTxResponseCodes; -import co.rsk.peg.pegin.PeginEvaluationResult; -import co.rsk.peg.pegin.PeginProcessAction; -import co.rsk.peg.pegin.RejectedPeginReason; +import co.rsk.peg.pegin.*; import co.rsk.peg.pegininstructions.PeginInstructionsException; import co.rsk.peg.pegininstructions.PeginInstructionsProvider; -import co.rsk.peg.utils.BridgeEventLogger; -import co.rsk.peg.utils.BtcTransactionFormatUtils; -import co.rsk.peg.utils.PartialMerkleTreeFormatUtils; -import co.rsk.peg.utils.RejectedPegoutReason; -import co.rsk.peg.utils.UnrefundablePeginReason; -import co.rsk.peg.vote.AddressBasedAuthorizer; -import co.rsk.peg.whitelist.LockWhitelist; -import co.rsk.peg.whitelist.LockWhitelistEntry; -import co.rsk.peg.whitelist.OneOffWhiteListEntry; -import co.rsk.peg.whitelist.UnlimitedWhiteListEntry; +import co.rsk.peg.utils.*; +import co.rsk.peg.vote.*; +import co.rsk.peg.whitelist.*; import co.rsk.rpc.modules.trace.CallType; import co.rsk.rpc.modules.trace.ProgramSubtrace; import com.google.common.annotations.VisibleForTesting; @@ -92,23 +51,14 @@ import java.io.InputStream; import java.math.BigInteger; import java.time.Instant; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; import javax.annotation.Nullable; import org.apache.commons.lang3.tuple.Pair; import org.bouncycastle.util.encoders.Hex; import org.ethereum.config.blockchain.upgrades.ActivationConfig; import org.ethereum.config.blockchain.upgrades.ConsensusRule; -import org.ethereum.core.Block; -import org.ethereum.core.Repository; -import org.ethereum.core.SignatureCache; -import org.ethereum.core.Transaction; +import org.ethereum.core.*; import org.ethereum.crypto.ECKey; import org.ethereum.crypto.HashUtil; import org.ethereum.util.ByteUtil; @@ -157,7 +107,7 @@ public class BridgeSupport { // (6 blocks/hour, 24 hours/day, 30 days/month) public static final Integer BTC_TRANSACTION_CONFIRMATION_MAX_DEPTH = 4320; - private static final Logger logger = LoggerFactory.getLogger("BridgeSupport"); + private static final Logger logger = LoggerFactory.getLogger(BridgeSupport.class); private static final PanicProcessor panicProcessor = new PanicProcessor(); private static final String INVALID_ADDRESS_FORMAT_MESSAGE = "invalid address format";