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(hard_fork):remove local version checking logic #5268

Merged
merged 2 commits into from
Jun 9, 2023
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
39 changes: 11 additions & 28 deletions chainbase/src/main/java/org/tron/common/utils/ForkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public class ForkController {

public void init(ChainBaseManager manager) {
this.manager = manager;
DynamicPropertiesStore store = manager.getDynamicPropertiesStore();
int latestVersion = store.getLatestVersion();
if (latestVersion == 0) {
for (ForkBlockVersionEnum version : ForkBlockVersionEnum.values()) {
int v = version.getValue();
if (pass(v) && latestVersion < v) {
latestVersion = v;
}
}
store.saveLatestVersion(latestVersion);
}
}

public boolean pass(ForkBlockVersionEnum forkBlockVersionEnum) {
Expand Down Expand Up @@ -218,32 +229,4 @@ private ForkController getInstance() {
}
}

public void checkLocalVersion() {
DynamicPropertiesStore store = manager.getDynamicPropertiesStore();
int latestVersion = store.getLatestVersion();
if (latestVersion == 0) {
for (ForkBlockVersionEnum version : ForkBlockVersionEnum.values()) {
int v = version.getValue();
if (pass(v) && latestVersion < v) {
latestVersion = v;
}
}
store.saveLatestVersion(latestVersion);
return;
}

if (!CommonParameter.getInstance().isVersionCheckEnable()) {
return;
}

int systemVersion = 0;
for (ForkBlockVersionEnum version : ForkBlockVersionEnum.values()) {
if (version.getValue() > systemVersion) {
systemVersion = version.getValue();
}
}
if (latestVersion > systemVersion) {
throw new RuntimeException("Version check failed, please upgrade to the latest version");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,6 @@ public class CommonParameter {
public boolean version;
@Getter
@Setter
public boolean versionCheckEnable;
@Getter
@Setter
public String zenTokenId;
@Getter
@Setter
Expand Down
2 changes: 0 additions & 2 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,5 @@ public class Constant {
public static final String DYNAMIC_CONFIG_ENABLE = "node.dynamicConfig.enable";
public static final String DYNAMIC_CONFIG_CHECK_INTERVAL = "node.dynamicConfig.checkInterval";

public static final String NODE_VERSION_CHECK_ENABLE = "node.versionCheckEnable";

public static final String COMMITTEE_ALLOW_TVM_SHANGHAI = "committee.allowTvmShangHai";
}
4 changes: 0 additions & 4 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ public static void clearParam() {
PARAMETER.p2pDisable = false;
PARAMETER.dynamicConfigEnable = false;
PARAMETER.dynamicConfigCheckInterval = 600;
PARAMETER.versionCheckEnable = true;
PARAMETER.allowTvmShangHai = 0;
}

Expand Down Expand Up @@ -1180,9 +1179,6 @@ public static void setParam(final String[] args, final String confFileName) {
PARAMETER.dynamicConfigCheckInterval = 600;
}

PARAMETER.versionCheckEnable = !config.hasPath(Constant.NODE_VERSION_CHECK_ENABLE)
|| config.getBoolean(Constant.NODE_VERSION_CHECK_ENABLE);

PARAMETER.allowTvmShangHai =
config.hasPath(Constant.COMMITTEE_ALLOW_TVM_SHANGHAI) ? config
.getInt(Constant.COMMITTEE_ALLOW_TVM_SHANGHAI) : 0;
Expand Down
6 changes: 0 additions & 6 deletions framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,6 @@ public void init() {
System.exit(1);
}
getChainBaseManager().getForkController().init(this.chainBaseManager);
try {
getChainBaseManager().getForkController().checkLocalVersion();
} catch (RuntimeException r) {
logger.error("{}", r.getMessage());
System.exit(1);
}

if (Args.getInstance().isNeedToUpdateAsset() && needToUpdateAsset()) {
new AssetUpdateHelper(chainBaseManager).doWork();
Expand Down
33 changes: 0 additions & 33 deletions framework/src/test/java/org/tron/core/ForkControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,39 +222,6 @@ public void testUpdate() {
Assert.assertEquals(getSum(bytes), 4);
}

@Test
public void testCheck() {
byte[] stats1 = {0, 0, 0, 0, 0};
byte[] stats2 = {1, 1, 1, 1, 1};

for (Parameter.ForkBlockVersionEnum version : Parameter.ForkBlockVersionEnum.values()) {
dynamicPropertiesStore.statsByVersion(version.getValue(), stats1);
}

dynamicPropertiesStore
.statsByVersion(Parameter.ForkBlockVersionEnum.VERSION_3_5.getValue(), stats2);

forkController.checkLocalVersion();

Assert.assertEquals(dynamicPropertiesStore.getLatestVersion(),
Parameter.ForkBlockVersionEnum.VERSION_3_5.getValue());


Args.getInstance().setVersionCheckEnable(false);
dynamicPropertiesStore.saveLatestVersion(Integer.MAX_VALUE);

forkController.checkLocalVersion();

Args.getInstance().setVersionCheckEnable(true);

try {
forkController.checkLocalVersion();
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e instanceof RuntimeException);
}
}

private BlockCapsule getBlock(int i, Parameter.ForkBlockVersionEnum versionEnum) {
org.tron.protos.Protocol.BlockHeader.raw rawData =
org.tron.protos.Protocol.BlockHeader.raw.newBuilder()
Expand Down