Skip to content

Commit

Permalink
Add estimatedPegoutTxIndexBtcActivationHeight and pegoutTxIndexGraceP…
Browse files Browse the repository at this point in the history
…eriodInBtcBlocks constant
  • Loading branch information
nathanieliov committed Oct 19, 2023
1 parent 18ff58b commit 53e8d1e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
12 changes: 12 additions & 0 deletions rskj-core/src/main/java/co/rsk/config/BridgeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public abstract class BridgeConstants {

protected int numberOfBlocksBetweenPegouts;

protected long estimatedPegoutTxIndexBtcActivationHeight;

protected long pegoutTxIndexGracePeriodInBtcBlocks;

public NetworkParameters getBtcParams() {
return NetworkParameters.fromID(btcParamsString);
}
Expand Down Expand Up @@ -185,4 +189,12 @@ public int getMaxInputsPerPegoutTransaction() {
public int getNumberOfBlocksBetweenPegouts() {
return numberOfBlocksBetweenPegouts;
}

public long getEstimatedPegoutTxIndexBtcActivationHeight() {
return estimatedPegoutTxIndexBtcActivationHeight;
}

public long getPegoutTxIndexGracePeriodInBtcBlocks() {
return pegoutTxIndexGracePeriodInBtcBlocks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,8 @@ public BridgeDevNetConstants(List<BtcECKey> federationPublicKeys) {
maxInputsPerPegoutTransaction = 10;

numberOfBlocksBetweenPegouts = 360; // 3 hours of RSK blocks (considering 1 block every 30 seconds)

estimatedPegoutTxIndexBtcActivationHeight = 1; // TODO: TBD. This is an estimation of the btc block number once RSKIP379 is activated.
pegoutTxIndexGracePeriodInBtcBlocks = 500; // TODO: TBD. Period of grace in btc blocks to continue using the legacy mechanism to identify btc tx.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import co.rsk.peg.FederationMember;
import com.google.common.collect.Lists;
import org.bouncycastle.util.encoders.Hex;
import org.ethereum.config.blockchain.upgrades.ConsensusRule;
import org.ethereum.config.blockchain.upgrades.NetworkUpgrade;
import org.ethereum.crypto.ECKey;

import java.time.Instant;
Expand Down Expand Up @@ -151,6 +153,9 @@ public class BridgeMainNetConstants extends BridgeConstants {
maxInputsPerPegoutTransaction = 50;

numberOfBlocksBetweenPegouts = 360; // 3 hours of RSK blocks (considering 1 block every 30 seconds)

estimatedPegoutTxIndexBtcActivationHeight = 1; // TODO: TBD. This is an estimation of the btc block number once RSKIP379 is activated.
pegoutTxIndexGracePeriodInBtcBlocks = 500; // TODO: TBD. Period of grace in btc blocks to continue using the legacy mechanism to identify btc tx.
}

public static BridgeMainNetConstants getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public BridgeRegTestConstants(List<BtcECKey> federationPublicKeys) {
maxInputsPerPegoutTransaction = 10;

numberOfBlocksBetweenPegouts = 50; // 25 Minutes of RSK blocks (considering 1 block every 30 seconds)

estimatedPegoutTxIndexBtcActivationHeight = 1; // TODO: TBD. This is an estimation of the btc block number once RSKIP379 is activated.
pegoutTxIndexGracePeriodInBtcBlocks = 500; // TODO: TBD. Period of grace in btc blocks to continue using the legacy mechanism to identify btc tx.
}

public static BridgeRegTestConstants getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public class BridgeTestNetConstants extends BridgeConstants {
maxInputsPerPegoutTransaction = 50;

numberOfBlocksBetweenPegouts = 360; // 3 hours of RSK blocks (considering 1 block every 30 seconds)

estimatedPegoutTxIndexBtcActivationHeight = 1; // TODO: TBD. This is an estimation of the btc block number once RSKIP379 is activated.
pegoutTxIndexGracePeriodInBtcBlocks = 500; // TODO: TBD. Period of grace in btc blocks to continue using the legacy mechanism to identify btc tx.
}

public static BridgeTestNetConstants getInstance() {
Expand Down
29 changes: 29 additions & 0 deletions rskj-core/src/test/java/co/rsk/config/BridgeConstantsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import co.rsk.bitcoinj.core.Coin;
import org.ethereum.config.blockchain.upgrades.ActivationConfig;
import org.ethereum.config.blockchain.upgrades.ConsensusRule;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -122,4 +123,32 @@ void test_getMinimumPeginTxValue(BridgeConstants bridgeConstants, boolean isRSKI
assertEquals(bridgeConstants.legacyMinimumPeginTxValue, minimumPeginTxValue);
}
}

private static Stream<Arguments> bridgeConstantsArgProvider() {
return Stream.of(
Arguments.of(BridgeMainNetConstants.getInstance()),
Arguments.of(BridgeTestNetConstants.getInstance()),
Arguments.of(BridgeRegTestConstants.getInstance())
);
}

@ParameterizedTest()
@MethodSource("bridgeConstantsArgProvider")
void test_getEstimatedPegoutTxIndexBtcActivationHeight(BridgeConstants bridgeConstants){
// Act
long estimatedPegoutTxIndexBtcActivationHeight = bridgeConstants.getEstimatedPegoutTxIndexBtcActivationHeight();

// assert
Assertions.assertTrue(estimatedPegoutTxIndexBtcActivationHeight > 0);
}

@ParameterizedTest()
@MethodSource("bridgeConstantsArgProvider")
void test_getPegoutTxIndexGracePeriodInBtcBlocks(BridgeConstants bridgeConstants){
// Act
long pegoutTxIndexGracePeriodInBtcBlocks = bridgeConstants.getPegoutTxIndexGracePeriodInBtcBlocks();

// assert
Assertions.assertTrue(pegoutTxIndexGracePeriodInBtcBlocks > 0);
}
}

0 comments on commit 53e8d1e

Please sign in to comment.