Closed halibobo1205 closed 7 months ago
Sounds great, looking forward to future developments
Will the difference in results before and after optimization lead to hard forks or data inconsistencies?
@halibobo1205
Note: The voting reward withdrawal can be triggered by the following transactions:
VoteWitnessContract
UnfreezeBalanceContract
UnfreezeBalanceV2Contract
WithdrawBalanceContract
@halibobo1205 Will these transaction types involve code changes?
@halibobo1205 What problems will exist on the Tron network if this optimization is not implemented and the current logic is maintained?
One more question, in the logic of transaction execution, in scenario 1.i.b, will blocking make the node unavailable, for example, producing blocks, processing blocks, processing other transactions, etc.?
I wonder if I voted in phase 1, and have rewards in both phase 1 and phase 2, if I withdraw all the rewards, is it calculated by phase1.algorithm only? And then I will have new rewards only in phase 2, if I withdraw the new rewards again, is it calculated by phase1.algorithm too?
Will the difference in results before and after optimization lead to hard forks or data inconsistencies?
@CarlChaoCarl Yes, a hard fork is required.
I wonder if I voted in phase 1, and have rewards in both phase 1 and phase 2, if I withdraw all the rewards, is it calculated by phase1.algorithm only? And then I will have new rewards only in phase 2, if I withdraw the new rewards again, is it calculated by phase1.algorithm too?
@KrisdiaPaul phase 1 is calculated by phase1.algorithm , phase 2 is calculated by phase2.algorithm. if you withdraw the new rewards again, there is no reward in phase 1, because after TIP-465, there is no reward in phase 1.
One more question, in the logic of transaction execution, in scenario 1.i.b, will blocking make the node unavailable, for example, producing blocks, processing blocks, processing other transactions, etc.?
There is a very low probability that it will occur, it will not occur under normal conditions, and the calculation task will take about 5 minutes, which is more than enough time for the new proposal to take effect.
@halibobo1205 What problems will exist on the Tron network if this optimization is not implemented and the current logic is maintained?
@jwrct The TPS of the related transactions may be unstable.
Simple Summary
This TIP aims to optimize the algorithm of the voting reward withdrawal in Phase1 (since TIP-53, before TIP-465 took effect) to improve the TPS of such transactions.
Abstract
There are currently two phases of the TRON protocol voting reward:
Due to the poor performance of the current Phase1 voting reward withdrawal algorithm, when a user who has Phase1 reward initiates the transactions triggering the algorithm, the performance of the network would degrade.
This TIP proposes a scheme that optimizes the relevant calculation complexity to O(1) for Phase1 without an additional reward withdrawal logic, greatly optimizing the calculation performance of Phase1 reward and improving the TPS.
Motivation
Performance
According to statistics, there are currently about 160k users on the TRON mainnet who have Phase1 rewards to be withdrawn. By comparing the performance of the Phase1 reward algorithm before and after optimization in the test environment, it is expected that this optimization plan can improve performance by >20 times.
User Reward
The current Phase1 voting reward withdrawal uses truncation at the end of the decimal, resulting in the current actual value being slightly smaller than the expected value. The optimized algorithm will adopt higher calculation accuracy, and the calculation value will be closer to the expected values. At the same time, the difference in results before and after optimization will be controlled within 1 TRX, which will have almost no impact on the TRX inflation of the entire network and user rewards.
Specification
Glossary
In Phase1 and Phase2, the calculation logic of voting reward for a single SR vote is as follows:
Phase1.algorithm1 uses iterative calculations for each maintenance[startCycle, endCycle) and does an accumulation in the final, and the algorithm complexity is O(n).
Phase2.algorithm directly multiplies the userVote(s) and the delta between the accumulateRewardPerVote[startCycle-1, s] and accumulateRewardPerVote[endCycle-1, s], and the algorithm complexity is O(1). For more information please refer to TIP-465.
The Phase1.algorithm2 remains the same as the Phase2.algorithm. Based on the previous analysis, this optimization includes the following steps:
Note: The voting reward withdrawal can be triggered by the following transactions:
VoteWitnessContract
UnfreezeBalanceContract
UnfreezeBalanceV2Contract
WithdrawBalanceContract
Rationale
Impacts on Ecology
Data Consistency
This optimization affects the voting reward calculation logic and the consensus. Therefore, a proposal is needed to control the optimization to ensure data consistency on the chain.
Pre-calculation of rewardViSet
To minimize the impact on node performance, pre-calculation is executed asynchronously. However asynchronous tasks often have some state synchronization problems, so the execution logic of pre-calculation tasks needs to be described in detail here.
Transaction Execution
Check if there is any Phase1 voting reward
Backward Compatibility
According to the above sections, this optimization has no compatibility issues. Please note that if any third party implements an off-chain voting reward estimation algorithm individually, please adapt these changes promptly.