Skip to content

Commit 4bc0b9d

Browse files
committed
2 parents 246ba16 + 1b271b3 commit 4bc0b9d

File tree

5 files changed

+62
-12
lines changed

5 files changed

+62
-12
lines changed

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

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,22 @@
1717
import org.apache.commons.lang3.StringUtils;
1818
import org.tron.core.Wallet;
1919
import org.tron.core.capsule.BlockCapsule;
20-
import org.tron.core.config.Parameter;
2120
import org.tron.core.config.Parameter.ForkBlockVersionConsts;
2221
import org.tron.core.db.Manager;
2322

2423
@Slf4j
2524
@NoArgsConstructor(access = AccessLevel.PRIVATE)
2625
public class ForkController {
2726

27+
private static final byte VERSION_UPGRADE = (byte) 1;
28+
private static final byte HARD_FORK_EFFECTIVE = (byte) 2;
2829
private static final byte[] check;
30+
private static final byte[] check2;
2931
static {
3032
check = new byte[1024];
31-
Arrays.fill(check, (byte) 1);
33+
Arrays.fill(check, VERSION_UPGRADE);
34+
check2 = new byte[1024];
35+
Arrays.fill(check2, HARD_FORK_EFFECTIVE);
3236
}
3337

3438
@Getter
@@ -42,7 +46,7 @@ public void init(Manager manager) {
4246
}
4347

4448
public synchronized boolean pass(int version) {
45-
if (!check(version)) {
49+
if (!checkEnergy(version)) {
4650
return false;
4751
}
4852

@@ -51,14 +55,23 @@ public synchronized boolean pass(int version) {
5155
}
5256

5357
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(version);
54-
boolean pass = check(stats);
58+
boolean pass;
59+
if (version == ForkBlockVersionConsts.ENERGY_LIMIT) {
60+
pass = check(stats);
61+
} else {
62+
pass = check2(stats);
63+
}
64+
5565
if (pass) {
5666
passSet.add(version);
5767
}
5868
return pass;
5969
}
6070

61-
private boolean check(int version) {
71+
// when block.version = 5,
72+
// it make block use new energy to handle transaction when block number >= 4727890L.
73+
// version !=5, skip this.
74+
private boolean checkEnergy(int version) {
6275
if (version != ForkBlockVersionConsts.ENERGY_LIMIT) {
6376
return true;
6477
}
@@ -68,6 +81,14 @@ private boolean check(int version) {
6881
}
6982

7083
private boolean check(byte[] stats) {
84+
return check(check, stats);
85+
}
86+
87+
private boolean check2(byte[] stats) {
88+
return check(check2, stats);
89+
}
90+
91+
private boolean check(byte[] check, byte[] stats) {
7192
if (stats == null || stats.length == 0) {
7293
return false;
7394
}
@@ -95,16 +116,15 @@ public synchronized void update(BlockCapsule blockCapsule) {
95116
}
96117

97118
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(version);
98-
if (check(stats)) {
99-
passSet.add(version);
119+
if (check(stats) || check2(stats)) {
100120
return;
101121
}
102122

103123
if (stats == null) {
104124
stats = new byte[witnesses.size()];
105125
}
106126

107-
stats[slot] = (byte) 1;
127+
stats[slot] = VERSION_UPGRADE;
108128
manager.getDynamicPropertiesStore().statsByVersion(version, stats);
109129
logger.info(
110130
"*******update hard fork:{}, witness size:{}, solt:{}, witness:{}, version:{}",
@@ -118,15 +138,32 @@ public synchronized void update(BlockCapsule blockCapsule) {
118138
version);
119139
}
120140

141+
public synchronized void updateWhenMaintenance(BlockCapsule blockCapsule) {
142+
int version = blockCapsule.getInstance().getBlockHeader().getRawData().getVersion();
143+
if (version < ForkBlockVersionConsts.VERSION_3_2_2 || passSet.contains(version)) {
144+
return;
145+
}
146+
147+
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(version);
148+
if (check2(stats)) {
149+
return;
150+
}
151+
152+
if (check(stats)) {
153+
Arrays.fill(stats, HARD_FORK_EFFECTIVE);
154+
manager.getDynamicPropertiesStore().statsByVersion(version, stats);
155+
logger.info("*******hard fork is effective in the maintenance, version is {}", version);
156+
}
157+
}
158+
121159
public synchronized void reset(BlockCapsule blockCapsule) {
122160
int version = blockCapsule.getInstance().getBlockHeader().getRawData().getVersion();
123161
if (version < ForkBlockVersionConsts.ENERGY_LIMIT || passSet.contains(version)) {
124162
return;
125163
}
126164

127165
byte[] stats = manager.getDynamicPropertiesStore().statsByVersion(version);
128-
if (check(stats)) {
129-
passSet.add(version);
166+
if (check(stats) || check2(stats)) {
130167
return;
131168
}
132169

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ interface ForkBlockVersionConsts {
107107

108108
int START_NEW_TRANSACTION = 4;
109109
int ENERGY_LIMIT = 5;
110+
int VERSION_3_2_2 = 6;
110111
}
111112

112113
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,7 @@ void validateCommon(TransactionCapsule transactionCapsule)
594594
}
595595

596596
void validateDup(TransactionCapsule transactionCapsule) throws DupTransactionException {
597-
if (getTransactionStore().getUnchecked(transactionCapsule.getTransactionId().getBytes())
598-
!= null) {
597+
if (getTransactionStore().has(transactionCapsule.getTransactionId().getBytes())) {
599598
logger.debug(ByteArray.toHexString(transactionCapsule.getTransactionId().getBytes()));
600599
throw new DupTransactionException("dup trans");
601600
}
@@ -1406,6 +1405,7 @@ private void processMaintenance(BlockCapsule block) {
14061405
proposalController.processProposals();
14071406
witnessController.updateWitness();
14081407
this.dynamicPropertiesStore.updateNextMaintenanceTime(block.getTimeStamp());
1408+
forkController.updateWhenMaintenance(block);
14091409
forkController.reset(block);
14101410
}
14111411

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ public TransactionCapsule get(byte[] key) throws BadItemException {
8686
return transactionCapsule == null ? new TransactionCapsule(value) : transactionCapsule;
8787
}
8888

89+
@Override
90+
public TransactionCapsule getUnchecked(byte[] key) {
91+
try {
92+
return get(key);
93+
} catch (Exception e) {
94+
return null;
95+
}
96+
}
97+
8998
/**
9099
* get total transaction.
91100
*/

src/main/java/org/tron/program/SolidityNode.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ private void processTrx() {
257257
logger.warn("Failed to get trx: {}, reason: {}", trx.getTransactionId(), ex.getMessage());
258258
continue;
259259
}
260+
if (ret == null) {
261+
continue;
262+
}
260263
ret.setBlockNumber(blockCapsule.getNum());
261264
ret.setBlockTimeStamp(blockCapsule.getTimeStamp());
262265
dbManager.getTransactionHistoryStore().put(trx.getTransactionId().getBytes(), ret);

0 commit comments

Comments
 (0)