Skip to content

Commit

Permalink
Remove unthrown exceptions from method signatures
Browse files Browse the repository at this point in the history
Remove unused import
  • Loading branch information
marcos-iov committed Aug 20, 2024
1 parent c04b77f commit 0d6dd00
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 215 deletions.
10 changes: 5 additions & 5 deletions rskj-core/src/main/java/co/rsk/peg/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand All @@ -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];
Expand All @@ -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;
Expand All @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions rskj-core/src/main/java/co/rsk/peg/BridgeStorageProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,15 @@ public Optional<FlyoverFederationInformation> 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) {
Expand Down Expand Up @@ -520,7 +520,7 @@ protected void savePegoutTxSigHashes() {
));
}

public void save() throws IOException {
public void save() {
saveBtcTxHashesAlreadyProcessed();

saveReleaseRequestQueue();
Expand Down
46 changes: 21 additions & 25 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -178,7 +173,7 @@ InputStream getCheckPoints() {
return checkpoints;
}

public void save() throws IOException {
public void save() {
provider.save();
feePerKbSupport.save();
whitelistSupport.save();
Expand Down Expand Up @@ -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<UTXO> utxos = federationSupport.getActiveFederationBtcUTXOs();

Expand All @@ -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<UTXO> 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");
Expand Down Expand Up @@ -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(
Expand All @@ -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 {
Expand Down Expand Up @@ -2031,7 +2029,7 @@ private List<Federation> 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);
}

Expand Down Expand Up @@ -2533,7 +2531,7 @@ protected void saveFlyoverActiveFederationDataInStorage(
Keccak256 derivationHash,
FlyoverFederationInformation flyoverFederationInformation,
List<UTXO> utxosList
) throws IOException {
) {
provider.markFlyoverDerivationHashAsUsed(btcTxHash, derivationHash);
provider.setFlyoverFederationInformation(flyoverFederationInformation);
federationSupport.getActiveFederationBtcUTXOs().addAll(utxosList);
Expand All @@ -2544,7 +2542,7 @@ protected void saveFlyoverRetiringFederationDataInStorage(
Keccak256 derivationHash,
FlyoverFederationInformation flyoverRetiringFederationInformation,
List<UTXO> utxosList
) throws IOException {
) {
provider.markFlyoverDerivationHashAsUsed(btcTxHash, derivationHash);
provider.setFlyoverRetiringFederationInformation(flyoverRetiringFederationInformation);
federationSupport.getRetiringFederationBtcUTXOs().addAll(utxosList);
Expand Down Expand Up @@ -2597,14 +2595,12 @@ private Pair<BtcTransaction, List<UTXO>> createMigrationTransaction(Wallet origi
}

List<UTXO> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Script> getLastRetiredFederationP2SHScript();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.ethereum.config;

import co.rsk.bitcoinj.core.BtcECKey;
import co.rsk.peg.constants.BridgeDevNetConstants;
import co.rsk.config.ConfigLoader;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigObject;
Expand Down
Loading

0 comments on commit 0d6dd00

Please sign in to comment.