feat(db): optimize calculation services for reward when the node starts by halibobo1205 · Pull Request #5654 · tronprotocol/java-tron
We can start working on computational tasks immediately without waiting for a minimum of one block to synchronize if the new reward algorithm is already in effect when the node starts.
| revokingStore.disable(); | ||
| revokingStore.check(); | ||
| transactionCache.initCache(); | ||
| rewardViCalService.init(); |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If rewardViCalService is initialized behind revokingStore.check(), is the latestBlockNumber check still necessary?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scenes are synchronized from 0 and never restarted, check is still necessary.
| if (ret) { | ||
| // checkpoint is flushed to db, we can start rewardViCalService immediately | ||
| lastBlockNumber = Long.MAX_VALUE; | ||
| } |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to define this variable ret.
The style needs to be consistent, lastBlockNumber -> this.lastBlockNumber
| // checkpoint is flushed to db, we can start rewardViCalService immediately | ||
| lastBlockNumber = Long.MAX_VALUE; | ||
| } | ||
| es.scheduleWithFixedDelay(this::maybeRun, 0, 3, TimeUnit.SECONDS); |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the significance of this code in the enableNewRewardAlgorithm function?
if (ret && lastBlockNumber == -1) {
lastBlockNumber = this.getLatestBlockHeaderNumber();
}
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the block-catching case, record the block for which NewRewardAlgorithm is in effect, and wait for the block to be flushed before data computation to ensure data consistency.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function getLatestBlockHeaderNumber obtains the data of the underlying database, right?
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
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