Skip to content

Commit

Permalink
Rename Minimum Pegout Constants From BridgeConstants
Browse files Browse the repository at this point in the history
There are 2 bridge constants related to the minimum pegout value. legacyMinimumPegoutTxValueInSatoshis and minimumPegoutTxValueInSatoshis

The name is not precise, because the data type is actually a Coin object, so it’s not an amount and should not have a unit. For this reason, we renamed both constants to legacyMinimumPegoutTxValue and minimumPegoutTxValue respectively.
  • Loading branch information
wilmerrootstock authored and marcos-iov committed May 17, 2024
1 parent f878fd8 commit c70a501
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 50 deletions.
4 changes: 2 additions & 2 deletions rskj-core/src/main/java/co/rsk/peg/BridgeSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ private void requestRelease(Address destinationAddress, Coin value, Transaction
); // add the gap

// The pegout value should be greater or equals than the max of these two values
Coin minValue = Coin.valueOf(Math.max(bridgeConstants.getMinimumPegoutTxValueInSatoshis().value, requireFundsForFee.value));
Coin minValue = Coin.valueOf(Math.max(bridgeConstants.getMinimumPegoutTxValue().value, requireFundsForFee.value));

// Since Iris the peg-out the rule is that the minimum is inclusive
if (value.isLessThan(minValue)) {
Expand All @@ -881,7 +881,7 @@ private void requestRelease(Address destinationAddress, Coin value, Transaction
}
} else {
// For legacy peg-outs the rule stated that the minimum was exclusive
if (!value.isGreaterThan(bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis())) {
if (!value.isGreaterThan(bridgeConstants.getLegacyMinimumPegoutTxValue())) {
optionalRejectedPegoutReason = Optional.of(RejectedPegoutReason.LOW_AMOUNT);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public abstract class BridgeConstants {

protected Coin legacyMinimumPeginTxValue;
protected Coin minimumPeginTxValue;
protected Coin legacyMinimumPegoutTxValueInSatoshis;
protected Coin minimumPegoutTxValueInSatoshis;
protected Coin legacyMinimumPegoutTxValue;
protected Coin minimumPegoutTxValue;

protected long federationActivationAge;
protected long federationActivationAgeLegacy;
Expand Down Expand Up @@ -126,9 +126,9 @@ public Coin getMinimumPeginTxValue(ActivationConfig.ForBlock activations) {
return activations.isActive(ConsensusRule.RSKIP219) ? minimumPeginTxValue : legacyMinimumPeginTxValue;
}

public Coin getLegacyMinimumPegoutTxValueInSatoshis() { return legacyMinimumPegoutTxValueInSatoshis; }
public Coin getLegacyMinimumPegoutTxValue() { return legacyMinimumPegoutTxValue; }

public Coin getMinimumPegoutTxValueInSatoshis() { return minimumPegoutTxValueInSatoshis; }
public Coin getMinimumPegoutTxValue() { return minimumPegoutTxValue; }

public long getFederationActivationAge(ActivationConfig.ForBlock activations) {
return activations.isActive(ConsensusRule.RSKIP383)? federationActivationAge: federationActivationAgeLegacy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public BridgeDevNetConstants(List<BtcECKey> federationPublicKeys) {
maxBtcHeadersPerRskBlock = 500;

legacyMinimumPeginTxValue = Coin.valueOf(1_000_000);
legacyMinimumPegoutTxValueInSatoshis = Coin.valueOf(500_000);
legacyMinimumPegoutTxValue = Coin.valueOf(500_000);
minimumPeginTxValue = Coin.valueOf(500_000);
minimumPegoutTxValueInSatoshis = Coin.valueOf(250_000);
minimumPegoutTxValue = Coin.valueOf(250_000);

// Keys generated with GenNodeKey using generators 'auth-a' through 'auth-e'
List<ECKey> federationChangeAuthorizedKeys = Arrays.stream(new String[]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public class BridgeMainNetConstants extends BridgeConstants {
maxBtcHeadersPerRskBlock = 500;

legacyMinimumPeginTxValue = Coin.valueOf(1_000_000);
legacyMinimumPegoutTxValueInSatoshis = Coin.valueOf(800_000);
legacyMinimumPegoutTxValue = Coin.valueOf(800_000);
minimumPeginTxValue = Coin.valueOf(500_000);
minimumPegoutTxValueInSatoshis = Coin.valueOf(400_000);
minimumPegoutTxValue = Coin.valueOf(400_000);

List<ECKey> federationChangeAuthorizedKeys = Arrays.stream(new String[]{
"04e593d4cde25137b13f19462bc4c02e97ba2ed5a3860813497abf9b4eeb9259e37e0384d12cfd2d9a7a0ba606b31ee34317a9d7f4a8591c6bcf5dfd5563248b2f",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public BridgeRegTestConstants(List<BtcECKey> federationPublicKeys) {
maxBtcHeadersPerRskBlock = 500;

legacyMinimumPeginTxValue = Coin.COIN;
legacyMinimumPegoutTxValueInSatoshis = Coin.valueOf(500_000);
legacyMinimumPegoutTxValue = Coin.valueOf(500_000);
minimumPeginTxValue = Coin.COIN.div(2);
minimumPegoutTxValueInSatoshis = Coin.valueOf(250_000);
minimumPegoutTxValue = Coin.valueOf(250_000);

// Keys generated with GenNodeKey using generators 'auth-a' through 'auth-e'
List<ECKey> federationChangeAuthorizedKeys = Arrays.stream(new String[]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public class BridgeTestNetConstants extends BridgeConstants {

legacyMinimumPeginTxValue = Coin.valueOf(1_000_000);
minimumPeginTxValue = Coin.valueOf(500_000);
legacyMinimumPegoutTxValueInSatoshis = Coin.valueOf(500_000);
minimumPegoutTxValueInSatoshis = Coin.valueOf(250_000);
legacyMinimumPegoutTxValue = Coin.valueOf(500_000);
minimumPegoutTxValue = Coin.valueOf(250_000);

// Passphrases are kept private
List<ECKey> federationChangeAuthorizedKeys = Arrays.stream(new String[]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,7 @@ void pegout_many_outputs_and_inputs_with_change_output(
);
}

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4);
for (int i = 0; i < 10; i++) {
btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), BitcoinTestUtils.createP2PKHAddress(btcMainnetParams, "user" + i));
Expand Down Expand Up @@ -1705,7 +1705,7 @@ void pegout_many_outputs_and_one_input(
ScriptBuilder.createP2SHMultiSigInputScript(null, activeFederation.getRedeemScript())
);

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4);
for (int i = 0; i < 10; i++) {
btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), BitcoinTestUtils.createP2PKHAddress(btcMainnetParams, "user" + i));
Expand Down Expand Up @@ -1788,7 +1788,7 @@ void pegout_one_output_and_many_input(
);
}

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
btcTransaction.addOutput(minimumPegoutTxValue, userAddress);

FederationTestUtils.addSignatures(activeFederation, activeFedSigners, btcTransaction);
Expand Down Expand Up @@ -1946,7 +1946,7 @@ void migration_many_outputs_and_inputs(
);
}

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4);
for (int i = 0; i < 10; i++) {
btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), activeFederation.getAddress());
Expand Down Expand Up @@ -2013,7 +2013,7 @@ void migration_many_outputs_and_one_input(
ScriptBuilder.createP2SHMultiSigInputScript(null, retiringFederation.getRedeemScript())
);

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4);
for (int i = 0; i < 10; i++) {
btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), activeFederation.getAddress());
Expand Down Expand Up @@ -2083,7 +2083,7 @@ void migration_one_outputs_and_many_input(
);
}

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
btcTransaction.addOutput(minimumPegoutTxValue, activeFederation.getAddress());

FederationTestUtils.addSignatures(retiringFederation, retiringFedSigners, btcTransaction);
Expand Down
36 changes: 18 additions & 18 deletions rskj-core/src/test/java/co/rsk/peg/BridgeSupportReleaseBtcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,10 @@ void release_after_rskip_219() throws IOException {
bridgeSupport = initBridgeSupport(eventLogger, activationMock);

// Get a value between old and new minimum pegout values
Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis().subtract(bridgeConstants.getMinimumPegoutTxValueInSatoshis()).div(2);
Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(middle);
Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis()));
Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValueInSatoshis()));
Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValue().subtract(bridgeConstants.getMinimumPegoutTxValue()).div(2);
Coin value = bridgeConstants.getMinimumPegoutTxValue().add(middle);
Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValue()));
Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValue()));
bridgeSupport.releaseBtc(buildReleaseRskTx(value));

Transaction rskTx = buildUpdateTx();
Expand Down Expand Up @@ -465,10 +465,10 @@ void release_after_rskip_219_326() throws IOException {
bridgeSupport = initBridgeSupport(eventLogger, activationMock);

// Get a value between old and new minimum pegout values
Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis().subtract(bridgeConstants.getMinimumPegoutTxValueInSatoshis()).div(2);
Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(middle);
Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis()));
Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValueInSatoshis()));
Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValue().subtract(bridgeConstants.getMinimumPegoutTxValue()).div(2);
Coin value = bridgeConstants.getMinimumPegoutTxValue().add(middle);
Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValue()));
Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValue()));
bridgeSupport.releaseBtc(buildReleaseRskTx(value));

Transaction rskTx = buildUpdateTx();
Expand Down Expand Up @@ -498,10 +498,10 @@ void release_before_rskip_219() throws IOException {
bridgeSupport = initBridgeSupport(eventLogger, activationMock);

// Get a value between old and new minimum pegout values
Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis().subtract(bridgeConstants.getMinimumPegoutTxValueInSatoshis()).div(2);
Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(middle);
Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis()));
Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValueInSatoshis()));
Coin middle = bridgeConstants.getLegacyMinimumPegoutTxValue().subtract(bridgeConstants.getMinimumPegoutTxValue()).div(2);
Coin value = bridgeConstants.getMinimumPegoutTxValue().add(middle);
Assertions.assertTrue(value.isLessThan(bridgeConstants.getLegacyMinimumPegoutTxValue()));
Assertions.assertTrue(value.isGreaterThan(bridgeConstants.getMinimumPegoutTxValue()));
bridgeSupport.releaseBtc(buildReleaseRskTx(value));

Transaction rskTx = buildUpdateTx();
Expand All @@ -525,7 +525,7 @@ void release_before_rskip_219_minimum_exclusive() throws IOException {
bridgeSupport = initBridgeSupport(eventLogger, activationMock);

// Get a value exactly to legacy minimum
Coin value = bridgeConstants.getLegacyMinimumPegoutTxValueInSatoshis();
Coin value = bridgeConstants.getLegacyMinimumPegoutTxValue();
bridgeSupport.releaseBtc(buildReleaseRskTx(value));

Transaction rskTx = buildUpdateTx();
Expand All @@ -549,7 +549,7 @@ void release_after_rskip_219_minimum_inclusive() throws IOException {
bridgeSupport = initBridgeSupport(eventLogger, activationMock);

// Get a value exactly to current minimum
Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis();
Coin value = bridgeConstants.getMinimumPegoutTxValue();
bridgeSupport.releaseBtc(buildReleaseRskTx(value));

Transaction rskTx = buildUpdateTx();
Expand Down Expand Up @@ -580,7 +580,7 @@ void release_after_rskip_219_326_minimum_inclusive() throws IOException {
bridgeSupport = initBridgeSupport(eventLogger, activationMock);

// Get a value exactly to current minimum
Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis();
Coin value = bridgeConstants.getMinimumPegoutTxValue();
bridgeSupport.releaseBtc(buildReleaseRskTx(value));

Transaction rskTx = buildUpdateTx();
Expand All @@ -602,7 +602,7 @@ void release_after_rskip_219_326_minimum_inclusive() throws IOException {

@Test
void release_verify_fee_below_fee_is_rejected() throws IOException {
Coin value = bridgeConstants.getMinimumPegoutTxValueInSatoshis().add(Coin.SATOSHI);
Coin value = bridgeConstants.getMinimumPegoutTxValue().add(Coin.SATOSHI);

testPegoutMinimumWithFeeVerification(Coin.COIN, value, false);
}
Expand Down Expand Up @@ -633,7 +633,7 @@ void release_verify_fee_above_fee_but_below_gap_is_rejected_after_rskip_271() th
void release_verify_fee_above_fee_but_below_minimum_is_rejected() throws IOException {
testPegoutMinimumWithFeeVerification(
Coin.MILLICOIN,
bridgeConstants.getMinimumPegoutTxValueInSatoshis().minus(Coin.SATOSHI),
bridgeConstants.getMinimumPegoutTxValue().minus(Coin.SATOSHI),
false
);
}
Expand Down Expand Up @@ -1147,7 +1147,7 @@ private void testPegoutMinimumWithFeeVerification(Coin feePerKB, Coin value, boo
// if shouldPegout true then value should be greater or equals than both required fee plus gap and min pegout value
// if shouldPegout false then value should be smaller than any of those minimums
Assertions.assertEquals(!shouldPegout, value.isLessThan(minValueWithGapAboveFee) ||
value.isLessThan(bridgeConstants.getMinimumPegoutTxValueInSatoshis()));
value.isLessThan(bridgeConstants.getMinimumPegoutTxValue()));

bridgeSupport.releaseBtc(buildReleaseRskTx(value));

Expand Down
12 changes: 6 additions & 6 deletions rskj-core/src/test/java/co/rsk/peg/BridgeTestIntegration.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ void callUpdateCollectionsWithSignatureNotFromFederation() throws IOException {

@Test
void callUpdateCollectionsWithTransactionsWaitingForConfirmation() throws IOException, VMException {
BtcTransaction tx1 = createTransaction(2, bridgeRegTestConstants.getMinimumPegoutTxValueInSatoshis());
BtcTransaction tx2 = createTransaction(3, bridgeRegTestConstants.getMinimumPegoutTxValueInSatoshis().add(Coin.MILLICOIN));
BtcTransaction tx3 = createTransaction(4, bridgeRegTestConstants.getMinimumPegoutTxValueInSatoshis().add(Coin.MILLICOIN).add(Coin.MILLICOIN));
BtcTransaction tx1 = createTransaction(2, bridgeRegTestConstants.getMinimumPegoutTxValue());
BtcTransaction tx2 = createTransaction(3, bridgeRegTestConstants.getMinimumPegoutTxValue().add(Coin.MILLICOIN));
BtcTransaction tx3 = createTransaction(4, bridgeRegTestConstants.getMinimumPegoutTxValue().add(Coin.MILLICOIN).add(Coin.MILLICOIN));

Repository repository = createRepository();
Repository track = repository.startTracking();
Expand Down Expand Up @@ -275,9 +275,9 @@ void callUpdateCollectionsWithTransactionsWaitingForConfirmation() throws IOExce

@Test
void callUpdateCollectionsWithTransactionsWaitingForConfirmationWithEnoughConfirmations() throws IOException, VMException {
BtcTransaction tx1 = createTransaction(2, bridgeRegTestConstants.getMinimumPegoutTxValueInSatoshis());
BtcTransaction tx2 = createTransaction(3, bridgeRegTestConstants.getMinimumPegoutTxValueInSatoshis().add(Coin.MILLICOIN));
BtcTransaction tx3 = createTransaction(4, bridgeRegTestConstants.getMinimumPegoutTxValueInSatoshis().add(Coin.MILLICOIN).add(Coin.MILLICOIN));
BtcTransaction tx1 = createTransaction(2, bridgeRegTestConstants.getMinimumPegoutTxValue());
BtcTransaction tx2 = createTransaction(3, bridgeRegTestConstants.getMinimumPegoutTxValue().add(Coin.MILLICOIN));
BtcTransaction tx3 = createTransaction(4, bridgeRegTestConstants.getMinimumPegoutTxValue().add(Coin.MILLICOIN).add(Coin.MILLICOIN));

Repository repository = createRepository();
Repository track = repository.startTracking();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ void many_outputs_and_inputs_pegout(
);
}

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4);
for (int i = 0; i < 10; i++) {
btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), BitcoinTestUtils.createP2PKHAddress(btcMainnetParams, "user" + i ));
Expand Down Expand Up @@ -1170,7 +1170,7 @@ void many_outputs_and_one_input_pegout(
ScriptBuilder.createP2SHMultiSigInputScript(null, activeFederation.getRedeemScript())
);

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4);
for (int i = 0; i < 10; i++) {
btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), BitcoinTestUtils.createP2PKHAddress(btcMainnetParams, "user" + i ));
Expand Down Expand Up @@ -1231,7 +1231,7 @@ void one_outputs_and_many_input_pegout(
);
}

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
btcTransaction.addOutput(minimumPegoutTxValue, userAddress);

FederationTestUtils.addSignatures(activeFederation, activeFedSigners, btcTransaction);
Expand Down Expand Up @@ -1434,7 +1434,7 @@ void many_outputs_and_inputs_migration(
);
}

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4);
for (int i = 0; i < 10; i++) {
btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), activeFederation.getAddress());
Expand Down Expand Up @@ -1495,7 +1495,7 @@ void many_outputs_and_one_input_migration(
ScriptBuilder.createP2SHMultiSigInputScript(null, retiringFederation.getRedeemScript())
);

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
Coin quarterMinimumPegoutTxValue = minimumPegoutTxValue.div(4);
for (int i = 0; i < 10; i++) {
btcTransaction.addOutput(quarterMinimumPegoutTxValue.add(Coin.CENT), activeFederation.getAddress());
Expand Down Expand Up @@ -1557,7 +1557,7 @@ void one_outputs_and_many_input_migration(
);
}

Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValueInSatoshis();
Coin minimumPegoutTxValue = bridgeMainnetConstants.getMinimumPegoutTxValue();
btcTransaction.addOutput(minimumPegoutTxValue, activeFederation.getAddress());

FederationTestUtils.addSignatures(retiringFederation, retiringFedSigners, btcTransaction);
Expand Down

0 comments on commit c70a501

Please sign in to comment.