-
Notifications
You must be signed in to change notification settings - Fork 283
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
[Draft] Add database reset on Ephemery Network #8626
[Draft] Add database reset on Ephemery Network #8626
Conversation
Signed-off-by: gconnect <agatevureglory@gmail.com>
@rolfyone please take a look when you have the time. |
Thanks for raising, will review shortly. One initial comment - |
if (source.exists()) { | ||
final DatabaseNetwork databaseNetwork = | ||
objectMapper.readerFor(DatabaseNetwork.class).readValue(source); | ||
|
||
// Fork version validation |
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.
we can remove these comments, they don't really add to the readability of the code... (basically all of the comments in this file at least)
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.
Alright, I will remove it.
Not sure what you meant here. |
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.
We could potentially treat this as a 'tracer' PR and just create a new branch with what we want in the first one... Alternatively we need to remove all of the functionality other than the network yaml change
Basically, I need a PR that just changes the network yaml and doesn't break anything when reading the old configuration file that doesn't have the chain id in it... This is really critical, because thats basically ensuring its not a breaking change.
DatabaseNetwork databaseNetwork = | ||
new DatabaseNetwork(forkVersionString, depositContractString); | ||
// Handle Ephemery or other networks | ||
String depositChainIdString = depositChainId.orElse(null); |
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.
final
System.out.println( | ||
"network " + NETWORK_CONFIG.getEth2Network().equals(Optional.of(Eth2Network.EPHEMERY))); |
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.
we don't want System.out
in our code, we'd want to be using loggers... Is this just a test message?
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.
we don't want
System.out
in our code, we'd want to be using loggers... Is this just a test message?
Yes it a test message, forgot to remove it before pushing
if (NETWORK_CONFIG.getEth2Network().equals(Optional.of(Eth2Network.EPHEMERY))) { | ||
databaseNetwork = | ||
new DatabaseNetwork(forkVersionString, depositContractString, depositChainIdString); | ||
} else { | ||
databaseNetwork = new DatabaseNetwork(forkVersionString, depositContractString, null); | ||
} |
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.
We can just always write deposit_chain_id to the file which makes this a lot more readable. The conditional check I'd be more worried about would be ensuring we don't crash if it's not there on startup once we're checking that.
@@ -95,11 +140,12 @@ public boolean equals(final Object o) { | |||
} | |||
final DatabaseNetwork that = (DatabaseNetwork) o; | |||
return Objects.equals(forkVersion, that.forkVersion) | |||
&& Objects.equals(depositContract, that.depositContract); | |||
&& Objects.equals(depositContract, that.depositContract) | |||
&& Objects.equals(depositChainId, that.depositChainId); // Compare deposit_chain_id |
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.
remove comment
this.forkVersion = forkVersion; | ||
this.depositContract = depositContract; | ||
this.depositChainId = depositChainId; // Can be null for non-Ephemery networks |
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.
remove comment - will also be null for any old databases that ARE ephemery that you open... we can't assume all ephemery will have this data.
Also though it's less important, people just have to manually reset their db (it'll literally be a dev - you or me basically)
I do also think that we could have a constructor with just the old interface and default the new field to null, which would simplify testing and make it clearer...
if (NETWORK_CONFIG.getEth2Network().equals(Optional.of(Eth2Network.EPHEMERY))) { | ||
|
||
// Deposit chain ID validation | ||
if (depositChainId.isPresent() | ||
&& databaseNetwork.depositChainId != null | ||
&& !databaseNetwork.depositChainId.equals(depositChainId.get())) { | ||
throw DatabaseStorageException.unrecoverable( | ||
formatMessage( | ||
"deposit chain ID", | ||
depositChainId.get(), | ||
String.valueOf(databaseNetwork.depositChainId))); | ||
} | ||
} |
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.
defer this check to another PR please. it'll make testing a lot easier to see.
@@ -37,11 +37,12 @@ public void shouldCreateNetworkFile(@TempDir final File tempDir) throws IOExcept | |||
assertThat(networkFile).doesNotExist(); | |||
final Bytes4 fork = dataStructureUtil.randomFork().getCurrentVersion(); | |||
final Eth1Address eth1Address = dataStructureUtil.randomEth1Address(); | |||
assertThat(DatabaseNetwork.init(networkFile, fork, eth1Address)) | |||
assertThat(DatabaseNetwork.init(networkFile, fork, eth1Address, null)) |
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.
i'd be surprised that any of these tests pass? we're pushing a null into an optional field which rarely ends well...
My suggestion above was to make the init not take an optional, so this will likely be a better answer after that...
// This implementation is required for Ephemery Network | ||
private void resetDatabaseDirectories() { | ||
File networkFile = getNetworkFile(); | ||
|
||
try { | ||
if (dbDirectory.exists()) { | ||
deleteDirectoryRecursively(dbDirectory.toPath()); | ||
} | ||
if (v5ArchiveDirectory.exists()) { | ||
deleteDirectoryRecursively(v5ArchiveDirectory.toPath()); | ||
} | ||
if (networkFile.exists()) { | ||
try { | ||
LOG.info("Resetting network file at: {}", networkFile.getAbsolutePath()); | ||
Files.delete(networkFile.toPath()); | ||
System.out.println("Database directories reset successfully."); | ||
} catch (IOException e) { | ||
throw DatabaseStorageException.unrecoverable( | ||
String.format("Failed to reset network file at %s", networkFile.getAbsolutePath()), | ||
e); | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw DatabaseStorageException.unrecoverable("Failed to reset database directories", e); | ||
} | ||
} | ||
|
||
private void deleteDirectoryRecursively(final Path path) throws IOException { | ||
if (Files.isDirectory(path)) { | ||
try (var stream = Files.walk(path)) { | ||
stream | ||
.sorted((o1, o2) -> o2.compareTo(o1)) | ||
.forEach( | ||
p -> { | ||
try { | ||
Files.delete(p); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to delete file: " + p, e); | ||
} | ||
}); | ||
} | ||
} | ||
} |
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.
We'll defer this to another PR please, lets get the new field in and not breaking anything.
getNetworkFile(), | ||
spec.getGenesisSpecConfig().getGenesisForkVersion(), | ||
eth1Address, | ||
Optional.of(String.valueOf(spec.getGenesisSpecConfig().getDepositChainId()))); |
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.
i feel like at this level we just want the depositChainId as a long going in...
static final Eth2NetworkConfiguration NETWORK_CONFIG = | ||
Eth2NetworkConfiguration.builder(Eth2Network.EPHEMERY).build(); |
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.
Ideally I think we avoid something like this... at the very least we just want to add our deposit chain id in this pr.
What changes will I apply to the network.yaml file if I am not adding the chainId? |
opened a new PR here #8631 |
PR Description
Todo
Doing this tends not to work as expected
Still figuring how to handle the check.
Fixed Issue(s)
"fixes #8589"
Documentation
doc-change-required
label to this PR if updates are required.Changelog