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 dcdc93653d..79da301ab5 100644 --- a/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java +++ b/rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java @@ -1088,14 +1088,15 @@ private boolean isSvpOngoing() { } private void processSvpFundTransactionUnsigned(Keccak256 rskTxHash, Federation proposedFederation) { - Coin spendableValueFromProposedFederation = bridgeConstants.getSpendableValueFromProposedFederation(); try { - BtcTransaction svpFundTransactionUnsigned = createSvpFundTransaction(proposedFederation, spendableValueFromProposedFederation); + BtcTransaction svpFundTransactionUnsigned = createSvpFundTransaction(proposedFederation); provider.setSvpFundTxHashUnsigned(svpFundTransactionUnsigned.getHash()); PegoutsWaitingForConfirmations pegoutsWaitingForConfirmations = provider.getPegoutsWaitingForConfirmations(); List utxosToUse = federationSupport.getActiveFederationBtcUTXOs(); - settleReleaseRequest(utxosToUse, pegoutsWaitingForConfirmations, svpFundTransactionUnsigned, rskTxHash, spendableValueFromProposedFederation); + // minPegoutValue to proposed fed, minPegoutValue to flyover proposed fed + Coin totalValueSentToProposedFederation = bridgeConstants.getMinimumPegoutTxValue().multiply(2); + settleReleaseRequest(utxosToUse, pegoutsWaitingForConfirmations, svpFundTransactionUnsigned, rskTxHash, totalValueSentToProposedFederation); } catch (InsufficientMoneyException e) { logger.error( "[processSvpFundTransactionUnsigned] Insufficient funds for creating the fund transaction. Error message: {}", @@ -1109,18 +1110,18 @@ private void processSvpFundTransactionUnsigned(Keccak256 rskTxHash, Federation p } } - private BtcTransaction createSvpFundTransaction(Federation proposedFederation, Coin spendableValueFromProposedFederation) throws InsufficientMoneyException { + private BtcTransaction createSvpFundTransaction(Federation proposedFederation) throws InsufficientMoneyException { Wallet activeFederationWallet = getActiveFederationWallet(true); BtcTransaction svpFundTransaction = new BtcTransaction(networkParameters); svpFundTransaction.setVersion(BTC_TX_VERSION_2); + Coin minPegoutTxValue = bridgeConstants.getMinimumPegoutTxValue(); // add outputs to proposed fed and proposed fed with flyover prefix - svpFundTransaction.addOutput(spendableValueFromProposedFederation, proposedFederation.getAddress()); - + svpFundTransaction.addOutput(minPegoutTxValue, proposedFederation.getAddress()); Address proposedFederationWithFlyoverPrefixAddress = getFlyoverAddress(networkParameters, bridgeConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript()); - svpFundTransaction.addOutput(spendableValueFromProposedFederation, proposedFederationWithFlyoverPrefixAddress); + svpFundTransaction.addOutput(minPegoutTxValue, proposedFederationWithFlyoverPrefixAddress); // complete tx with input and change output SendRequest sendRequest = createSvpFundTransactionSendRequest(svpFundTransaction); diff --git a/rskj-core/src/main/java/co/rsk/peg/constants/BridgeConstants.java b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeConstants.java index a6035dfda7..80593638dd 100644 --- a/rskj-core/src/main/java/co/rsk/peg/constants/BridgeConstants.java +++ b/rskj-core/src/main/java/co/rsk/peg/constants/BridgeConstants.java @@ -105,8 +105,6 @@ public Coin getMinimumPeginTxValue(ActivationConfig.ForBlock activations) { public Coin getMinimumPegoutTxValue() { return minimumPegoutTxValue; } - public Coin getSpendableValueFromProposedFederation() { return minimumPegoutTxValue.multiply(2); } - public Keccak256 getProposedFederationFlyoverPrefix() { return new Keccak256("0000000000000000000000000000000000000000000000000000000000000001"); } public Coin getMaxRbtc() { return Coin.valueOf(21_000_000, 0); } diff --git a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java index 85c44717ec..a71dabb7f3 100644 --- a/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java @@ -52,7 +52,8 @@ public class BridgeSupportSvpTest { private static final NetworkParameters btcMainnetParams = bridgeMainNetConstants.getBtcParams(); private static final FederationConstants federationMainNetConstants = bridgeMainNetConstants.getFederationConstants(); - private static final Coin spendableValueFromProposedFederation = bridgeMainNetConstants.getSpendableValueFromProposedFederation(); + private static final Coin minPegoutTxValue = bridgeMainNetConstants.getMinimumPegoutTxValue(); + private static final Coin totalValueSentToProposedFederation = bridgeMainNetConstants.getMinimumPegoutTxValue().multiply(2); private static final Coin feePerKb = Coin.valueOf(1000L); private static final Keccak256 svpSpendTxCreationHash = RskTestUtils.createHash(1); @@ -411,14 +412,14 @@ private void assertOneOutputIsChange(List transactionOutputs) private void assertOneOutputIsToProposedFederationWithExpectedAmount(List svpFundTransactionUnsignedOutputs) { Script proposedFederationScriptPubKey = proposedFederation.getP2SHScript(); - assertOutputWasSentToExpectedScriptWithExpectedAmount(svpFundTransactionUnsignedOutputs, proposedFederationScriptPubKey, spendableValueFromProposedFederation); + assertOutputWasSentToExpectedScriptWithExpectedAmount(svpFundTransactionUnsignedOutputs, proposedFederationScriptPubKey, minPegoutTxValue); } private void assertOneOutputIsToProposedFederationWithFlyoverPrefixWithExpectedAmount(List svpFundTransactionUnsignedOutputs) { Script proposedFederationWithFlyoverPrefixScriptPubKey = PegUtils.getFlyoverScriptPubKey(bridgeMainNetConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript()); - assertOutputWasSentToExpectedScriptWithExpectedAmount(svpFundTransactionUnsignedOutputs, proposedFederationWithFlyoverPrefixScriptPubKey, spendableValueFromProposedFederation); + assertOutputWasSentToExpectedScriptWithExpectedAmount(svpFundTransactionUnsignedOutputs, proposedFederationWithFlyoverPrefixScriptPubKey, minPegoutTxValue); } @Test @@ -510,7 +511,7 @@ private void assertSvpFundTxReleaseWasSettled(Sha256Hash svpFundTransactionHashU svpFundTransaction = getSvpFundTransactionFromPegoutsMap(pegoutsWaitingForConfirmations); assertPegoutTxSigHashWasSaved(svpFundTransaction); - assertLogReleaseRequested(rskTx.getHash(), svpFundTransactionHashUnsigned, spendableValueFromProposedFederation); + assertLogReleaseRequested(rskTx.getHash(), svpFundTransactionHashUnsigned, totalValueSentToProposedFederation); assertLogPegoutTransactionCreated(svpFundTransaction); } @@ -741,10 +742,9 @@ private void assertSvpSpendTxHasExpectedInputsAndOutputs() { .multiply(calculatedTransactionSize * 12L / 10L) // back up calculation .divide(1000); - Coin valueToSend = spendableValueFromProposedFederation - .multiply(2) + Coin valueToSendBackToActiveFed = totalValueSentToProposedFederation .minus(fees); - assertOutputWasSentToExpectedScriptWithExpectedAmount(outputs, activeFederation.getP2SHScript(), valueToSend); + assertOutputWasSentToExpectedScriptWithExpectedAmount(outputs, activeFederation.getP2SHScript(), valueToSendBackToActiveFed); } private void assertInputsHaveExpectedScriptSig(List inputs) { @@ -1319,13 +1319,13 @@ private void recreateSvpFundTransactionUnsigned() { Sha256Hash parentTxHash = BitcoinTestUtils.createHash(1); addInput(svpFundTransaction, parentTxHash, proposedFederation.getRedeemScript()); - svpFundTransaction.addOutput(spendableValueFromProposedFederation, proposedFederation.getAddress()); + svpFundTransaction.addOutput(minPegoutTxValue, proposedFederation.getAddress()); Address flyoverProposedFederationAddress = PegUtils.getFlyoverAddress( btcMainnetParams, bridgeMainNetConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript() ); - svpFundTransaction.addOutput(spendableValueFromProposedFederation, flyoverProposedFederationAddress); + svpFundTransaction.addOutput(minPegoutTxValue, flyoverProposedFederationAddress); } private BtcTransaction createPegout(Script redeemScript) { diff --git a/rskj-core/src/test/java/co/rsk/peg/constants/BridgeConstantsTest.java b/rskj-core/src/test/java/co/rsk/peg/constants/BridgeConstantsTest.java index 4884f08397..cd27eba870 100644 --- a/rskj-core/src/test/java/co/rsk/peg/constants/BridgeConstantsTest.java +++ b/rskj-core/src/test/java/co/rsk/peg/constants/BridgeConstantsTest.java @@ -63,25 +63,6 @@ void getMinimumPegoutTxValue(BridgeConstants bridgeConstants, Coin expectedMinim assertEquals(expectedMinimumPegoutTxValue, minimumPegoutTxValue); } - private static Stream spendableValueFromProposedFederationArgProvider() { - BridgeConstants bridgeMainnetConstants = BridgeMainNetConstants.getInstance(); - BridgeConstants bridgeTestnetConstants = BridgeTestNetConstants.getInstance(); - BridgeConstants bridgeRegtestConstants = new BridgeRegTestConstants(); - - return Stream.of( - Arguments.of(bridgeMainnetConstants, bridgeMainnetConstants.getMinimumPegoutTxValue().multiply(2)), - Arguments.of(bridgeTestnetConstants, bridgeTestnetConstants.getMinimumPegoutTxValue().multiply(2)), - Arguments.of(bridgeRegtestConstants, bridgeRegtestConstants.getMinimumPegoutTxValue().multiply(2)) - ); - } - - @ParameterizedTest() - @MethodSource("spendableValueFromProposedFederationArgProvider") - void getSpendableValueFromProposedFederation(BridgeConstants bridgeConstants, Coin expectedSpendableValueFromProposedFederation) { - Coin spendableValueFromProposedFederation = bridgeConstants.getSpendableValueFromProposedFederation(); - assertEquals(expectedSpendableValueFromProposedFederation, spendableValueFromProposedFederation); - } - private static Stream bridgeConstantsArgProvider() { BridgeConstants bridgeMainnetConstants = BridgeMainNetConstants.getInstance(); BridgeConstants bridgeTestnetConstants = BridgeTestNetConstants.getInstance();