Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ void setup() throws IOException {
String.format("-Xrpc.providers.web.http.port=%s", port)
};
strBaseArgs = String.join(" ", baseArgs);
baseJavaCmd = String.format("java %s %s", String.format("-Dlogback.configurationFile=%s", logbackXmlFile), String.format("-Drsk.conf.file=%s", rskConfFile));
baseJavaCmd = String.format("java %s %s", String.format("-Dlogback.configurationFile=%s", logbackXmlFile),
String.format("-Drsk.conf.file=%s", rskConfFile));
} catch (Exception e) {
// Ensure cleanup on setup failure
cleanupTempFiles();
Expand All @@ -113,7 +114,8 @@ void whenExportBlocksRuns_shouldExportSpecifiedBlocks() throws Exception {

blocksFile = createTempFile("blocks.txt");

String cmd = String.format("%s -cp %s/%s co.rsk.cli.tools.ExportBlocks --fromBlock 0 --toBlock %s --file %s %s",
String cmd = String.format(
"%s -cp %s/%s co.rsk.cli.tools.ExportBlocks --fromBlock 0 --toBlock %s --file %s %s",
baseJavaCmd, buildLibsPath, jarName, blockNumber, blocksFile, strBaseArgs);
executeCommand(cmd, 1, TimeUnit.MINUTES);

Expand All @@ -126,7 +128,8 @@ void whenExportBlocksRuns_shouldExportSpecifiedBlocks() throws Exception {
String[] exportedBlocksLineParts = exportedBlocksLine.split(",");

Assertions.assertFalse(exportedBlocksLines.isEmpty());
Assertions.assertTrue(blockInfo.transactionsNode.get(0).get("blockHash").asText().contains(exportedBlocksLineParts[1]));
Assertions.assertTrue(
blockInfo.transactionsNode.get(0).get("blockHash").asText().contains(exportedBlocksLineParts[1]));
} finally {
safeDeleteFile(blocksFile);
}
Expand Down Expand Up @@ -174,7 +177,8 @@ void whenShowStateInfoRuns_shouldShowSpecifiedState() throws Exception {
List<String> stateInfoLines = Arrays.asList(showStateInfoProc.getOutput().split("\\n"));

Assertions.assertFalse(stateInfoLines.isEmpty());
Assertions.assertTrue(stateInfoLines.stream().anyMatch(l -> l.contains(HexUtils.removeHexPrefix(blockInfo.blockHash))));
Assertions.assertTrue(
stateInfoLines.stream().anyMatch(l -> l.contains(HexUtils.removeHexPrefix(blockInfo.blockHash))));
}

@Test
Expand Down Expand Up @@ -238,7 +242,8 @@ void whenImportBlocksRuns_shouldImportAllExportedBlocks() throws Exception {

blocksFile = createTempFile("blocks.txt");

String cmd = String.format("%s -cp %s/%s co.rsk.cli.tools.ExportBlocks --fromBlock 0 --toBlock 20 --file %s %s",
String cmd = String.format(
"%s -cp %s/%s co.rsk.cli.tools.ExportBlocks --fromBlock 0 --toBlock 20 --file %s %s",
baseJavaCmd, buildLibsPath, jarName, blocksFile, strBaseArgs);
executeCommand(cmd, 1, TimeUnit.MINUTES);

Expand Down Expand Up @@ -359,47 +364,58 @@ void whenRewindBlocksRuns_shouldRewindSpecifiedBlocks() throws Exception {

@Test
void whenDbMigrateRuns_shouldMigrateLevelDbToRocksDbAndShouldStartNodeWithPrevDbKind() throws Exception {
String cmd = String.format("%s -cp %s/%s co.rsk.Start --reset %s", baseJavaCmd, buildLibsPath, jarName, strBaseArgs);
CommandLineFixture.runCommand(cmd, 1, TimeUnit.MINUTES, false);
String cmd = String.format("%s -cp %s/%s co.rsk.Start --reset %s", baseJavaCmd, buildLibsPath, jarName,
strBaseArgs);
CommandLineFixture.CustomProcess startProc = executeCommand(cmd, 5, TimeUnit.MINUTES);
validateProcessOutput(startProc, "[minerserver]");

cmd = String.format("%s -cp %s/%s co.rsk.cli.tools.DbMigrate --targetDb rocksdb %s", baseJavaCmd, buildLibsPath, jarName, strBaseArgs);
CommandLineFixture.CustomProcess dbMigrateProc = CommandLineFixture.runCommand(cmd, 1, TimeUnit.MINUTES);
cmd = String.format("%s -cp %s/%s co.rsk.cli.tools.DbMigrate --targetDb rocksdb %s", baseJavaCmd, buildLibsPath,
jarName, strBaseArgs);
CommandLineFixture.CustomProcess dbMigrateProc = executeCommand(cmd, 5, TimeUnit.MINUTES);
validateProcessOutput(dbMigrateProc, "DbMigrate finished");

cmd = String.format("%s -cp %s/%s co.rsk.Start --regtest %s", baseJavaCmd, buildLibsPath, jarName, strBaseArgs);
CommandLineFixture.CustomProcess proc = CommandLineFixture.runCommand(cmd, 1, TimeUnit.MINUTES, false);
CommandLineFixture.CustomProcess proc = CommandLineFixture.runCommand(cmd, 5, TimeUnit.MINUTES, false);
validateProcessOutput(proc, "[minerserver]");

List<String> logLines = Arrays.asList(proc.getOutput().split("\\n"));

Assertions.assertTrue(dbMigrateProc.getOutput().contains("DbMigrate finished"));
Assertions.assertTrue(logLines.stream().anyMatch(l -> l.contains("[minerserver] [miner client] Mined block import result is IMPORTED_BEST")));
Assertions.assertTrue(logLines.stream()
.anyMatch(l -> l.contains("[minerserver] [miner client] Mined block import result is IMPORTED_BEST")));
Assertions.assertTrue(logLines.stream().noneMatch(l -> l.contains("Exception:")));
}

@Test
void whenDbMigrateRuns_shouldMigrateLevelDbToRocksDbAndShouldStartNodeSuccessfully() throws Exception {
String cmd = String.format("%s -cp %s/%s co.rsk.Start --reset %s", baseJavaCmd, buildLibsPath, jarName, strBaseArgs);
CommandLineFixture.runCommand(cmd, 1, TimeUnit.MINUTES);
String cmd = String.format("%s -cp %s/%s co.rsk.Start --reset %s", baseJavaCmd, buildLibsPath, jarName,
strBaseArgs);
CommandLineFixture.CustomProcess startProc = executeCommand(cmd, 5, TimeUnit.MINUTES);
validateProcessOutput(startProc, "[minerserver]");

cmd = String.format("%s -cp %s/%s co.rsk.cli.tools.DbMigrate --targetDb rocksdb %s", baseJavaCmd, buildLibsPath, jarName, strBaseArgs);
CommandLineFixture.CustomProcess dbMigrateProc = CommandLineFixture.runCommand(cmd, 1, TimeUnit.MINUTES);
cmd = String.format("%s -cp %s/%s co.rsk.cli.tools.DbMigrate --targetDb rocksdb %s", baseJavaCmd, buildLibsPath,
jarName, strBaseArgs);
CommandLineFixture.CustomProcess dbMigrateProc = executeCommand(cmd, 5, TimeUnit.MINUTES);
validateProcessOutput(dbMigrateProc, "DbMigrate finished");

LinkedList<String> args = Stream.of(baseArgs)
.map(arg -> arg.equals("-Xkeyvalue.datasource=leveldb") ? "-Xkeyvalue.datasource=rocksdb" : arg)
.collect(Collectors.toCollection(LinkedList::new));

cmd = String.format("%s -cp %s/%s co.rsk.Start %s", baseJavaCmd, buildLibsPath, jarName, String.join(" ", args));
CommandLineFixture.CustomProcess proc = CommandLineFixture.runCommand(cmd, 1, TimeUnit.MINUTES);
cmd = String.format("%s -cp %s/%s co.rsk.Start %s", baseJavaCmd, buildLibsPath, jarName,
String.join(" ", args));
CommandLineFixture.CustomProcess proc = executeCommand(cmd, 5, TimeUnit.MINUTES);

List<String> logLines = Arrays.asList(proc.getOutput().split("\\n"));

Assertions.assertTrue(dbMigrateProc.getOutput().contains("DbMigrate finished"));
Assertions.assertTrue(logLines.stream().anyMatch(l -> l.contains("[minerserver] [miner client] Mined block import result is IMPORTED_BEST")));
Assertions.assertTrue(logLines.stream()
.anyMatch(l -> l.contains("[minerserver] [miner client] Mined block import result is IMPORTED_BEST")));
Assertions.assertTrue(logLines.stream().noneMatch(l -> l.contains("Exception:")));
}

@Test
void whenStartBootstrapRuns_shouldRunSuccessfully() throws Exception {
String cmd = String.format("%s -cp %s/%s co.rsk.cli.tools.StartBootstrap --reset %s", baseJavaCmd, buildLibsPath, jarName, strBaseArgs);
String cmd = String.format("%s -cp %s/%s co.rsk.cli.tools.StartBootstrap --reset %s", baseJavaCmd,
buildLibsPath, jarName, strBaseArgs);
CommandLineFixture.CustomProcess proc = CommandLineFixture.runCommand(cmd, 1, TimeUnit.MINUTES);

Assertions.assertTrue(proc.getOutput().contains("Identified public IP"));
Expand All @@ -408,12 +424,14 @@ void whenStartBootstrapRuns_shouldRunSuccessfully() throws Exception {

@Test
void whenIndexBloomsRuns_shouldIndexBlockRangeSInBLoomsDbSuccessfully() throws Exception {
String cmd = String.format("%s -cp %s/%s co.rsk.Start --reset %s", baseJavaCmd, buildLibsPath, jarName, strBaseArgs);
String cmd = String.format("%s -cp %s/%s co.rsk.Start --reset %s", baseJavaCmd, buildLibsPath, jarName,
strBaseArgs);
CommandLineFixture.runCommand(cmd, 1, TimeUnit.MINUTES);

FileUtil.recursiveDelete(bloomsDbDir);

cmd = String.format("%s -cp %s/%s co.rsk.cli.tools.IndexBlooms -fb %s -tb %s %s", baseJavaCmd, buildLibsPath, jarName, "earliest", "latest", strBaseArgs);
cmd = String.format("%s -cp %s/%s co.rsk.cli.tools.IndexBlooms -fb %s -tb %s %s", baseJavaCmd, buildLibsPath,
jarName, "earliest", "latest", strBaseArgs);
CommandLineFixture.CustomProcess proc = CommandLineFixture.runCommand(cmd, 1, TimeUnit.MINUTES);

Assertions.assertTrue(proc.getOutput().contains("[c.r.c.t.IndexBlooms] [main] Processed "));
Expand Down Expand Up @@ -444,7 +462,8 @@ private Path createFileWithRetry(Path filePath) throws IOException {
}
} catch (IOException e) {
if (attempt == maxRetries - 1) {
throw new IOException("Failed to create file " + filePath + " after " + maxRetries + " attempts", e);
throw new IOException("Failed to create file " + filePath + " after " + maxRetries + " attempts",
e);
}
try {
Thread.sleep(retryDelayMs * (attempt + 1));
Expand All @@ -459,7 +478,8 @@ private Path createFileWithRetry(Path filePath) throws IOException {

private void writeToFile(Path filePath, String content) throws IOException {
try {
Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
Files.write(filePath, content.getBytes(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.WRITE);
} catch (IOException e) {
throw new IOException("Failed to write to file " + filePath, e);
}
Expand Down Expand Up @@ -488,7 +508,8 @@ private void safeDeleteFile(Path filePath) {
} catch (IOException e) {
if (attempt == maxRetries - 1) {
// Log warning but don't fail the test
System.err.println("Warning: Failed to delete file " + filePath + " after " + maxRetries + " attempts: " + e.getMessage());
System.err.println("Warning: Failed to delete file " + filePath + " after " + maxRetries
+ " attempts: " + e.getMessage());
} else {
try {
Thread.sleep(retryDelayMs * (attempt + 1));
Expand Down Expand Up @@ -566,7 +587,8 @@ private void closeRskContext(RskContext rskContext) {
/**
* Executes a command and waits for it to complete
*/
private CommandLineFixture.CustomProcess executeCommand(String cmd, int timeout, TimeUnit timeUnit) throws InterruptedException, IOException {
private CommandLineFixture.CustomProcess executeCommand(String cmd, int timeout, TimeUnit timeUnit)
throws InterruptedException, IOException {
return CommandLineFixture.runCommand(cmd, timeout, timeUnit);
}

Expand All @@ -582,15 +604,17 @@ private void executeCommandWithCallback(String cmd, int timeout, TimeUnit timeUn
* Starts RSK node and waits for it to be ready
*/
private void startRskNode() throws Exception {
String cmd = String.format("%s -cp %s/%s co.rsk.Start --reset %s", baseJavaCmd, buildLibsPath, jarName, strBaseArgs);
String cmd = String.format("%s -cp %s/%s co.rsk.Start --reset %s", baseJavaCmd, buildLibsPath, jarName,
strBaseArgs);
executeCommand(cmd, 1, TimeUnit.MINUTES);
}

/**
* Starts RSK node and waits for it to be ready with callback
*/
private void startRskNodeWithCallback(java.util.function.Consumer<Process> callback) throws Exception {
String cmd = String.format("%s -cp %s/%s co.rsk.Start --reset %s", baseJavaCmd, buildLibsPath, jarName, strBaseArgs);
String cmd = String.format("%s -cp %s/%s co.rsk.Start --reset %s", baseJavaCmd, buildLibsPath, jarName,
strBaseArgs);
executeCommandWithCallback(cmd, 1, TimeUnit.MINUTES, callback);
}

Expand Down
13 changes: 4 additions & 9 deletions rskj-core/src/main/java/co/rsk/core/RskAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
package co.rsk.core;

import co.rsk.core.exception.InvalidRskAddressException;
import com.google.common.primitives.UnsignedBytes;

import co.rsk.util.HexUtils;

import com.google.common.primitives.UnsignedBytes;
import org.ethereum.util.ByteUtil;
import org.ethereum.vm.DataWord;

Expand All @@ -41,18 +39,15 @@ public class RskAddress {
* This is the size of an RSK address in bytes.
*/
public static final int LENGTH_IN_BYTES = 20;

private static final RskAddress NULL_ADDRESS = new RskAddress();
//
public static final RskAddress ZERO_ADDRESS = new RskAddress("0000000000000000000000000000000000000000");

/**
* This compares using the lexicographical order of the sender unsigned bytes.
*/
public static final Comparator<RskAddress> LEXICOGRAPHICAL_COMPARATOR = Comparator.comparing(
RskAddress::getBytes,
UnsignedBytes.lexicographicalComparator());

private static final RskAddress NULL_ADDRESS = new RskAddress();
private final byte[] bytes;

/**
Expand All @@ -77,7 +72,7 @@ public RskAddress(byte[] bytes) {
throw new InvalidRskAddressException(String.format("An RSK address must be %d bytes long", LENGTH_IN_BYTES));
}

this.bytes = bytes;
this.bytes = Arrays.copyOf(bytes, bytes.length);
}

/**
Expand All @@ -95,7 +90,7 @@ public static RskAddress nullAddress() {
}

public byte[] getBytes() {
return bytes;
return Arrays.copyOf(bytes, bytes.length);
}

public String toHexString() {
Expand Down
Loading
Loading