From 44b47b5ab605a4de60b20a6b771737d6c96acaf5 Mon Sep 17 00:00:00 2001 From: julia-zack Date: Thu, 9 Jan 2025 17:42:09 -0300 Subject: [PATCH] Rename and add explanatory comment --- .../main/java/co/rsk/peg/BridgeSupport.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 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 903e2fefa8..481bc2ab44 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -1370,42 +1370,47 @@ private Coin getPegoutRequestedAmount(BtcTransaction pegoutTransaction) { totalAmount = totalAmount.add(input.getValue()); } - TransactionOutput changeOutput = pegoutTransaction.getOutput(pegoutTransaction.getOutputs().size() - 1); + int changeOutputIndex = pegoutTransaction.getOutputs().size() - 1; + TransactionOutput changeOutput = pegoutTransaction.getOutput(changeOutputIndex); Coin changeOutputAmount = changeOutput.getValue(); + // since the user pays for the pegout fees, the actual amount + // being sent is different from the requested amount, + // that is the total amount from used inputs, minus the change output return totalAmount.minus(changeOutputAmount); } private void settleMigrationRelease(PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations, BtcTransaction migrationTransaction, Keccak256 migrationCreationTxHash) { - Coin requestedAmount = getMigrationRequestedAmount(migrationTransaction); + Coin amountToMigrate = amountToMigrate(migrationTransaction); List utxosToUse = federationSupport.getRetiringFederationBtcUTXOs(); - settleReleaseRequest(utxosToUse, pegoutsWaitingForConfirmations, migrationTransaction, migrationCreationTxHash, requestedAmount); + settleReleaseRequest(utxosToUse, pegoutsWaitingForConfirmations, migrationTransaction, migrationCreationTxHash, amountToMigrate); } - private Coin getMigrationRequestedAmount(BtcTransaction migrationTransaction) { - Coin requestedAmount = Coin.ZERO; + private Coin amountToMigrate(BtcTransaction migrationTransaction) { + Coin amountToMigrate = Coin.ZERO; for (int i = 0; i < migrationTransaction.getInputs().size(); i ++) { TransactionInput input = migrationTransaction.getInput(i); - requestedAmount = requestedAmount.add(input.getValue()); + amountToMigrate = amountToMigrate.add(input.getValue()); } - return requestedAmount; + return amountToMigrate; } private void settleSvpFundTransactionRelease(PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations, BtcTransaction svpFundTransaction, Keccak256 svpFundCreationTxHash) { List utxosToUse = federationSupport.getActiveFederationBtcUTXOs(); - Coin requestedAmount = getSvpFundTxRequestedAmount(svpFundTransaction); - settleReleaseRequest(utxosToUse, pegoutsWaitingForConfirmations, svpFundTransaction, svpFundCreationTxHash, requestedAmount); + Coin svpFundTxSentAmount = getSvpFundTxSentAmount(svpFundTransaction); + + settleReleaseRequest(utxosToUse, pegoutsWaitingForConfirmations, svpFundTransaction, svpFundCreationTxHash, svpFundTxSentAmount); } - private Coin getSvpFundTxRequestedAmount(BtcTransaction svpFundTransaction) { - Coin requestedAmount = Coin.ZERO; + private Coin getSvpFundTxSentAmount(BtcTransaction svpFundTransaction) { + Coin svpFundTxSentAmount = Coin.ZERO; for (int i = 0; i < svpFundTransaction.getOutputs().size() - 1; i ++) { TransactionOutput output = svpFundTransaction.getOutput(i); - requestedAmount = requestedAmount.add(output.getValue()); + svpFundTxSentAmount = svpFundTxSentAmount.add(output.getValue()); } - return requestedAmount; + return svpFundTxSentAmount; } private void settleReleaseRequest(List utxosToUse, PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations, BtcTransaction releaseTransaction, Keccak256 releaseCreationTxHash, Coin requestedAmount) {