Skip to content

Commit

Permalink
Update directory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed Apr 11, 2024
1 parent f6eafd9 commit 6062046
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
public class P2PDumpManager {
private static final Logger LOG = LogManager.getLogger();

private static final String GOSSIP_DECODING_ERROR_DIR = "gossip-decoding-error-messages";
private static final String GOSSIP_REJECTED_DIR = "rejected-gossip-messages";
private static final String INVALID_BLOCK_DIR = "invalid-blocks";
private static final String GOSSIP_MESSAGES_DIR = "gossip_messages";
private static final String DECODING_ERROR_SUB_DIR = "decoding_error";
private static final String REJECTED_SUB_DIR = "rejected";
private static final String INVALID_BLOCK_DIR = "invalid_blocks";

private final boolean enabled;
private final Path directory;
Expand All @@ -41,17 +42,18 @@ public P2PDumpManager(final Path directory, final boolean enabled) {
return;
}

if (this.directory.resolve(GOSSIP_DECODING_ERROR_DIR).toFile().mkdirs()) {
final Path gossipMessagesPath = this.directory.resolve(GOSSIP_MESSAGES_DIR);
if (gossipMessagesPath.toFile().mkdirs()) {
LOG.info("{} directory has been created to save gossip messages.", GOSSIP_MESSAGES_DIR);
}
if (gossipMessagesPath.resolve(DECODING_ERROR_SUB_DIR).toFile().mkdirs()) {
LOG.info(
String.format(
"%s directory has been created to save gossip messages with decoding errors.",
GOSSIP_DECODING_ERROR_DIR));
"{} directory has been created to save gossip messages with decoding errors.",
DECODING_ERROR_SUB_DIR);
}
if (this.directory.resolve(GOSSIP_REJECTED_DIR).toFile().mkdirs()) {
if (gossipMessagesPath.resolve(REJECTED_SUB_DIR).toFile().mkdirs()) {
LOG.info(
String.format(
"%s directory has been created to save rejected gossip messages.",
GOSSIP_REJECTED_DIR));
"{}} directory has been created to save rejected gossip messages.", REJECTED_SUB_DIR);
}
if (this.directory.resolve(INVALID_BLOCK_DIR).toFile().mkdirs()) {
LOG.info(
Expand All @@ -67,12 +69,13 @@ public void saveGossipMessageDecodingError(
}
final String fileName = String.format("%s_%s.ssz", arrivalTimestamp, topic);
final String identifiers = String.format("Topic: %s", topic);
final Path topicPath = Path.of(GOSSIP_DECODING_ERROR_DIR).resolve(topic);
final Path topicPath =
Path.of(GOSSIP_MESSAGES_DIR).resolve(DECODING_ERROR_SUB_DIR).resolve(topic);
checkTopicDirExists(topicPath);
saveBytesToFile(
"gossip message with decoding error",
identifiers,
Path.of(GOSSIP_DECODING_ERROR_DIR).resolve(topic).resolve(fileName),
topicPath.resolve(fileName),
originalMessage);
}

Expand All @@ -83,7 +86,7 @@ public void saveGossipRejectedMessageToFile(
}
final String fileName = String.format("%s_%s.ssz", arrivalTimestamp, topic);
final String identifiers = String.format("Topic: %s", topic);
final Path topicPath = Path.of(GOSSIP_REJECTED_DIR).resolve(topic);
final Path topicPath = Path.of(GOSSIP_MESSAGES_DIR).resolve(REJECTED_SUB_DIR).resolve(topic);
checkTopicDirExists(topicPath);
saveBytesToFile(
"rejected gossip message", identifiers, topicPath.resolve(fileName), decodedMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ void saveGossipMessageDecodingError_shouldSaveToFile(@TempDir Path tempDir) {

final String fileName = String.format("%s_%s.ssz", arrivalTimestamp, topic);
final Path expectedFile =
tempDir.resolve("gossip-decoding-error-messages").resolve(topic).resolve(fileName);
tempDir
.resolve("gossip_messages")
.resolve("decoding_error")
.resolve(topic)
.resolve(fileName);
checkBytesSavedToFile(expectedFile, messageBytes);
}

Expand All @@ -56,7 +60,8 @@ void saveGossipMessageDecodingError_shouldNotSaveToFileWhenDisabled(@TempDir Pat
assertThat(manager.isEnabled()).isFalse();

final String fileName = String.format("%s_%s.ssz", arrivalTimestamp, "test_topic");
final Path expectedFile = tempDir.resolve("gossip-decoding-error-messages").resolve(fileName);
final Path expectedFile =
tempDir.resolve("gossip_messages").resolve("decoding_error").resolve(fileName);
checkFileNotExist(expectedFile);
}

Expand All @@ -70,7 +75,7 @@ void saveGossipRejectedMessageToFile_shouldSaveToFile(@TempDir Path tempDir) {

final String fileName = String.format("%s_%s.ssz", arrivalTimestamp, topic);
final Path expectedFile =
tempDir.resolve("rejected-gossip-messages").resolve(topic).resolve(fileName);
tempDir.resolve("gossip_messages").resolve("rejected").resolve(topic).resolve(fileName);
checkBytesSavedToFile(expectedFile, messageBytes);
}

Expand All @@ -83,7 +88,8 @@ void saveGossipRejectedMessageToFile_shouldNotSaveToFileWhenDisabled(@TempDir Pa
assertThat(manager.isEnabled()).isFalse();

final String fileName = String.format("%s_%s.ssz", arrivalTimestamp, "test_topic");
final Path expectedFile = tempDir.resolve("rejected-gossip-messages").resolve(fileName);
final Path expectedFile =
tempDir.resolve("gossip_messages").resolve("rejected").resolve(fileName);
checkFileNotExist(expectedFile);
}

Expand All @@ -96,7 +102,7 @@ void saveInvalidBlockToFile_shouldSaveToFile(@TempDir Path tempDir) {
final String fileName =
String.format(
"slot%s_root%s.ssz", block.getSlot(), block.getRoot().toUnprefixedHexString());
final Path expectedFile = tempDir.resolve("invalid-blocks").resolve(fileName);
final Path expectedFile = tempDir.resolve("invalid_blocks").resolve(fileName);
checkBytesSavedToFile(expectedFile, block.sszSerialize());
}

Expand All @@ -110,7 +116,7 @@ void saveInvalidBlockToFile_shouldNotSaveToFileWhenDisabled(@TempDir Path tempDi
final String fileName =
String.format(
"slot%s_root%s.ssz", block.getSlot(), block.getRoot().toUnprefixedHexString());
final Path expectedFile = tempDir.resolve("invalid-blocks").resolve(fileName);
final Path expectedFile = tempDir.resolve("invalid_blocks").resolve(fileName);
checkFileNotExist(expectedFile);
}

Expand Down

0 comments on commit 6062046

Please sign in to comment.