Skip to content

Commit 805ed34

Browse files
committed
hard fork in mantenance
1 parent 365ae55 commit 805ed34

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/main/java/org/tron/common/utils/ForkController.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,16 @@ public synchronized void update(BlockCapsule blockCapsule) {
159159
version);
160160
}
161161

162-
private void setSolidNumWithVersion5BeEffective() {
162+
private void setSolidNumWithVersion5BeEffective(int version, int witnessSize) {
163+
if (version != ForkBlockVersionConsts.ENERGY_LIMIT) {
164+
return;
165+
}
163166

167+
long num = manager.getDynamicPropertiesStore().getSolidNumWithVersion5();
168+
if (num == -1) {
169+
long blockNum = manager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum();
170+
manager.getDynamicPropertiesStore().setSolidNumWithVersion5(blockNum + witnessSize * 2 / 3);
171+
}
164172
}
165173

166174
public synchronized void updateWhenMaintenance(BlockCapsule blockCapsule) {

src/main/java/org/tron/core/db/DynamicPropertiesStore.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.springframework.beans.factory.annotation.Value;
1111
import org.springframework.stereotype.Component;
1212
import org.tron.common.utils.ByteArray;
13+
import org.tron.common.utils.ByteUtil;
1314
import org.tron.common.utils.Sha256Hash;
1415
import org.tron.core.capsule.BytesCapsule;
1516
import org.tron.core.config.Parameter;
@@ -119,6 +120,7 @@ private static class DynamicResourceProperties {
119120

120121
private static final byte[] FORK_CONTROLLER = "FORK_CONTROLLER".getBytes();
121122
private static final String FORK_PREFIX = "FORK_VERSION_";
123+
private static final byte[] SOLID_NUM_WITH_VERSION_5 = "SOLID_NUM_WITH_VERSION_5".getBytes();
122124

123125
//This value is only allowed to be 0, 1, -1
124126
private static final byte[] REMOVE_THE_POWER_OF_THE_GR = "REMOVE_THE_POWER_OF_THE_GR".getBytes();
@@ -1411,6 +1413,18 @@ public byte[] statsByVersion(int version) {
14111413
return revokingDB.getUnchecked(statsKey.getBytes());
14121414
}
14131415

1416+
public void setSolidNumWithVersion5(long blockNum) {
1417+
byte[] longBytes = ByteArray.fromLong(blockNum);
1418+
put(SOLID_NUM_WITH_VERSION_5, new BytesCapsule(longBytes));
1419+
}
1420+
1421+
public long getSolidNumWithVersion5() {
1422+
return Optional.ofNullable(getUnchecked(SOLID_NUM_WITH_VERSION_5))
1423+
.map(BytesCapsule::getData)
1424+
.map(ByteArray::toLong)
1425+
.orElse(-1L);
1426+
}
1427+
14141428
public boolean getForked() {
14151429
byte[] value = revokingDB.getUnchecked(FORK_CONTROLLER);
14161430
return value == null ? Boolean.FALSE : Boolean.valueOf(new String(value));

0 commit comments

Comments
 (0)