Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not shuffle fundTx outputs order #2919

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ private SendRequest createSvpFundTransactionSendRequest(BtcTransaction transacti
sendRequest.feePerKb = feePerKbSupport.getFeePerKb();
sendRequest.missingSigsMode = Wallet.MissingSigsMode.USE_OP_ZERO;
sendRequest.recipientsPayFees = false;
sendRequest.shuffleOutputs = false;

return sendRequest;
}
Expand Down
40 changes: 15 additions & 25 deletions rskj-core/src/test/java/co/rsk/peg/BridgeSupportSvpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,22 @@ void updateCollections_whenFundTxCanBeCreated_createsExpectedFundTxAndSavesTheHa
private void assertSvpFundTransactionHasExpectedInputsAndOutputs() {
assertInputsAreFromActiveFederation();

List<TransactionOutput> svpFundTransactionUnsignedOutputs = svpFundTransaction.getOutputs();
int svpFundTransactionUnsignedOutputsExpectedSize = 3;
assertEquals(svpFundTransactionUnsignedOutputsExpectedSize, svpFundTransactionUnsignedOutputs.size());
assertOneOutputIsChange(svpFundTransactionUnsignedOutputs);
assertOneOutputIsToProposedFederationWithExpectedAmount(svpFundTransactionUnsignedOutputs);
assertOneOutputIsToProposedFederationWithFlyoverPrefixWithExpectedAmount(svpFundTransactionUnsignedOutputs);
assertEquals(svpFundTransactionUnsignedOutputsExpectedSize, svpFundTransaction.getOutputs().size());

// assert outputs are the expected ones in the expected order
TransactionOutput outputToProposedFed = svpFundTransaction.getOutput(0);
assertEquals(outputToProposedFed.getScriptPubKey(), proposedFederation.getP2SHScript());
assertEquals(outputToProposedFed.getValue(), bridgeMainNetConstants.getMinimumPegoutTxValue());

TransactionOutput outputToFlyoverProposedFed = svpFundTransaction.getOutput(1);
Script proposedFederationWithFlyoverPrefixScriptPubKey =
PegUtils.getFlyoverScriptPubKey(bridgeMainNetConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript());
assertEquals(outputToFlyoverProposedFed.getScriptPubKey(), proposedFederationWithFlyoverPrefixScriptPubKey);
assertEquals(outputToFlyoverProposedFed.getValue(), bridgeMainNetConstants.getMinimumPegoutTxValue());

TransactionOutput changeOutput = svpFundTransaction.getOutput(2);
assertEquals(changeOutput.getScriptPubKey(), activeFederation.getP2SHScript());
}

private void assertInputsAreFromActiveFederation() {
Expand All @@ -402,26 +412,6 @@ private void assertInputsAreFromActiveFederation() {
}
}

private void assertOneOutputIsChange(List<TransactionOutput> transactionOutputs) {
Script activeFederationScriptPubKey = activeFederation.getP2SHScript();

Optional<TransactionOutput> changeOutputOpt = searchForOutput(transactionOutputs, activeFederationScriptPubKey);
assertTrue(changeOutputOpt.isPresent());
}

private void assertOneOutputIsToProposedFederationWithExpectedAmount(List<TransactionOutput> svpFundTransactionUnsignedOutputs) {
Script proposedFederationScriptPubKey = proposedFederation.getP2SHScript();

assertOutputWasSentToExpectedScriptWithExpectedAmount(svpFundTransactionUnsignedOutputs, proposedFederationScriptPubKey, minPegoutTxValue);
}

private void assertOneOutputIsToProposedFederationWithFlyoverPrefixWithExpectedAmount(List<TransactionOutput> svpFundTransactionUnsignedOutputs) {
Script proposedFederationWithFlyoverPrefixScriptPubKey =
PegUtils.getFlyoverScriptPubKey(bridgeMainNetConstants.getProposedFederationFlyoverPrefix(), proposedFederation.getRedeemScript());

assertOutputWasSentToExpectedScriptWithExpectedAmount(svpFundTransactionUnsignedOutputs, proposedFederationWithFlyoverPrefixScriptPubKey, minPegoutTxValue);
}

@Test
void updateCollections_whenWaitingForFundTxToBeRegistered_shouldNotCreateFundTransactionAgain() throws Exception {
// arrange
Expand Down
Loading