Skip to content

Optimize Stake 2.0 related code #5424

Closed
@CarlChaoCarl

Description

@CarlChaoCarl

Rationale

After the stake2.0 code was launched, some of the codes were found that could be optimized, and here these codes are proposed for discussion and optimization.

  1. call in the for loop: votesCapsule.addNewVotes

    • Solution: It is recommended to add to the list first, and then call addAll
  2. The code of estimateConsumeBandWidthSize is too complicated and needs to be simplified

    • Solution: It is recommended to remove redundant code and streamline the code.
  3. GetCanDelegatedMaxSize has many repeated codes.

    • Solution: It is recommended to encapsulate it into a function and reuse the code.
  4. The description of exception information in stake 2.0 is inaccurate.

    • Solution: It is recommended to describe the exception information accurately.

Implementation

  1. Located in: updateVote method of UnfreezeBalanceV2Actuator class

    • Add a List addVotes instead and do addAll once.
  2. Located in: estimateConsumeBandWidthSize method of TransactionUtil class

    • There are some redundant codes in the method of calculating the estimated transaction size, which can be simplified
  3. The getCanDelegatedMaxSize function in the Wallet are duplicated with other codes in the other place, and can be reused

    • It can be abstracted: getV2NetUsage, getV2EnergyUsage for code reuse.
  4. Optimize the description of Stake 2.0 exception messages
    - When delegateBalance < TRX_PRECISION in DelegateResourceActuator.java, description 'delegateBalance must be more than 1 TRX' is replaced with'delegateBalance must be greater than or equal to 1 TRX'
    - When ownerCapsule.getFrozenV2BalanceForBandwidth() - remainNetUsage < delegateBalance in DelegateResourceActuator.java, description 'delegateBalance must be less than available FreezeBandwidthV2 balance' is replaced with 'delegateBalance must be less than or equal to available FreezeBandwidthV2 balance'
    - When ownerCapsule.getFrozenV2BalanceForEnergy() - remainEnergyUsage < delegateBalance in DelegateResourceActuator.java, description 'delegateBalance must be less than available FreezeEnergyV2 balance' is replaced with 'delegateBalance must be less than or equal to available FreezeEnergyV2 balance'
    - When frozenBalance < TRX_PRECISION in FreezeBalanceActuator.java, description 'frozenBalance must be more than 1TRX' is replaced with 'frozenBalance must be greater than or equal to 1 TRX'
    - When frozenBalance > accountCapsule.getBalance() in FreezeBalanceActuator.java, description 'frozenBalance must be less than accountBalance' is replaced with 'frozenBalance must be less than or equal to accountBalance'
    - When frozenBalance < TRX_PRECISION in FreezeBalanceV2Actuator.java, description 'frozenBalance must be more than 1TRX' is replaced with 'frozenBalance must be greater than or equal to 1 TRX'
    - When frozenBalance > accountCapsule.getBalance() in FreezeBalanceV2Actuator.java, description 'frozenBalance must be less than accountBalance' is replaced with 'frozenBalance must be less than or equal to accountBalance'
    - When delegateBalance < TRX_PRECISION in DelegateResourceProcessor.java, description 'delegateBalance must be more than 1TRX' is replaced with 'delegateBalance must be greater than or equal to 1 TRX'
    - When ownerCapsule.getFrozenV2BalanceForBandwidth() - v2NetUsage < delegateBalance in DelegateResourceProcessor.java, description 'delegateBalance must be less than available FreezeBandwidthV2 balance' is replaced with 'delegateBalance must be less than or equal to available FreezeBandwidthV2 balance'
    - When ownerCapsule.getFrozenV2BalanceForEnergy() - v2EnergyUsage < delegateBalance in DelegateResourceProcessor.java, description 'delegateBalance must be less than available FreezeEnergyV2 balance' is replaced with 'delegateBalance must be less than or equal to available FreezeEnergyV2 balance'
    - When frozenBalance < TRX_PRECISION in FreezeBalanceProcessor.java, description 'FrozenBalance must be less than accountBalance' is replaced with 'FrozenBalance must be less than or equal to accountBalance'
    - When frozenBalance < TRX_PRECISION in FreezeBalanceV2Processor.java, description 'FrozenBalance must be more than 1TRX' is replaced with 'FrozenBalance must be greater than or equal to 1 TRX'
    - When frozenBalance > ownerCapsule.getBalance() in FreezeBalanceV2Processor.java, description 'FrozenBalance must be less than accountBalance' is replaced with 'FrozenBalance must be less than or equal to accountBalance'

Are you willing to implement this feature?

Yes, I have completed the code

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions