Skip to content

Commit 67170b6

Browse files
authored
Merge pull request #3314 from tronprotocol/release_4.0.1
Release 4.0.1
2 parents 742f321 + 6a30e73 commit 67170b6

File tree

8 files changed

+71
-30
lines changed

8 files changed

+71
-30
lines changed

actuator/src/main/java/org/tron/core/utils/ProposalUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore, Fork
302302
break;
303303
}
304304
case ALLOW_SHIELDED_TRC20_TRANSACTION: {
305-
if (!forkUtils.pass(ForkBlockVersionEnum.VERSION_4_0)) {
305+
if (!forkUtils.pass(ForkBlockVersionEnum.VERSION_4_0_1)) {
306306
throw new ContractValidateException(
307307
"Bad chain parameter id [ALLOW_SHIELDED_TRC20_TRANSACTION]");
308308
}

chainbase/src/main/java/org/tron/common/utils/ForkUtils.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ public boolean pass(ForkBlockVersionEnum forkBlockVersionEnum) {
3737
}
3838

3939
public synchronized boolean pass(int version) {
40+
if (version > ForkBlockVersionEnum.VERSION_4_0.getValue()) {
41+
return passNew(version);
42+
} else {
43+
return passOld(version);
44+
}
45+
}
46+
47+
private boolean passOld(int version) {
4048
if (version == ForkBlockVersionConsts.ENERGY_LIMIT) {
4149
return checkForEnergyLimit();
4250
}
@@ -45,6 +53,32 @@ public synchronized boolean pass(int version) {
4553
return check(stats);
4654
}
4755

56+
private boolean passNew(int version) {
57+
ForkBlockVersionEnum versionEnum = ForkBlockVersionEnum.getForkBlockVersionEnum(version);
58+
if (versionEnum == null) {
59+
logger.error("not exist block version: {}", version);
60+
return false;
61+
}
62+
long latestBlockTime = dynamicPropertiesStore.getLatestBlockHeaderTimestamp();
63+
long maintenanceTimeInterval = dynamicPropertiesStore.getMaintenanceTimeInterval();
64+
long hardForkTime = ((versionEnum.getHardForkTime() - 1) / maintenanceTimeInterval + 1)
65+
* maintenanceTimeInterval;
66+
if (latestBlockTime < hardForkTime) {
67+
return false;
68+
}
69+
byte[] stats = dynamicPropertiesStore.statsByVersion(version);
70+
if (stats == null || stats.length == 0) {
71+
return false;
72+
}
73+
int count = 0;
74+
for (int i = 0; i < stats.length; i++) {
75+
if (check[i] == stats[i]) {
76+
++count;
77+
}
78+
}
79+
return count >= versionEnum.getHardForkCount();
80+
}
81+
4882
// when block.version = 5,
4983
// it make block use new energy to handle transaction when block number >= 4727890L.
5084
// version !=5, skip this.

chainbase/src/main/java/org/tron/core/config/Parameter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ChainConstant {
1818
public static final int SINGLE_REPEAT = 1;
1919
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
2020
public static final int MAX_FROZEN_NUMBER = 1;
21-
public static final int BLOCK_VERSION = 16;
21+
public static final int BLOCK_VERSION = 17;
2222
}
2323

2424
public class NodeConstant {

chainbase/src/main/java/org/tron/core/config/args/Parameter.java

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,35 @@
55
public class Parameter {
66

77
public enum ForkBlockVersionEnum {
8-
ENERGY_LIMIT(5),
9-
VERSION_3_2_2(6),
10-
VERSION_3_5(7),
11-
VERSION_3_6(8),
12-
VERSION_3_6_5(9),
13-
VERSION_3_6_6(10),
14-
VERSION_4_0(16);
8+
ENERGY_LIMIT(5, 0L, 0),
9+
VERSION_3_2_2(6, 0L, 0),
10+
VERSION_3_5(7, 0L, 0),
11+
VERSION_3_6(8, 0L, 0),
12+
VERSION_3_6_5(9, 0L, 0),
13+
VERSION_3_6_6(10, 0L, 0),
14+
VERSION_4_0(16, 0L, 0),
15+
VERSION_4_0_1(17, 1596780000000L, 22);//GMT 2020-08-07 06:00:00
1516

1617
@Getter
1718
private int value;
19+
@Getter
20+
private long hardForkTime;
21+
@Getter
22+
private int hardForkCount;
1823

19-
ForkBlockVersionEnum(int value) {
24+
ForkBlockVersionEnum(int value, long hardForkTime, int hardForkCount) {
2025
this.value = value;
26+
this.hardForkTime = hardForkTime;
27+
this.hardForkCount = hardForkCount;
28+
}
29+
30+
public static ForkBlockVersionEnum getForkBlockVersionEnum(int value) {
31+
for (ForkBlockVersionEnum versionEnum : values()) {
32+
if (versionEnum.getValue() == value) {
33+
return versionEnum;
34+
}
35+
}
36+
return null;
2137
}
2238
}
2339

chainbase/src/main/java/org/tron/core/store/DynamicPropertiesStore.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
9191
private static final byte[] TOTAL_STORAGE_TAX = "TOTAL_STORAGE_TAX".getBytes();
9292
private static final byte[] TOTAL_STORAGE_RESERVED = "TOTAL_STORAGE_RESERVED".getBytes();
9393
private static final byte[] STORAGE_EXCHANGE_TAX_RATE = "STORAGE_EXCHANGE_TAX_RATE".getBytes();
94-
private static final byte[] FORK_CONTROLLER = "FORK_CONTROLLER".getBytes();
94+
private static final String FORK_CONTROLLER = "FORK_CONTROLLER";
9595
private static final String FORK_PREFIX = "FORK_VERSION_";
9696
//This value is only allowed to be 0, 1, -1
9797
private static final byte[] REMOVE_THE_POWER_OF_THE_GR = "REMOVE_THE_POWER_OF_THE_GR".getBytes();
@@ -121,7 +121,7 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
121121
private static final byte[] ALLOW_SHIELDED_TRANSACTION = "ALLOW_SHIELDED_TRANSACTION".getBytes();
122122
private static final byte[] ALLOW_SHIELDED_TRC20_TRANSACTION =
123123
"ALLOW_SHIELDED_TRC20_TRANSACTION"
124-
.getBytes();
124+
.getBytes();
125125
private static final byte[] ALLOW_TVM_CONSTANTINOPLE = "ALLOW_TVM_CONSTANTINOPLE".getBytes();
126126
private static final byte[] ALLOW_TVM_SOLIDITY_059 = "ALLOW_TVM_SOLIDITY_059".getBytes();
127127
private static final byte[] FORBID_TRANSFER_TO_CONTRACT = "FORBID_TRANSFER_TO_CONTRACT"
@@ -1767,8 +1767,9 @@ public void addTotalTransactionCost(long fee) {
17671767
saveTotalTransactionCost(newValue);
17681768
}
17691769

1770-
public void forked() {
1771-
put(FORK_CONTROLLER, new BytesCapsule(Boolean.toString(true).getBytes()));
1770+
public void forked(int version, boolean value) {
1771+
String forkKey = FORK_CONTROLLER + version;
1772+
put(forkKey.getBytes(), new BytesCapsule(Boolean.toString(value).getBytes()));
17721773
}
17731774

17741775
public void statsByVersion(int version, byte[] stats) {
@@ -1781,9 +1782,10 @@ public byte[] statsByVersion(int version) {
17811782
return revokingDB.getUnchecked(statsKey.getBytes());
17821783
}
17831784

1784-
public boolean getForked() {
1785-
byte[] value = revokingDB.getUnchecked(FORK_CONTROLLER);
1786-
return value == null ? Boolean.FALSE : Boolean.valueOf(new String(value));
1785+
public Boolean getForked(int version) {
1786+
String forkKey = FORK_CONTROLLER + version;
1787+
byte[] value = revokingDB.getUnchecked(forkKey.getBytes());
1788+
return value == null ? null : Boolean.valueOf(new String(value));
17871789
}
17881790

17891791
/**
@@ -1871,10 +1873,10 @@ private static class DynamicResourceProperties {
18711873
private static final byte[] BLOCK_ENERGY_USAGE = "BLOCK_ENERGY_USAGE".getBytes();
18721874
private static final byte[] ADAPTIVE_RESOURCE_LIMIT_MULTIPLIER =
18731875
"ADAPTIVE_RESOURCE_LIMIT_MULTIPLIER"
1874-
.getBytes();
1876+
.getBytes();
18751877
private static final byte[] ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO =
18761878
"ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO"
1877-
.getBytes();
1879+
.getBytes();
18781880
}
18791881

18801882
}

framework/src/main/java/org/tron/common/entity/NodeInfo.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,6 @@ public static class ConfigNodeInfo {
504504

505505
/*node information*/
506506
private String codeVersion;
507-
private String versionName;
508507
private String versionNum;
509508
private String p2pVersion;
510509
private int listenPort;
@@ -534,14 +533,6 @@ public ConfigNodeInfo setCodeVersion(String codeVersion) {
534533
return this;
535534
}
536535

537-
public String getVersionName() {
538-
return versionName;
539-
}
540-
541-
public void setVersionName(String versionName) {
542-
this.versionName = versionName;
543-
}
544-
545536
public String getVersionNum() {
546537
return versionNum;
547538
}

framework/src/main/java/org/tron/core/config/args/Args.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,6 @@ private static void logConfig() {
14561456
logger.info("Backup priority: {}", args.getBackupPriority());
14571457
logger.info("************************ Code version *************************");
14581458
logger.info("Code version : {}", Version.getVersion());
1459-
logger.info("Version name: {}", Version.versionName);
14601459
logger.info("Version code: {}", Version.versionCode);
14611460
logger.info("************************ DB config *************************");
14621461
logger.info("DB version : {}", args.getStorage().getDbVersion());

framework/src/main/java/org/tron/core/services/NodeInfoService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ private void setConnectInfo(NodeInfo nodeInfo) {
165165
private void setConfigNodeInfo(NodeInfo nodeInfo) {
166166
ConfigNodeInfo configNodeInfo = new ConfigNodeInfo();
167167
configNodeInfo.setCodeVersion(Version.getVersion());
168-
configNodeInfo.setVersionName(Version.versionName);
169168
configNodeInfo.setVersionNum(Version.versionCode);
170169
configNodeInfo.setP2pVersion(String.valueOf(args.getNodeP2pVersion()));
171170
configNodeInfo.setListenPort(args.getNodeListenPort());

0 commit comments

Comments
 (0)