feat(*): optimize old rewards withdrawal by halibobo1205 · Pull Request #5742 · tronprotocol/java-tron
Conversation
What does this PR do?
- remove useNewRewardAlgorithmFromStart
- code clear
- exit when the calculation task gets an exception
- tools: add
db rootto calculate the data root - make reward-vi root configurable
Why are these changes required?
see #5406 (comment).
This PR has been tested by:
- Unit Tests
- Manual Testing
Follow up
Extra details
| logger.warn("Merkle root mismatch, expect: {}, actual: {}." | ||
| + " If you are quite sure that there is no miscalculation (not on the main network)" | ||
| + ", please configure 'storage.merkleRoot.reward-vi = {}'" | ||
| + "(for a specific network such as Nile, etc.) to config.conf to fix the hints", |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a small spelling error.'to config.conf' should be 'in config.conf'.
| private Sha256Hash rewardViRoot = Sha256Hash.wrap( | ||
| ByteString.fromHex("9debcb9924055500aaae98cdee10501c5c39d4daa75800a996f4bdda73dbccd8")); | ||
| private static final String MAIN_NET_ROOT_HEX = | ||
| "9debcb9924055500aaae98cdee10501c5c39d4daa75800a996f4bdda73dbccd8"; |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this root hex is already configured in conf. here it is declared again. Should it be possible for this value declared in one place instead of two different files?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to ensure that the main-net node does not need to change the configuration file.
|
|
||
| @Override | ||
| public byte[] getValue() { | ||
| checkState(); |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a varible method close and a method with the same name in this class, maybe you should use different names to distinguish them.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No changes for now.
| clearUp(false); | ||
| logger.info("rewardViCalService is no need to run"); | ||
| } | ||
| } catch (Exception e) { |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In which case shall it throw an Exception?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such as too many open files, not enough disk space, etc.
| private List<Leaf> leaves; | ||
| private Leaf root; | ||
|
|
||
| public static MerkleTree getInstance() { |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here it uses Double-Checked Locking to ensure that only one instance is created in a multi-threaded environment. However, this code suffers from concurrency issues. Double-Checked Locking is not always reliable in Java because it depends on the memory model and compiler optimizations.
A safer implementation of the singleton pattern uses static inner classes in a way that is thread-safe and efficient。
private static class MerkleTreeHolder { private static final MerkleTree instance = new MerkleTree(); } public static MerkleTree getInstance() { return MerkleTreeHolder.instance; }
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class has member variables and can not be used for concurrency, need to modify the usage scenarios while labeling them as not being able to be concurrent.
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