feat(*): optimize old rewards withdrawal by halibobo1205 · Pull Request #5742 · tronprotocol/java-tron

Conversation

@halibobo1205

What does this PR do?

  1. remove useNewRewardAlgorithmFromStart
  2. code clear
  3. exit when the calculation task gets an exception
  4. tools: add db root to calculate the data root
  5. 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

eodiandie

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'.

eodiandie

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.

317787106


@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.

lurais

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.

eodiandie

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.

tomatoishealthy

jwrct

OnlineshopDimond46

OnlineshopDimond46

Reviewers

@yanghang8612 yanghang8612 Awaiting requested review from yanghang8612

@317787106 317787106 Awaiting requested review from 317787106

@lurais lurais Awaiting requested review from lurais

4 more reviewers

@eodiandie eodiandie eodiandie left review comments

@jwrct jwrct jwrct approved these changes

Reviewers whose approvals may not affect merge requirements