diff --git a/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java b/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java index f4220002f3a..4f128884dfd 100644 --- a/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java +++ b/actuator/src/main/java/org/tron/core/utils/ProposalUtil.java @@ -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]"); } @@ -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; } @@ -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; diff --git a/chainbase/src/main/java/org/tron/core/capsule/utils/AssetUtil.java b/chainbase/src/main/java/org/tron/core/capsule/utils/AssetUtil.java index fff204ebdf2..7638ac0bb69 100644 --- a/chainbase/src/main/java/org/tron/core/capsule/utils/AssetUtil.java +++ b/chainbase/src/main/java/org/tron/core/capsule/utils/AssetUtil.java @@ -61,7 +61,7 @@ public static void setDynamicPropertiesStore(DynamicPropertiesStore dynamicPrope } public static boolean isAllowAssetOptimization() { - return dynamicPropertiesStore.supportAllowAccountAssetOptimization(); + return dynamicPropertiesStore.supportAllowAssetOptimization(); } -} \ No newline at end of file +} diff --git a/chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java b/chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java index 08215bb12eb..721eb80d14d 100644 --- a/chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java +++ b/chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java @@ -167,6 +167,11 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking //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 = @@ -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) { @@ -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))); } @@ -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( @@ -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) { diff --git a/common/src/main/java/org/tron/common/parameter/CommonParameter.java b/common/src/main/java/org/tron/common/parameter/CommonParameter.java index adc9f36eee0..df4cf35f71c 100644 --- a/common/src/main/java/org/tron/common/parameter/CommonParameter.java +++ b/common/src/main/java/org/tron/common/parameter/CommonParameter.java @@ -530,6 +530,10 @@ public class CommonParameter { @Setter public long allowAccountAssetOptimization; + @Getter + @Setter + public long allowAssetOptimization; + @Getter @Setter public List disabledApiList; diff --git a/common/src/main/java/org/tron/core/Constant.java b/common/src/main/java/org/tron/core/Constant.java index 679d27461c7..d0a557ccf44 100644 --- a/common/src/main/java/org/tron/core/Constant.java +++ b/common/src/main/java/org/tron/core/Constant.java @@ -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"; diff --git a/framework/src/main/java/org/tron/core/Wallet.java b/framework/src/main/java/org/tron/core/Wallet.java index 3282922714e..7015afe2405 100755 --- a/framework/src/main/java/org/tron/core/Wallet.java +++ b/framework/src/main/java/org/tron/core/Wallet.java @@ -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(); } diff --git a/framework/src/main/java/org/tron/core/config/args/Args.java b/framework/src/main/java/org/tron/core/config/args/Args.java index 4fb4beb98ac..f35b10c8034 100644 --- a/framework/src/main/java/org/tron/core/config/args/Args.java +++ b/framework/src/main/java/org/tron/core/config/args/Args.java @@ -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; @@ -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) diff --git a/framework/src/main/java/org/tron/core/consensus/ProposalService.java b/framework/src/main/java/org/tron/core/consensus/ProposalService.java index 1803bb6811d..21c3e70896f 100644 --- a/framework/src/main/java/org/tron/core/consensus/ProposalService.java +++ b/framework/src/main/java/org/tron/core/consensus/ProposalService.java @@ -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; diff --git a/framework/src/test/java/org/tron/core/db/AccountStoreTest.java b/framework/src/test/java/org/tron/core/db/AccountStoreTest.java index 22e1d70d301..44efc7f1e97 100755 --- a/framework/src/test/java/org/tron/core/db/AccountStoreTest.java +++ b/framework/src/test/java/org/tron/core/db/AccountStoreTest.java @@ -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), @@ -202,4 +202,4 @@ private AccountCapsule saveAccount(AccountCapsule accountCapsule) { return accountCapsule; } -} \ No newline at end of file +}