From 0d6dd00b09f70099a9c029ae843cf11ec277ae60 Mon Sep 17 00:00:00 2001 From: Marcos Date: Tue, 20 Aug 2024 12:52:12 -0300 Subject: [PATCH] Remove unthrown exceptions from method signatures Remove unused import --- .../src/main/java/co/rsk/peg/Bridge.java | 10 +- .../co/rsk/peg/BridgeStorageProvider.java | 8 +- .../main/java/co/rsk/peg/BridgeSupport.java | 46 ++-- .../rsk/peg/federation/FederationSupport.java | 7 +- .../org/ethereum/config/SystemProperties.java | 1 - .../co/rsk/peg/BridgeStorageProviderTest.java | 152 +++++++------ .../test/java/co/rsk/peg/BridgeSupportIT.java | 212 +++++++++++------- .../java/co/rsk/peg/BridgeSupportTest.java | 2 +- ...ockCoinbaseTransactionInformationTest.java | 48 ++-- 9 files changed, 271 insertions(+), 215 deletions(-) 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 fd6c3382897..7f8d422e6bb 100644 --- a/rskj-core/src/main/java/co/rsk/peg/Bridge.java +++ b/rskj-core/src/main/java/co/rsk/peg/Bridge.java @@ -903,7 +903,7 @@ public long getRetiringFederationCreationBlockNumber(Object[] args) { return bridgeSupport.getRetiringFederationCreationBlockNumber(); } - public Integer createFederation(Object[] args) throws BridgeIllegalArgumentException { + public Integer createFederation(Object[] args) { logger.trace("createFederation"); return bridgeSupport.voteFederationChange( @@ -912,7 +912,7 @@ public Integer createFederation(Object[] args) throws BridgeIllegalArgumentExcep ); } - public Integer addFederatorPublicKey(Object[] args) throws BridgeIllegalArgumentException { + public Integer addFederatorPublicKey(Object[] args) { logger.trace("addFederatorPublicKey"); byte[] publicKeyBytes; @@ -929,7 +929,7 @@ public Integer addFederatorPublicKey(Object[] args) throws BridgeIllegalArgument ); } - public Integer addFederatorPublicKeyMultikey(Object[] args) throws BridgeIllegalArgumentException { + public Integer addFederatorPublicKeyMultikey(Object[] args) { logger.trace("addFederatorPublicKeyMultikey"); byte[] btcPublicKeyBytes = (byte[]) args[0]; @@ -945,7 +945,7 @@ public Integer addFederatorPublicKeyMultikey(Object[] args) throws BridgeIllegal ); } - public Integer commitFederation(Object[] args) throws BridgeIllegalArgumentException { + public Integer commitFederation(Object[] args) { logger.trace("commitFederation"); byte[] hash; @@ -962,7 +962,7 @@ public Integer commitFederation(Object[] args) throws BridgeIllegalArgumentExcep ); } - public Integer rollbackFederation(Object[] args) throws BridgeIllegalArgumentException { + public Integer rollbackFederation(Object[] args) { logger.trace("rollbackFederation"); return bridgeSupport.voteFederationChange( 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 f7fe046e510..1b9797bd1c5 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java @@ -373,15 +373,15 @@ public Optional getFlyoverFederationInformation(by return Optional.empty(); } - FlyoverFederationInformation flyoverFederationInformation = this.safeGetFromRepository( + FlyoverFederationInformation flyoverFederationInformationInStorage = this.safeGetFromRepository( getStorageKeyForFlyoverFederationInformation(flyoverFederationRedeemScriptHash), data -> BridgeSerializationUtils.deserializeFlyoverFederationInformation(data, flyoverFederationRedeemScriptHash) ); - if (flyoverFederationInformation == null) { + if (flyoverFederationInformationInStorage == null) { return Optional.empty(); } - return Optional.of(flyoverFederationInformation); + return Optional.of(flyoverFederationInformationInStorage); } public void setFlyoverFederationInformation(FlyoverFederationInformation flyoverFederationInformation) { @@ -520,7 +520,7 @@ protected void savePegoutTxSigHashes() { )); } - public void save() throws IOException { + public void save() { saveBtcTxHashesAlreadyProcessed(); saveReleaseRequestQueue(); 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 a5aef5b9a05..d83bf35927b 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -34,10 +34,7 @@ import co.rsk.core.RskAddress; import co.rsk.crypto.Keccak256; import co.rsk.panic.PanicProcessor; -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.*; @@ -72,9 +69,7 @@ import org.ethereum.vm.DataWord; import org.ethereum.vm.PrecompiledContracts; import org.ethereum.vm.exception.VMException; -import org.ethereum.vm.program.InternalTransaction; -import org.ethereum.vm.program.Program; -import org.ethereum.vm.program.ProgramResult; +import org.ethereum.vm.program.*; import org.ethereum.vm.program.invoke.TransferInvoke; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -178,7 +173,7 @@ InputStream getCheckPoints() { return checkpoints; } - public void save() throws IOException { + public void save() { provider.save(); feePerKbSupport.save(); whitelistSupport.save(); @@ -280,7 +275,7 @@ private boolean cannotProcessNextBlock(StoredBlock previousBlock) { * @throws IOException * @param shouldConsiderFlyoverUTXOs */ - public Wallet getActiveFederationWallet(boolean shouldConsiderFlyoverUTXOs) throws IOException { + public Wallet getActiveFederationWallet(boolean shouldConsiderFlyoverUTXOs) { Federation federation = getActiveFederation(); List utxos = federationSupport.getActiveFederationBtcUTXOs(); @@ -298,15 +293,14 @@ public Wallet getActiveFederationWallet(boolean shouldConsiderFlyoverUTXOs) thro * or null if there's currently no retiring federation * @return A BTC wallet for the currently active federation * - * @throws IOException * @param shouldConsiderFlyoverUTXOs */ - protected Wallet getRetiringFederationWallet(boolean shouldConsiderFlyoverUTXOs) throws IOException { + protected Wallet getRetiringFederationWallet(boolean shouldConsiderFlyoverUTXOs) { List retiringFederationBtcUTXOs = federationSupport.getRetiringFederationBtcUTXOs(); return getRetiringFederationWallet(shouldConsiderFlyoverUTXOs, retiringFederationBtcUTXOs.size()); } - private Wallet getRetiringFederationWallet(boolean shouldConsiderFlyoverUTXOs, int utxosSizeLimit) throws IOException { + private Wallet getRetiringFederationWallet(boolean shouldConsiderFlyoverUTXOs, int utxosSizeLimit) { Federation federation = getRetiringFederation(); if (federation == null) { logger.debug("[getRetiringFederationWallet] No retiring federation found"); @@ -978,9 +972,11 @@ private void processFundsMigration(Transaction rskTx) throws IOException { long federationAge = rskExecutionBlock.getNumber() - activeFederation.getCreationBlockNumber(); logger.trace("[processFundsMigration] Active federation (age={}) is in migration age.", federationAge); if (hasMinimumFundsToMigrate(retiringFederationWallet)){ + Coin retiringFederationBalance = retiringFederationWallet.getBalance(); + String retiringFederationBalanceInFriendlyFormat = retiringFederationBalance.toFriendlyString(); logger.info( "[processFundsMigration] Retiring federation has funds to migrate: {}.", - retiringFederationWallet.getBalance().toFriendlyString() + retiringFederationBalanceInFriendlyFormat ); migrateFunds( @@ -994,9 +990,11 @@ private void processFundsMigration(Transaction rskTx) throws IOException { if (retiringFederationWallet != null && federationIsPastMigrationAge(activeFederation)) { if (retiringFederationWallet.getBalance().isGreaterThan(Coin.ZERO)) { + Coin retiringFederationBalance = retiringFederationWallet.getBalance(); + String retiringFederationBalanceInFriendlyFormat = retiringFederationBalance.toFriendlyString(); logger.info( "[processFundsMigration] Federation is past migration age and will try to migrate remaining balance: {}.", - retiringFederationWallet.getBalance().toFriendlyString() + retiringFederationBalanceInFriendlyFormat ); try { @@ -2031,7 +2029,7 @@ private List getLiveFederations() { return liveFederations; } - public Integer voteFederationChange(Transaction tx, ABICallSpec callSpec) throws BridgeIllegalArgumentException { + public Integer voteFederationChange(Transaction tx, ABICallSpec callSpec) { return federationSupport.voteFederationChange(tx, callSpec, signatureCache, eventLogger); } @@ -2533,7 +2531,7 @@ protected void saveFlyoverActiveFederationDataInStorage( Keccak256 derivationHash, FlyoverFederationInformation flyoverFederationInformation, List utxosList - ) throws IOException { + ) { provider.markFlyoverDerivationHashAsUsed(btcTxHash, derivationHash); provider.setFlyoverFederationInformation(flyoverFederationInformation); federationSupport.getActiveFederationBtcUTXOs().addAll(utxosList); @@ -2544,7 +2542,7 @@ protected void saveFlyoverRetiringFederationDataInStorage( Keccak256 derivationHash, FlyoverFederationInformation flyoverRetiringFederationInformation, List utxosList - ) throws IOException { + ) { provider.markFlyoverDerivationHashAsUsed(btcTxHash, derivationHash); provider.setFlyoverRetiringFederationInformation(flyoverRetiringFederationInformation); federationSupport.getRetiringFederationBtcUTXOs().addAll(utxosList); @@ -2597,14 +2595,12 @@ private Pair> createMigrationTransaction(Wallet origi } List selectedUTXOs = originWallet - .getUTXOProvider().getOpenTransactionOutputs(originWallet.getWatchedAddresses()).stream() - .filter(utxo -> - migrationBtcTx.getInputs().stream().anyMatch(input -> - input.getOutpoint().getHash().equals(utxo.getHash()) && - input.getOutpoint().getIndex() == utxo.getIndex() - ) - ) - .collect(Collectors.toList()); + .getUTXOProvider() + .getOpenTransactionOutputs(originWallet.getWatchedAddresses()) + .stream() + .filter(utxo -> migrationBtcTx.getInputs().stream().anyMatch(input -> + input.getOutpoint().getHash().equals(utxo.getHash()) && input.getOutpoint().getIndex() == utxo.getIndex() + )).collect(Collectors.toList()); return Pair.of(migrationBtcTx, selectedUTXOs); } catch (InsufficientMoneyException | Wallet.ExceededMaxTransactionSize | Wallet.CouldNotAdjustDownwards e) { diff --git a/rskj-core/src/main/java/co/rsk/peg/federation/FederationSupport.java b/rskj-core/src/main/java/co/rsk/peg/federation/FederationSupport.java index e0526a7b8bf..0f623dc6eb1 100644 --- a/rskj-core/src/main/java/co/rsk/peg/federation/FederationSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/federation/FederationSupport.java @@ -47,7 +47,12 @@ public interface FederationSupport { byte[] getPendingFederatorBtcPublicKey(int index); byte[] getPendingFederatorPublicKeyOfType(int index, FederationMember.KeyType keyType); - int voteFederationChange(Transaction tx, ABICallSpec callSpec, SignatureCache signatureCache, BridgeEventLogger eventLogger); + int voteFederationChange( + Transaction tx, + ABICallSpec callSpec, + SignatureCache signatureCache, + BridgeEventLogger eventLogger + ); long getActiveFederationCreationBlockHeight(); Optional