-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement toDot
Method and File Storing Mechanism for VerkleTrie
#17
Closed
neotheprogramist
wants to merge
5
commits into
hyperledger:main
from
visoftsolutions:1-todot-and-storage
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1b678c2
move from old repo
neotheprogramist 49456ed
update deps
neotheprogramist 17c5309
Merge branch 'hyperledger:main' into 1-todot-and-storage
neotheprogramist 37c90d4
use dependencies with apache licence
neotheprogramist f1f1be5
Merge branch 'hyperledger:main' into 1-todot-and-storage
neotheprogramist File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/main/java/org/hyperledger/besu/ethereum/trie/verkle/exporter/DotExporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright Besu Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
package org.hyperledger.besu.ethereum.trie.verkle.exporter; | ||
|
||
import java.io.BufferedWriter; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.AccessDeniedException; | ||
import java.nio.file.FileSystemException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
/** Utility class for exporting Verkle Trie representations to DOT files. */ | ||
public class DotExporter { | ||
|
||
private static final Logger LOG = LogManager.getLogger(DotExporter.class); | ||
private static final Pattern FILE_EXTENSION_PATTERN = Pattern.compile("\\.(dot|gv)$"); | ||
private static final String DEFAULT_FILE_NAME = "./VerkleTrie.gv"; | ||
|
||
/** | ||
* Exports the Verkle Trie DOT representation to a '.gv' file located in the current directory. | ||
* The default file name is "VerkleTrie.gv". | ||
* | ||
* @param verkleTrieDotString The DOT representation of the Verkle Trie. | ||
* @throws IOException If an I/O error occurs during the export process. | ||
*/ | ||
public static void exportToDotFile(String verkleTrieDotString) throws IOException { | ||
exportToDotFile(verkleTrieDotString, DEFAULT_FILE_NAME); | ||
} | ||
|
||
/** | ||
* Exports the Verkle Trie DOT representation to a '.gv' file located at the specified path. | ||
* | ||
* @param verkleTrieDotString The DOT representation of the Verkle Trie. | ||
* @param filePath The location where the DOT file will be saved. | ||
* @throws IOException If an I/O error occurs during the export process. | ||
*/ | ||
public static void exportToDotFile(String verkleTrieDotString, String filePath) | ||
throws IOException { | ||
try { | ||
if (filePath == null || filePath.isEmpty()) { | ||
filePath = DEFAULT_FILE_NAME; | ||
} else { | ||
Matcher matcher = FILE_EXTENSION_PATTERN.matcher(filePath); | ||
if (!matcher.find()) { | ||
throw new IllegalArgumentException("Invalid file extension. Use .dot or .gv extension."); | ||
} | ||
} | ||
|
||
Path path = Paths.get(filePath); | ||
|
||
Files.createDirectories(path.getParent()); | ||
|
||
try (BufferedWriter writer = | ||
new BufferedWriter(new FileWriter(path.toString(), StandardCharsets.UTF_8))) { | ||
writer.write(verkleTrieDotString); | ||
} | ||
|
||
} catch (AccessDeniedException e) { | ||
LOG.error( | ||
"Access denied. Check write permissions for the file. Details: {}", e.getMessage(), e); | ||
throw e; | ||
} catch (FileSystemException e) { | ||
LOG.error( | ||
"File system issue. Check disk space and file system restrictions. Details: {}", | ||
e.getMessage(), | ||
e); | ||
throw e; | ||
} catch (IOException e) { | ||
LOG.error("Error writing DOT file: {}. Details: {}", e.getMessage(), e); | ||
throw e; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doing some tests currently
should display hex representation in order to avoid conversion issues
.append(Bytes.of(locationBytes.get(locationBytes.size() - 1)))
because I have something like that with the current code
LeafNode0xc43a5184f61b02b1e21512facb6deb3c01c1e6909158cccda8267b6618c44f8c[location="0xc43a5184f61b02b1e21512facb6deb3c01c1e6909158cccda8267b6618c44f8c", suffix="-116", value="0x0057600080fd5b82018360208201111561018b57600080fd5b80359060200191"]