Skip to content
Open
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
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ tasks.withType(AbstractArchiveTask) {
}

ext {
bitcoinjcoreVersion = '0.15.6-rsk-5'
bitcoinjVersion = '0.14.4-rsk-18'
bitcoinjcoreVersion = '0.15.6-rsk-6-SNAPSHOT'
bitcoinjVersion = '0.14.4-rsk-19-SNAPSHOT'
commonsLang3Version = '3.12.0'
commonsIoVersion = '2.11.0'
slf4jVersion = '1.7.36'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import java.math.BigInteger;

public enum NetworkDifficultyCap {
MAINNET(new BigInteger("7000000000000000000000")),
TESTNET(BigInteger.valueOf(3000000000L)),
REGTEST(BigInteger.valueOf(20L));
MAINNET(new BigInteger("7000000000000000000000")),
TESTNET2(BigInteger.valueOf(3000000000L)),
TESTNET(BigInteger.valueOf(3000000000L)),
REGTEST(BigInteger.valueOf(20L));
Comment on lines 5 to +9

private final BigInteger difficultyCap;
private final BigInteger difficultyCap;

NetworkDifficultyCap(BigInteger difficultyCap) {
NetworkDifficultyCap(BigInteger difficultyCap) {
this.difficultyCap = difficultyCap;
}
}

public BigInteger getDifficultyCap() {
public BigInteger getDifficultyCap() {
return difficultyCap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,38 +113,36 @@ public BigInteger getDifficultyTarget(HSMBookkeepingClient hsmClient) throws HSM
}
}

/**
* Retrieves the difficulty cap for a given network parameter.
* The difficulty cap is determined based on the network type (mainnet, testnet,
* or regtest). This value will be used to determine the maximum allowed
* difficulty for any given block.
*
* @param networkParameter the network parameter identifier, which can be one of
* the following:
* <ul>
* <li>{@link NetworkParameters#ID_MAINNET} - Mainnet
* network</li>
* <li>{@link NetworkParameters#ID_TESTNET} - Testnet
* network</li>
* <li>{@link NetworkParameters#ID_REGTEST} - Regtest
* network</li>
* </ul>
* @return the difficulty cap as a {@link BigInteger} for the specified network.
* @throws IllegalArgumentException if the provided network parameter is
* invalid.
*/
public BigInteger getDifficultyCap(String networkParameter) {
switch (networkParameter) {
case NetworkParameters.ID_MAINNET:
return NetworkDifficultyCap.MAINNET.getDifficultyCap();
case NetworkParameters.ID_TESTNET:
return NetworkDifficultyCap.TESTNET.getDifficultyCap();
case NetworkParameters.ID_REGTEST:
return NetworkDifficultyCap.REGTEST.getDifficultyCap();
default:
String message = "Invalid network provided: " + networkParameter;
logger.error(message);
throw new IllegalArgumentException(message);
/**
* Retrieves the difficulty cap for a given network parameter.
* The difficulty cap is determined based on the network type (mainnet, testnet,
* or regtest). This value will be used to determine the maximum allowed
* difficulty for any given block.
*
* @param networkParameter the network parameter identifier, which can be one of the following:
* <ul>
* <li>{@link NetworkParameters#ID_MAINNET} - Mainnet network</li>
* <li>{@link NetworkParameters#ID_TESTNET4} - Testnet4 network</li>
* <li>{@link NetworkParameters#ID_TESTNET} - Testnet network</li>
* <li>{@link NetworkParameters#ID_REGTEST} - Regtest network</li>
* </ul>
* @return the difficulty cap as a {@link BigInteger} for the specified network.
* @throws IllegalArgumentException if the provided network parameter is invalid.
*/
Comment on lines +116 to +131
public BigInteger getDifficultyCap(String networkParameter) {
switch (networkParameter) {
case NetworkParameters.ID_MAINNET:
return NetworkDifficultyCap.MAINNET.getDifficultyCap();
case NetworkParameters.ID_TESTNET4:
return NetworkDifficultyCap.TESTNET2.getDifficultyCap();
case NetworkParameters.ID_TESTNET:
Comment on lines +136 to +138
return NetworkDifficultyCap.TESTNET.getDifficultyCap();
case NetworkParameters.ID_REGTEST:
return NetworkDifficultyCap.REGTEST.getDifficultyCap();
default:
String message = "Invalid network provided: " + networkParameter;
logger.error(message);
throw new IllegalArgumentException(message);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ void isStoppingBookkeepingScheduler_whenCustomConfigNotAvailable_shouldReturnDef

@ParameterizedTest
@MethodSource("provideNetworkParametersAndExpectedCaps")
void getDifficultyCap_whenGivenNetwork_shouldMatchExpectedDifficultyCap(String networkId,
NetworkDifficultyCap expectedNetworkDifficultyCap) {
assertEquals(expectedNetworkDifficultyCap.getDifficultyCap(),
powHsmConfig.getDifficultyCap(networkId));
void getDifficultyCap_whenGivenNetwork_shouldMatchExpectedDifficultyCap(
String networkId,
NetworkDifficultyCap expectedNetworkDifficultyCap
) {
assertEquals(
expectedNetworkDifficultyCap.getDifficultyCap(),
powHsmConfig.getDifficultyCap(networkId)
);
}
Comment on lines +151 to 159

@Test
Expand Down Expand Up @@ -179,6 +183,7 @@ private static Stream<Arguments> powHSMConfigParameterProvider() {
static Stream<Arguments> provideNetworkParametersAndExpectedCaps() {
return Stream.of(
Arguments.of(NetworkParameters.ID_MAINNET, NetworkDifficultyCap.MAINNET),
Arguments.of(NetworkParameters.ID_TESTNET4, NetworkDifficultyCap.TESTNET2),
Arguments.of(NetworkParameters.ID_TESTNET, NetworkDifficultyCap.TESTNET),
Arguments.of(NetworkParameters.ID_REGTEST, NetworkDifficultyCap.REGTEST));
}
Expand Down
Loading