Skip to content

Commit

Permalink
Merge pull request tronprotocol#3314 from tronprotocol/release_4.0.1
Browse files Browse the repository at this point in the history
Release 4.0.1
  • Loading branch information
lvs007 authored Jul 29, 2020
2 parents 742f321 + 6a30e73 commit 67170b6
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public static void validator(DynamicPropertiesStore dynamicPropertiesStore, Fork
break;
}
case ALLOW_SHIELDED_TRC20_TRANSACTION: {
if (!forkUtils.pass(ForkBlockVersionEnum.VERSION_4_0)) {
if (!forkUtils.pass(ForkBlockVersionEnum.VERSION_4_0_1)) {
throw new ContractValidateException(
"Bad chain parameter id [ALLOW_SHIELDED_TRC20_TRANSACTION]");
}
Expand Down
34 changes: 34 additions & 0 deletions chainbase/src/main/java/org/tron/common/utils/ForkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public boolean pass(ForkBlockVersionEnum forkBlockVersionEnum) {
}

public synchronized boolean pass(int version) {
if (version > ForkBlockVersionEnum.VERSION_4_0.getValue()) {
return passNew(version);
} else {
return passOld(version);
}
}

private boolean passOld(int version) {
if (version == ForkBlockVersionConsts.ENERGY_LIMIT) {
return checkForEnergyLimit();
}
Expand All @@ -45,6 +53,32 @@ public synchronized boolean pass(int version) {
return check(stats);
}

private boolean passNew(int version) {
ForkBlockVersionEnum versionEnum = ForkBlockVersionEnum.getForkBlockVersionEnum(version);
if (versionEnum == null) {
logger.error("not exist block version: {}", version);
return false;
}
long latestBlockTime = dynamicPropertiesStore.getLatestBlockHeaderTimestamp();
long maintenanceTimeInterval = dynamicPropertiesStore.getMaintenanceTimeInterval();
long hardForkTime = ((versionEnum.getHardForkTime() - 1) / maintenanceTimeInterval + 1)
* maintenanceTimeInterval;
if (latestBlockTime < hardForkTime) {
return false;
}
byte[] stats = dynamicPropertiesStore.statsByVersion(version);
if (stats == null || stats.length == 0) {
return false;
}
int count = 0;
for (int i = 0; i < stats.length; i++) {
if (check[i] == stats[i]) {
++count;
}
}
return count >= versionEnum.getHardForkCount();
}

// when block.version = 5,
// it make block use new energy to handle transaction when block number >= 4727890L.
// version !=5, skip this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ChainConstant {
public static final int SINGLE_REPEAT = 1;
public static final int BLOCK_FILLED_SLOTS_NUMBER = 128;
public static final int MAX_FROZEN_NUMBER = 1;
public static final int BLOCK_VERSION = 16;
public static final int BLOCK_VERSION = 17;
}

public class NodeConstant {
Expand Down
32 changes: 24 additions & 8 deletions chainbase/src/main/java/org/tron/core/config/args/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,35 @@
public class Parameter {

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

@Getter
private int value;
@Getter
private long hardForkTime;
@Getter
private int hardForkCount;

ForkBlockVersionEnum(int value) {
ForkBlockVersionEnum(int value, long hardForkTime, int hardForkCount) {
this.value = value;
this.hardForkTime = hardForkTime;
this.hardForkCount = hardForkCount;
}

public static ForkBlockVersionEnum getForkBlockVersionEnum(int value) {
for (ForkBlockVersionEnum versionEnum : values()) {
if (versionEnum.getValue() == value) {
return versionEnum;
}
}
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
private static final byte[] TOTAL_STORAGE_TAX = "TOTAL_STORAGE_TAX".getBytes();
private static final byte[] TOTAL_STORAGE_RESERVED = "TOTAL_STORAGE_RESERVED".getBytes();
private static final byte[] STORAGE_EXCHANGE_TAX_RATE = "STORAGE_EXCHANGE_TAX_RATE".getBytes();
private static final byte[] FORK_CONTROLLER = "FORK_CONTROLLER".getBytes();
private static final String FORK_CONTROLLER = "FORK_CONTROLLER";
private static final String FORK_PREFIX = "FORK_VERSION_";
//This value is only allowed to be 0, 1, -1
private static final byte[] REMOVE_THE_POWER_OF_THE_GR = "REMOVE_THE_POWER_OF_THE_GR".getBytes();
Expand Down Expand Up @@ -121,7 +121,7 @@ public class DynamicPropertiesStore extends TronStoreWithRevoking<BytesCapsule>
private static final byte[] ALLOW_SHIELDED_TRANSACTION = "ALLOW_SHIELDED_TRANSACTION".getBytes();
private static final byte[] ALLOW_SHIELDED_TRC20_TRANSACTION =
"ALLOW_SHIELDED_TRC20_TRANSACTION"
.getBytes();
.getBytes();
private static final byte[] ALLOW_TVM_CONSTANTINOPLE = "ALLOW_TVM_CONSTANTINOPLE".getBytes();
private static final byte[] ALLOW_TVM_SOLIDITY_059 = "ALLOW_TVM_SOLIDITY_059".getBytes();
private static final byte[] FORBID_TRANSFER_TO_CONTRACT = "FORBID_TRANSFER_TO_CONTRACT"
Expand Down Expand Up @@ -1767,8 +1767,9 @@ public void addTotalTransactionCost(long fee) {
saveTotalTransactionCost(newValue);
}

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

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

public boolean getForked() {
byte[] value = revokingDB.getUnchecked(FORK_CONTROLLER);
return value == null ? Boolean.FALSE : Boolean.valueOf(new String(value));
public Boolean getForked(int version) {
String forkKey = FORK_CONTROLLER + version;
byte[] value = revokingDB.getUnchecked(forkKey.getBytes());
return value == null ? null : Boolean.valueOf(new String(value));
}

/**
Expand Down Expand Up @@ -1871,10 +1873,10 @@ private static class DynamicResourceProperties {
private static final byte[] BLOCK_ENERGY_USAGE = "BLOCK_ENERGY_USAGE".getBytes();
private static final byte[] ADAPTIVE_RESOURCE_LIMIT_MULTIPLIER =
"ADAPTIVE_RESOURCE_LIMIT_MULTIPLIER"
.getBytes();
.getBytes();
private static final byte[] ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO =
"ADAPTIVE_RESOURCE_LIMIT_TARGET_RATIO"
.getBytes();
.getBytes();
}

}
9 changes: 0 additions & 9 deletions framework/src/main/java/org/tron/common/entity/NodeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ public static class ConfigNodeInfo {

/*node information*/
private String codeVersion;
private String versionName;
private String versionNum;
private String p2pVersion;
private int listenPort;
Expand Down Expand Up @@ -534,14 +533,6 @@ public ConfigNodeInfo setCodeVersion(String codeVersion) {
return this;
}

public String getVersionName() {
return versionName;
}

public void setVersionName(String versionName) {
this.versionName = versionName;
}

public String getVersionNum() {
return versionNum;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,6 @@ private static void logConfig() {
logger.info("Backup priority: {}", args.getBackupPriority());
logger.info("************************ Code version *************************");
logger.info("Code version : {}", Version.getVersion());
logger.info("Version name: {}", Version.versionName);
logger.info("Version code: {}", Version.versionCode);
logger.info("************************ DB config *************************");
logger.info("DB version : {}", args.getStorage().getDbVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ private void setConnectInfo(NodeInfo nodeInfo) {
private void setConfigNodeInfo(NodeInfo nodeInfo) {
ConfigNodeInfo configNodeInfo = new ConfigNodeInfo();
configNodeInfo.setCodeVersion(Version.getVersion());
configNodeInfo.setVersionName(Version.versionName);
configNodeInfo.setVersionNum(Version.versionCode);
configNodeInfo.setP2pVersion(String.valueOf(args.getNodeP2pVersion()));
configNodeInfo.setListenPort(args.getNodeListenPort());
Expand Down

0 comments on commit 67170b6

Please sign in to comment.