From 60620465061b3b6c919811bb1c9802bc99628a81 Mon Sep 17 00:00:00 2001 From: courtneyeh Date: Thu, 11 Apr 2024 15:39:04 +1000 Subject: [PATCH] Update directory structure --- .../statetransition/util/P2PDumpManager.java | 31 ++++++++++--------- .../util/P2PDumpManagerTest.java | 18 +++++++---- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/P2PDumpManager.java b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/P2PDumpManager.java index bb788d56bbf..dcc8b596aa6 100644 --- a/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/P2PDumpManager.java +++ b/ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/util/P2PDumpManager.java @@ -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; @@ -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( @@ -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); } @@ -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); diff --git a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/P2PDumpManagerTest.java b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/P2PDumpManagerTest.java index df1d05553f8..ab0e539f283 100644 --- a/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/P2PDumpManagerTest.java +++ b/ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/util/P2PDumpManagerTest.java @@ -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); } @@ -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); } @@ -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); } @@ -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); } @@ -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()); } @@ -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); }