-
Notifications
You must be signed in to change notification settings - Fork 9
chore: Remove BlockAcknowledgement.block_root_hash from Publisher API #1407
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
Open
Nana-EC
wants to merge
4
commits into
main
Choose a base branch
from
1395-remove-publisher-brh
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+49
−130
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
import java.nio.file.Path; | ||
import javax.inject.Inject; | ||
import org.hiero.block.common.hasher.StreamingTreeHasher; | ||
import org.hiero.block.common.utils.FileUtilities; | ||
import org.hiero.block.common.utils.StringUtilities; | ||
import org.hiero.block.simulator.config.data.BlockGeneratorConfig; | ||
import org.hiero.block.simulator.config.data.SimulatorStartupDataConfig; | ||
|
@@ -20,7 +19,6 @@ public final class SimulatorStartupDataImpl implements SimulatorStartupData { | |
private final System.Logger LOGGER = System.getLogger(SimulatorStartupDataImpl.class.getName()); | ||
private final boolean enabled; | ||
private final Path latestAckBlockNumberPath; | ||
private final Path latestAckBlockHashPath; | ||
private final long startupDataBlockNumber; | ||
private final byte[] startupDataBlockHash; | ||
|
||
|
@@ -30,54 +28,26 @@ public SimulatorStartupDataImpl( | |
@NonNull final BlockGeneratorConfig blockGeneratorConfig) { | ||
this.enabled = simulatorStartupDataConfig.enabled(); | ||
this.latestAckBlockNumberPath = simulatorStartupDataConfig.latestAckBlockNumberPath(); | ||
this.latestAckBlockHashPath = simulatorStartupDataConfig.latestAckBlockHashPath(); | ||
long localStartupDataBlockNumber = blockGeneratorConfig.startBlockNumber() - 1L; | ||
byte[] localStartupDataBlockHash = new byte[StreamingTreeHasher.HASH_LENGTH]; | ||
if (enabled) { | ||
try { | ||
final int existsLatestAckBlockNumberFile = Files.exists(latestAckBlockNumberPath) ? 1 : 0; | ||
final int existsLatestAckBlockHashFile = Files.exists(latestAckBlockHashPath) ? 1 : 0; | ||
// determine the number of existing startup data files | ||
final int existingStartupDataFileCount = existsLatestAckBlockNumberFile + existsLatestAckBlockHashFile; | ||
switch (existingStartupDataFileCount) { | ||
case 0 -> { | ||
// if no startup data files exist, this means that this | ||
// is the initial setup, we only need to create the | ||
// startup data files | ||
FileUtilities.createFile(latestAckBlockNumberPath); | ||
FileUtilities.createFile(latestAckBlockHashPath); | ||
} | ||
case 1 -> { | ||
// if only one file exists, then this is an erroneous | ||
// state. We must investigate why this is happening. | ||
// Generally we never ever expect to enter here, but | ||
// we cannot continue to initialize the simulator | ||
if (!Files.exists(latestAckBlockNumberPath)) { | ||
// if no startup data files exist, this means that this | ||
// is the initial setup, we only need to create the | ||
// startup data files | ||
Files.createFile(latestAckBlockNumberPath); | ||
} else { | ||
// data from the files. | ||
// If successful, we can finish initialization, otherwise | ||
// we have broken state and cannot continue. | ||
final String blockNumberFromFile = Files.readString(latestAckBlockNumberPath); | ||
if (!StringUtilities.isBlank(blockNumberFromFile)) { | ||
localStartupDataBlockNumber = Long.parseLong(blockNumberFromFile); | ||
} else { | ||
throw new IllegalStateException( | ||
"Failed to initialize Simulator Startup Data, only one startup data file exists!"); | ||
} | ||
case 2 -> { | ||
// entering here means that both files exist, so now we | ||
// must attempt to read the startup data from the files. | ||
// If successful, we can finish initialization, otherwise | ||
// we have broken state and cannot continue. | ||
final String blockNumberFromFile = Files.readString(latestAckBlockNumberPath); | ||
if (!StringUtilities.isBlank(blockNumberFromFile)) { | ||
localStartupDataBlockNumber = Long.parseLong(blockNumberFromFile); | ||
} else { | ||
throw new IllegalStateException( | ||
"Failed to initialize latest ack block number from Simulator Startup Data"); | ||
} | ||
final byte[] previousHashFromFile = Files.readAllBytes(latestAckBlockHashPath); | ||
if (previousHashFromFile.length == StreamingTreeHasher.HASH_LENGTH) { | ||
localStartupDataBlockHash = previousHashFromFile; | ||
} else { | ||
throw new IllegalStateException( | ||
"Failed to initialize latest ack block hash from Simulator Startup Data"); | ||
} | ||
"Failed to initialize latest ack block number from Simulator Startup Data"); | ||
} | ||
default -> | ||
throw new IllegalStateException( | ||
"Failed to initialize Simulator Startup Data, invalid number of startup data files!"); | ||
} | ||
} catch (final IOException e) { | ||
throw new UncheckedIOException(e); | ||
|
@@ -104,13 +74,12 @@ public boolean isEnabled() { | |
} | ||
|
||
@Override | ||
public void updateLatestAckBlockStartupData(final long blockNumber, final byte[] blockHash) throws IOException { | ||
public void updateLatestAckBlockStartupData(final long blockNumber) throws IOException { | ||
if (enabled) { | ||
// @todo(904) we need the correct response code, currently it seems that | ||
// the response code is not being set correctly? The if check should | ||
// be different and based on the response code, only saving | ||
Files.write(latestAckBlockNumberPath, String.valueOf(blockNumber).getBytes()); | ||
Files.write(latestAckBlockHashPath, blockHash); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not think we can omit this, we simply need another way to supply the hash. |
||
LOGGER.log(DEBUG, "Updated startup data for latest ack block with number: {0}", blockNumber); | ||
} | ||
} | ||
|
This file contains hidden or 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 hidden or 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.
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.
Please note that the startup data will stop functioning w/o the hash to be saved on disk. This means that the next startup will be w/o previous hash and everything will be broken after that. We should add a way to save the current hash (as it is generated by the simulator) and then retrieving and storing that in the proper place once ack is received.