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: add new proposal #4402

Merged
merged 8 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions actuator/src/main/java/org/tron/core/utils/ProposalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}

case ALLOW_ACCOUNT_ASSET_OPTIMIZATION: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_5)) {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_3)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_ACCOUNT_ASSET_OPTIMIZATION]");
}
Expand Down Expand Up @@ -549,6 +549,17 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore,
}
break;
}
case ALLOW_ASSET_OPTIMIZATION: {
if (!forkController.pass(ForkBlockVersionEnum.VERSION_4_5)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_ASSET_OPTIMIZATION]");
}
if (value != 1) {
throw new ContractValidateException(
"This value[ALLOW_ASSET_OPTIMIZATION] is only allowed to be 1");
}
break;
}
default:
break;
}
Expand Down Expand Up @@ -611,7 +622,8 @@ public enum ProposalType { // current value, value range
FREE_NET_LIMIT(61), // 5000, [0, 100_000]
TOTAL_NET_LIMIT(62), // 43_200_000_000L, [0, 1000_000_000_000L]
ALLOW_TVM_LONDON(63), // 0, 1
ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX(65); // 0, 1
ALLOW_HIGHER_LIMIT_FOR_MAX_CPU_TIME_OF_ONE_TX(65), // 0, 1
ALLOW_ASSET_OPTIMIZATION(66); // 0, 1

private long code;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void setDynamicPropertiesStore(DynamicPropertiesStore dynamicPrope
}

public static boolean isAllowAssetOptimization() {
return dynamicPropertiesStore.supportAllowAccountAssetOptimization();
return dynamicPropertiesStore.supportAllowAssetOptimization();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
//This value is only allowed to be 1
private static final byte[] ALLOW_ACCOUNT_ASSET_OPTIMIZATION =
"ALLOW_ACCOUNT_ASSET_OPTIMIZATION".getBytes();

private static final byte[] ALLOW_ASSET_OPTIMIZATION =
"ALLOW_ASSET_OPTIMIZATION".getBytes();


private static final byte[] ENERGY_PRICE_HISTORY = "ENERGY_PRICE_HISTORY".getBytes();
private static final byte[] ENERGY_PRICE_HISTORY_DONE = "ENERGY_PRICE_HISTORY_DONE".getBytes();
private static final byte[] SET_BLACKHOLE_ACCOUNT_PERMISSION =
Expand Down Expand Up @@ -784,6 +789,13 @@ private DynamicPropertiesStore(@Value("properties") String dbName) {
this.saveAllowTvmCompatibleEvm(CommonParameter.getInstance().getAllowTvmCompatibleEvm());
}

try {
this.getAllowAssetOptimization();
} catch (IllegalArgumentException e) {
this.setAllowAssetOptimization(CommonParameter
.getInstance().getAllowAssetOptimization());
}

try {
this.getAllowAccountAssetOptimization();
} catch (IllegalArgumentException e) {
Expand Down Expand Up @@ -2279,6 +2291,10 @@ public boolean supportAllowAccountAssetOptimization() {
return getAllowAccountAssetOptimization() == 1L;
}

public boolean supportAllowAssetOptimization() {
return getAllowAssetOptimization() == 1L;
}

public void saveAllowNewResourceModel(long value) {
this.put(ALLOW_NEW_RESOURCE_MODEL, new BytesCapsule(ByteArray.fromLong(value)));
}
Expand Down Expand Up @@ -2368,7 +2384,7 @@ public long getNewRewardAlgorithmEffectiveCycle() {

public long getAllowAccountAssetOptimizationFromRoot() {
try {
return Optional.ofNullable(getFromRoot(ALLOW_ACCOUNT_ASSET_OPTIMIZATION))
return Optional.ofNullable(getFromRoot(ALLOW_ASSET_OPTIMIZATION))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElseThrow(
Expand All @@ -2389,7 +2405,23 @@ public long getAllowAccountAssetOptimization() {
}

public void setAllowAccountAssetOptimization(long value) {
this.put(ALLOW_ACCOUNT_ASSET_OPTIMIZATION, new BytesCapsule(ByteArray.fromLong(value)));
long allowAssetOptimization = getAllowAssetOptimization();
if (allowAssetOptimization != 1) {
this.put(ALLOW_ACCOUNT_ASSET_OPTIMIZATION, new BytesCapsule(ByteArray.fromLong(value)));
}
}

// 1: enable
public long getAllowAssetOptimization() {
return Optional.ofNullable(getUnchecked(ALLOW_ASSET_OPTIMIZATION))
.map(BytesCapsule::getData)
.map(ByteArray::toLong)
.orElseThrow(
() -> new IllegalArgumentException("not found ALLOW_ASSET_OPTIMIZATION"));
}

public void setAllowAssetOptimization(long value) {
this.put(ALLOW_ASSET_OPTIMIZATION, new BytesCapsule(ByteArray.fromLong(value)));
}

public void saveEnergyPriceHistoryDone(long value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@ public class CommonParameter {
@Setter
public long allowAccountAssetOptimization;

@Getter
@Setter
public long allowAssetOptimization;

@Getter
@Setter
public List<String> disabledApiList;
Expand Down
1 change: 1 addition & 0 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public class Constant {
public static final String OPEN_TRANSACTION_SORT = "node.openTransactionSort";

public static final String ALLOW_ACCOUNT_ASSET_OPTIMIZATION = "committee.allowAccountAssetOptimization";
public static final String ALLOW_ASSET_OPTIMIZATION = "committee.allowAssetOptimization";

public static final String LOCAL_HOST = "127.0.0.1";

Expand Down
4 changes: 4 additions & 0 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,10 @@ public Protocol.ChainParameters getChainParameters() {
.setKey("getAllowHigherLimitForMaxCpuTimeOfOneTx")
.setValue(dbManager.getDynamicPropertiesStore().getAllowHigherLimitForMaxCpuTimeOfOneTx())
.build());
builder.addChainParameter(Protocol.ChainParameters.ChainParameter.newBuilder()
.setKey("getAllowAssetOptimization")
.setValue(dbManager.getDynamicPropertiesStore().getAllowAssetOptimization())
.build());

return builder.build();
}
Expand Down
5 changes: 5 additions & 0 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public static void clearParam() {
PARAMETER.openPrintLog = true;
PARAMETER.openTransactionSort = false;
PARAMETER.allowAccountAssetOptimization = 0;
PARAMETER.allowAssetOptimization = 0;
PARAMETER.disabledApiList = Collections.emptyList();
PARAMETER.shutdownBlockTime = null;
PARAMETER.shutdownBlockHeight = -1;
Expand Down Expand Up @@ -858,6 +859,10 @@ public static void setParam(final String[] args, final String confFileName) {
.hasPath(Constant.ALLOW_ACCOUNT_ASSET_OPTIMIZATION) ? config
.getInt(Constant.ALLOW_ACCOUNT_ASSET_OPTIMIZATION) : 0;

PARAMETER.allowAssetOptimization = config
.hasPath(Constant.ALLOW_ASSET_OPTIMIZATION) ? config
.getInt(Constant.ALLOW_ASSET_OPTIMIZATION) : 0;

PARAMETER.disabledApiList =
config.hasPath(Constant.NODE_DISABLED_API_LIST)
? config.getStringList(Constant.NODE_DISABLED_API_LIST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ public static boolean process(Manager manager, ProposalCapsule proposalCapsule)
entry.getValue());
break;
}
case ALLOW_ASSET_OPTIMIZATION: {
manager.getDynamicPropertiesStore().setAllowAssetOptimization(entry.getValue());
break;
}
default:
find = false;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void put() {
@Test
public void assetTest() {

dynamicPropertiesStore.setAllowAccountAssetOptimization(1);
dynamicPropertiesStore.setAllowAssetOptimization(1);
dynamicPropertiesStore.saveAllowSameTokenName(1);
AccountCapsule accountCapsule = new AccountCapsule(ByteString.copyFrom(address),
ByteString.copyFrom(accountName),
Expand Down Expand Up @@ -200,4 +200,4 @@ private AccountCapsule saveAccount(AccountCapsule accountCapsule) {
return accountCapsule;
}

}
}