Skip to content

Commit a60e920

Browse files
authored
Merge branch 'release_v4.7.2' into feature/support_shanghai
2 parents 519cbeb + f6dd0d9 commit a60e920

161 files changed

Lines changed: 3301 additions & 5029 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

chainbase/src/main/java/org/tron/core/capsule/ReceiptCapsule.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ public void payEnergyBill(DynamicPropertiesStore dynamicPropertiesStore,
192192
AccountCapsule caller,
193193
long percent, long originEnergyLimit, EnergyProcessor energyProcessor, long now)
194194
throws BalanceInsufficientException {
195+
196+
// Reset origin energy usage here! Because after stake 2.0, this field are reused for
197+
// recording pre-merge frozen energy for origin account. If total energy usage is zero, this
198+
// field will be a dirty record.
199+
this.setOriginEnergyUsage(0);
200+
195201
if (receipt.getEnergyUsageTotal() <= 0) {
196202
return;
197203
}

chainbase/src/main/java/org/tron/core/db2/core/SnapshotManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Map;
1717
import java.util.Objects;
1818
import java.util.concurrent.ExecutionException;
19+
import java.util.concurrent.ExecutorService;
1920
import java.util.concurrent.Executors;
2021
import java.util.concurrent.Future;
2122
import java.util.concurrent.ScheduledExecutorService;
@@ -122,6 +123,7 @@ public void close() {
122123
exitThread.interrupt();
123124
// help GC
124125
exitThread = null;
126+
flushServices.values().forEach(ExecutorService::shutdown);
125127
} catch (Exception e) {
126128
logger.warn("exitThread interrupt error", e);
127129
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.tron.core.db.TransactionStore;
1515
import org.tron.core.db.TronStoreWithRevoking;
1616
import org.tron.core.exception.BadItemException;
17+
import org.tron.protos.Protocol;
1718
import org.tron.protos.Protocol.TransactionInfo;
1819

1920
@Slf4j(topic = "DB")
@@ -54,6 +55,17 @@ public TransactionInfoCapsule getTransactionInfo(byte[] key) throws BadItemExcep
5455
ByteString id = ByteString.copyFrom(key);
5556
for (TransactionInfo transactionResultInfo : result.getInstance().getTransactioninfoList()) {
5657
if (transactionResultInfo.getId().equals(id)) {
58+
Protocol.ResourceReceipt receipt = transactionResultInfo.getReceipt();
59+
// If query a result with dirty origin usage in receipt, we just reset it.
60+
if (receipt.getEnergyUsageTotal() == 0 && receipt.getOriginEnergyUsage() > 0) {
61+
transactionResultInfo =
62+
transactionResultInfo.toBuilder()
63+
.setReceipt(
64+
receipt.toBuilder()
65+
.clearOriginEnergyUsage()
66+
.build())
67+
.build();
68+
}
5769
return new TransactionInfoCapsule(transactionResultInfo);
5870
}
5971
}

common/src/main/java/org/tron/core/exception/BadBlockException.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,37 @@
22

33
public class BadBlockException extends TronException {
44

5+
private TypeEnum type = TypeEnum.DEFAULT;
6+
57
public BadBlockException() {
68
super();
79
}
810

911
public BadBlockException(String message) {
1012
super(message);
1113
}
14+
15+
public BadBlockException(TypeEnum type, String message) {
16+
super(message);
17+
this.type = type;
18+
}
19+
20+
public TypeEnum getType() {
21+
return type;
22+
}
23+
24+
public enum TypeEnum {
25+
CALC_MERKLE_ROOT_FAILED(1),
26+
DEFAULT(100);
27+
28+
private Integer value;
29+
30+
TypeEnum(Integer value) {
31+
this.value = value;
32+
}
33+
34+
public Integer getValue() {
35+
return value;
36+
}
37+
}
1238
}

common/src/main/java/org/tron/core/exception/P2pException.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public enum TypeEnum {
5050
TRX_EXE_FAILED(12, "trx exe failed"),
5151
DB_ITEM_NOT_FOUND(13, "DB item not found"),
5252
PROTOBUF_ERROR(14, "protobuf inconsistent"),
53+
BLOCK_SIGN_ERROR(15, "block sign error"),
54+
BLOCK_MERKLE_ERROR(16, "block merkle error"),
5355

5456
DEFAULT(100, "default exception");
5557

framework/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ dependencies {
8686
compile "io.vavr:vavr:0.9.2"
8787
compile group: 'org.pf4j', name: 'pf4j', version: '2.5.0'
8888

89+
testImplementation group: 'org.springframework', name: 'spring-test', version: '5.2.0.RELEASE'
90+
8991
compile group: 'org.zeromq', name: 'jeromq', version: '0.5.0'
9092
compile project(":chainbase")
9193
compile project(":protocol")
@@ -151,6 +153,10 @@ test {
151153
exclude 'org/tron/common/runtime/vm/WithdrawRewardTest.class'
152154
}
153155
maxHeapSize = "1024m"
156+
doFirst {
157+
forkEvery = 100
158+
jvmArgs "-XX:MetaspaceSize=128m","-XX:MaxMetaspaceSize=256m", "-XX:+UseG1GC"
159+
}
154160
}
155161

156162
task stest(type: Test) {

framework/src/main/java/org/tron/common/client/DatabaseGrpcClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public class DatabaseGrpcClient {
1515

1616
public DatabaseGrpcClient(String host, int port) {
1717
channel = ManagedChannelBuilder.forAddress(host, port)
18-
.usePlaintext(true)
18+
.usePlaintext()
1919
.build();
2020
databaseBlockingStub = DatabaseGrpc.newBlockingStub(channel);
2121
}
2222

2323
public DatabaseGrpcClient(String host) {
2424
channel = ManagedChannelBuilder.forTarget(host)
25-
.usePlaintext(true)
25+
.usePlaintext()
2626
.build();
2727
databaseBlockingStub = DatabaseGrpc.newBlockingStub(channel);
2828
}

framework/src/main/java/org/tron/common/client/WalletGrpcClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public class WalletGrpcClient {
2929

3030
public WalletGrpcClient(String host, int port) {
3131
channel = ManagedChannelBuilder.forAddress(host, port)
32-
.usePlaintext(true)
32+
.usePlaintext()
3333
.build();
3434
walletBlockingStub = WalletGrpc.newBlockingStub(channel);
3535
}
3636

3737
public WalletGrpcClient(String host) {
3838
channel = ManagedChannelBuilder.forTarget(host)
39-
.usePlaintext(true)
39+
.usePlaintext()
4040
.build();
4141
walletBlockingStub = WalletGrpc.newBlockingStub(channel);
4242
}

framework/src/main/java/org/tron/core/capsule/utils/RLP.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public static long decodeLong(byte[] data, int index) {
204204
return value;
205205
}
206206

207-
private static String decodeStringItem(byte[] data, int index) {
207+
public static String decodeStringItem(byte[] data, int index) {
208208

209209
final byte[] valueBytes = decodeItemBytes(data, index);
210210

@@ -229,12 +229,12 @@ public static BigInteger decodeBigInteger(byte[] data, int index) {
229229
}
230230
}
231231

232-
private static byte[] decodeByteArray(byte[] data, int index) {
232+
public static byte[] decodeByteArray(byte[] data, int index) {
233233

234234
return decodeItemBytes(data, index);
235235
}
236236

237-
private static int nextItemLength(byte[] data, int index) {
237+
public static int nextItemLength(byte[] data, int index) {
238238

239239
if (index >= data.length) {
240240
return -1;

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.tron.core.db;
22

33
import static org.tron.common.utils.Commons.adjustBalance;
4+
import static org.tron.core.exception.BadBlockException.TypeEnum.CALC_MERKLE_ROOT_FAILED;
45
import static org.tron.protos.Protocol.Transaction.Contract.ContractType.TransferContract;
56
import static org.tron.protos.Protocol.Transaction.Result.contractResult.SUCCESS;
67

@@ -192,7 +193,8 @@ public class Manager {
192193
@Getter
193194
@Setter
194195
private boolean isSyncMode;
195-
196+
@Getter
197+
private Object forkLock = new Object();
196198
// map<Long, IncrementalMerkleTree>
197199
@Getter
198200
@Setter
@@ -1213,8 +1215,8 @@ public void pushBlock(final BlockCapsule block)
12131215
if (!block.calcMerkleRoot().equals(block.getMerkleRoot())) {
12141216
logger.warn("Num: {}, the merkle root doesn't match, expect is {} , actual is {}.",
12151217
block.getNum(), block.getMerkleRoot(), block.calcMerkleRoot());
1216-
throw new BadBlockException(String.format("The merkle hash is not validated for %d",
1217-
block.getNum()));
1218+
throw new BadBlockException(CALC_MERKLE_ROOT_FAILED,
1219+
String.format("The merkle hash is not validated for %d", block.getNum()));
12181220
}
12191221
consensus.receiveBlock(block);
12201222
}
@@ -1268,8 +1270,9 @@ public void pushBlock(final BlockCapsule block)
12681270
chainBaseManager.getDynamicPropertiesStore().getLatestBlockHeaderTimestamp(),
12691271
khaosDb.getHead(), khaosDb.getMiniStore().size(),
12701272
khaosDb.getMiniUnlinkedStore().size());
1271-
1272-
switchFork(newBlock);
1273+
synchronized (forkLock) {
1274+
switchFork(newBlock);
1275+
}
12731276
logger.info(SAVE_BLOCK, newBlock);
12741277

12751278
logger.warn(
@@ -1912,6 +1915,7 @@ public NullifierStore getNullifierStore() {
19121915
public void closeAllStore() {
19131916
logger.info("******** Begin to close db. ********");
19141917
chainBaseManager.closeAllStore();
1918+
validateSignService.shutdown();
19151919
logger.info("******** End to close db. ********");
19161920
}
19171921

0 commit comments

Comments
 (0)