Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(freezeV2): merge feature ‘stake 2.0’ into release v4.7.0 #4838

Merged
merged 193 commits into from
Dec 13, 2022

Conversation

lxcmyf
Copy link
Contributor

@lxcmyf lxcmyf commented Dec 13, 2022

What does this PR do?
Launch a new staking mechanism - stake2.0

  • Add some protocols and contracts
  • Add multiple query interfaces for stake2.0
  • To make compatible with old stake mechanism
  • Optimize delegate resource storage
  • Optimize resource usage merging

Why are these changes required?
TIP:tronprotocol/tips#467
This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

zhang0125 and others added 30 commits August 29, 2022 15:21
    1. add UNFREEZE_DELAY_DAYS proposal
    2. add new freeze/unfreeze actuator

    Closes #
1. add delegate resource contract
2. add undelegate resource contract
3. add test cases for delegate and undelegate resource
halibobo1205 and others added 25 commits November 2, 2022 22:52
…e_2.0

feat(freezeV2): add three interfaces for the new stake model
…e_2.0

feat(freezeV2): add one interface for new stake model
…e_2.0

feat(freezeV2): add query api to get delegate max resource size
…e_2.0

feat(freezeV2): Add bandwidth cost for delegating validation
…e_2.0

# Conflicts:
#	actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
#	chainbase/src/main/java/org/tron/core/capsule/DelegatedResourceCapsule.java
#	chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java
#	common/src/main/java/org/tron/common/parameter/CommonParameter.java
#	framework/src/main/java/org/tron/core/config/args/Args.java
…e_2.0

# Conflicts:
#	actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
#	chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java
#	common/src/main/java/org/tron/common/parameter/CommonParameter.java
#	framework/src/main/java/org/tron/core/Wallet.java
#	framework/src/main/java/org/tron/core/config/args/Args.java
#	framework/src/main/java/org/tron/core/consensus/ProposalService.java
…ze_delegate_index

feat(freezeV2): optimize delegate index
# Conflicts:
#	framework/src/main/java/org/tron/core/Wallet.java
@zhang0125 zhang0125 merged commit 2fe10e3 into tronprotocol:release_v4.7.0 Dec 13, 2022
FreezeBalanceV2Contract = 54;
UnfreezeBalanceV2Contract = 55;
WithdrawExpireUnfreezeContract = 56;
DelegateResourceContract = 57;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
DelegateResourceContract = 57;
DelegateResourceContract = 57;

FreezeBalanceV2Contract = 54;
UnfreezeBalanceV2Contract = 55;
WithdrawExpireUnfreezeContract = 56;
DelegateResourceContract = 57;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**

Suggested change
DelegateResourceContract = 57;
DelegateResourceContract = 57;

**

MarketSellAssetContract = 52;
MarketCancelOrderContract = 53;
FreezeBalanceV2Contract = 54;
UnfreezeBalanceV2Contract = 55;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UnfreezeBalanceV2Contract = 55;
UnfreezeBalanceV2Contract = 55;

@@ -873,6 +880,13 @@ Contract and contract-related messages.
ClearABIContract = 48;
UpdateBrokerageContract = 49;
ShieldedTransferContract = 51;
MarketSellAssetContract = 52;
MarketCancelOrderContract = 53;
FreezeBalanceV2Contract = 54;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
FreezeBalanceV2Contract = 54;
FreezeBalanceV2Contract = 54;

@@ -873,6 +880,13 @@ Contract and contract-related messages.
ClearABIContract = 48;
UpdateBrokerageContract = 49;
ShieldedTransferContract = 51;
MarketSellAssetContract = 52;
MarketCancelOrderContract = 53;
FreezeBalanceV2Contract = 54;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


@@ -671,7 +691,7 @@ public long getTotalEnergyLimitWithFixRatio(AccountCapsule creator, AccountCapsu
long originEnergyLeft = 0;
if (consumeUserResourcePercent < VMConstant.ONE_HUNDRED) {
originEnergyLeft = rootRepository.getAccountLeftEnergyFromFreeze(creator);
if (VMConfig.allowTvmFreeze()) {
if (VMConfig.allowTvmFreeze() || VMConfig.allowTvmFreezeV2()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (VMConfig.allowTvmFreeze() || VMConfig.allowTvmFreezeV2()) {
if (VMConfig.allowTvmFreeze() || VMConfig.allowTvmFreezeV2()) {

Comment on lines +553 to +568
if (VMConfig.allowTvmFreezeV2()) {
long now = rootRepository.getHeadSlot();
EnergyProcessor energyProcessor =
new EnergyProcessor(
rootRepository.getDynamicPropertiesStore(),
ChainBaseManager.getInstance().getAccountStore());
energyProcessor.updateUsage(account);
account.setLatestConsumeTimeForEnergy(now);
receipt.setCallerEnergyUsage(account.getEnergyUsage());
receipt.setCallerEnergyWindowSize(account.getWindowSize(Common.ResourceCode.ENERGY));
account.setEnergyUsage(
energyProcessor.increase(account, Common.ResourceCode.ENERGY,
account.getEnergyUsage(), min(leftFrozenEnergy, energyFromFeeLimit), now, now));
receipt.setCallerEnergyMergedUsage(account.getEnergyUsage());
rootRepository.updateAccount(account.createDbKey(), account);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (VMConfig.allowTvmFreezeV2()) {
long now = rootRepository.getHeadSlot();
EnergyProcessor energyProcessor =
new EnergyProcessor(
rootRepository.getDynamicPropertiesStore(),
ChainBaseManager.getInstance().getAccountStore());
energyProcessor.updateUsage(account);
account.setLatestConsumeTimeForEnergy(now);
receipt.setCallerEnergyUsage(account.getEnergyUsage());
receipt.setCallerEnergyWindowSize(account.getWindowSize(Common.ResourceCode.ENERGY));
account.setEnergyUsage(
energyProcessor.increase(account, Common.ResourceCode.ENERGY,
account.getEnergyUsage(), min(leftFrozenEnergy, energyFromFeeLimit), now, now));
receipt.setCallerEnergyMergedUsage(account.getEnergyUsage());
rootRepository.updateAccount(account.createDbKey(), account);
}
if (VMConfig.allowTvmFreezeV2()) {
long now = rootRepository.getHeadSlot();
EnergyProcessor energyProcessor =
new EnergyProcessor(
rootRepository.getDynamicPropertiesStore(),
ChainBaseManager.getInstance().getAccountStore());
energyProcessor.updateUsage(account);
account.setLatestConsumeTimeForEnergy(now);
receipt.setCallerEnergyUsage(account.getEnergyUsage());
receipt.setCallerEnergyWindowSize(account.getWindowSize(Common.ResourceCode.ENERGY));
account.setEnergyUsage(
energyProcessor.increase(account, Common.ResourceCode.ENERGY,
account.getEnergyUsage(), min(leftFrozenEnergy, energyFromFeeLimit), now, now));
receipt.setCallerEnergyMergedUsage(account.getEnergyUsage());
rootRepository.updateAccount(account.createDbKey(), account);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Comment on lines +714 to +729
if (VMConfig.allowTvmFreezeV2()) {
long now = rootRepository.getHeadSlot();
EnergyProcessor energyProcessor =
new EnergyProcessor(
rootRepository.getDynamicPropertiesStore(),
ChainBaseManager.getInstance().getAccountStore());
energyProcessor.updateUsage(creator);
creator.setLatestConsumeTimeForEnergy(now);
receipt.setOriginEnergyUsage(creator.getEnergyUsage());
receipt.setOriginEnergyWindowSize(creator.getWindowSize(Common.ResourceCode.ENERGY));
creator.setEnergyUsage(
energyProcessor.increase(creator, Common.ResourceCode.ENERGY,
creator.getEnergyUsage(), creatorEnergyLimit, now, now));
receipt.setOriginEnergyMergedUsage(creator.getEnergyUsage());
rootRepository.updateAccount(creator.createDbKey(), creator);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

**```


@@ -49,6 +52,8 @@
import org.tron.protos.Protocol.TransactionSign;
import org.tron.protos.contract.SmartContractOuterClass.CreateSmartContract;
import org.tron.protos.contract.SmartContractOuterClass.TriggerSmartContract;
import org.tron.protos.Protocol.Transaction.Contract.ContractType;
import org.tron.protos.contract.BalanceContract.DelegateResourceContract;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://Common.ResourceCode.ENERGY

Suggested change
import org.tron.protos.contract.BalanceContract.DelegateResourceContract;
import org.tron.protos.contract.BalanceContract.DelegateResourceContract;

@@ -0,0 +1,298 @@
package org.tron.core.vm.nativecontract;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actuator/src/main/java/org/tron/core/vm/nativecontract/UnfreezeBalanceV2Processor.java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants