Skip to content

Commit 788136e

Browse files
authored
Merge pull request #5665 from tronprotocol/release_4.7.3.1
merge release_4.7.3.1
2 parents 440d062 + 259fa85 commit 788136e

File tree

9 files changed

+66
-43
lines changed

9 files changed

+66
-43
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ public class BlockCapsule implements ProtoCapsule<Block> {
5656

5757
private Block block;
5858
private List<TransactionCapsule> transactions = new ArrayList<>();
59-
private StringBuilder toStringBuff = new StringBuilder();
6059
private boolean isSwitch;
6160
@Getter
6261
@Setter
@@ -314,7 +313,7 @@ public boolean hasWitnessSignature() {
314313

315314
@Override
316315
public String toString() {
317-
toStringBuff.setLength(0);
316+
StringBuilder toStringBuff = new StringBuilder();
318317

319318
toStringBuff.append("BlockCapsule \n[ ");
320319
toStringBuff.append("hash=").append(getBlockId()).append("\n");

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

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,17 @@
1111
import org.springframework.beans.factory.annotation.Autowired;
1212
import org.springframework.beans.factory.annotation.Value;
1313
import org.springframework.stereotype.Component;
14-
import org.tron.common.cache.CacheManager;
15-
import org.tron.common.cache.CacheStrategies;
16-
import org.tron.common.cache.CacheType;
17-
import org.tron.common.cache.TronCache;
1814
import org.tron.core.capsule.WitnessCapsule;
1915
import org.tron.core.config.Parameter;
2016
import org.tron.core.db.TronStoreWithRevoking;
2117

2218
@Slf4j(topic = "DB")
2319
@Component
2420
public class WitnessStore extends TronStoreWithRevoking<WitnessCapsule> {
25-
// cache for 127 SR
26-
private final TronCache<Integer, List<WitnessCapsule>> witnessStandbyCache;
2721

2822
@Autowired
2923
protected WitnessStore(@Value("witness") String dbName) {
3024
super(dbName);
31-
String strategy = String.format(CacheStrategies.PATTERNS, 1, 1, "30s", 1);
32-
witnessStandbyCache = CacheManager.allocate(CacheType.witnessStandby, strategy);
3325
}
3426

3527
/**
@@ -48,19 +40,8 @@ public WitnessCapsule get(byte[] key) {
4840
}
4941

5042
public List<WitnessCapsule> getWitnessStandby() {
51-
List<WitnessCapsule> list =
52-
witnessStandbyCache.getIfPresent(Parameter.ChainConstant.WITNESS_STANDBY_LENGTH);
53-
if (list != null) {
54-
return list;
55-
}
56-
return updateWitnessStandby(null);
57-
}
58-
59-
public List<WitnessCapsule> updateWitnessStandby(List<WitnessCapsule> all) {
6043
List<WitnessCapsule> ret;
61-
if (all == null) {
62-
all = getAllWitnesses();
63-
}
44+
List<WitnessCapsule> all = getAllWitnesses();
6445
all.sort(Comparator.comparingLong(WitnessCapsule::getVoteCount)
6546
.reversed().thenComparing(Comparator.comparingInt(
6647
(WitnessCapsule w) -> w.getAddress().hashCode()).reversed()));
@@ -71,7 +52,6 @@ public List<WitnessCapsule> updateWitnessStandby(List<WitnessCapsule> all) {
7152
}
7253
// trim voteCount = 0
7354
ret.removeIf(w -> w.getVoteCount() < 1);
74-
witnessStandbyCache.put(Parameter.ChainConstant.WITNESS_STANDBY_LENGTH, ret);
7555
return ret;
7656
}
7757

consensus/src/main/java/org/tron/consensus/ConsensusDelegate.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ public List<WitnessCapsule> getAllWitnesses() {
108108
return witnessStore.getAllWitnesses();
109109
}
110110

111-
public List<WitnessCapsule> updateWitnessStandby(List<WitnessCapsule> all) {
112-
return witnessStore.updateWitnessStandby(all);
113-
}
114-
115111
public void saveStateFlag(int flag) {
116112
dynamicPropertiesStore.saveStateFlag(flag);
117113
}

consensus/src/main/java/org/tron/consensus/dpos/MaintenanceManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,11 @@ public void doMaintenance() {
151151
if (dynamicPropertiesStore.allowChangeDelegation()) {
152152
long nextCycle = dynamicPropertiesStore.getCurrentCycleNumber() + 1;
153153
dynamicPropertiesStore.saveCurrentCycleNumber(nextCycle);
154-
List<WitnessCapsule> all = consensusDelegate.getAllWitnesses();
155-
all.forEach(witness -> {
154+
consensusDelegate.getAllWitnesses().forEach(witness -> {
156155
delegationStore.setBrokerage(nextCycle, witness.createDbKey(),
157156
delegationStore.getBrokerage(witness.createDbKey()));
158157
delegationStore.setWitnessVote(nextCycle, witness.createDbKey(), witness.getVoteCount());
159158
});
160-
consensusDelegate.updateWitnessStandby(all);
161159
}
162160
}
163161

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.tron.common.cache;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class CacheManagerTest {
7+
8+
@Test
9+
public void allocate() {
10+
String strategy = String.format(CacheStrategies.PATTERNS, 1, 1, "30s", 1);
11+
TronCache<String, String> cache = CacheManager.allocate(CacheType.witnessStandby, strategy);
12+
Assert.assertNull(cache.getIfPresent("test"));
13+
}
14+
}

framework/src/main/java/org/tron/program/Version.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public class Version {
44

55
public static final String VERSION_NAME = "GreatVoyage-v4.7.2-140-g9d13f9cb69";
66
public static final String VERSION_CODE = "18173";
7-
private static final String VERSION = "4.7.3";
7+
private static final String VERSION = "4.7.3.1";
88

99
public static String getVersion() {
1010
return VERSION;

framework/src/test/java/org/tron/core/capsule/BlockCapsuleTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.google.protobuf.ByteString;
44
import java.io.IOException;
5+
import java.util.ArrayList;
56
import java.util.Arrays;
7+
import java.util.List;
68
import lombok.extern.slf4j.Slf4j;
79
import org.junit.AfterClass;
810
import org.junit.Assert;
@@ -146,4 +148,20 @@ public void testGetTimeStamp() {
146148
Assert.assertEquals(1234L, blockCapsule0.getTimeStamp());
147149
}
148150

151+
@Test
152+
public void testConcurrentToString() throws InterruptedException {
153+
List<Thread> threadList = new ArrayList<>();
154+
int n = 10;
155+
for (int i = 0; i < n; i++) {
156+
threadList.add(new Thread(() -> blockCapsule0.toString()));
157+
}
158+
for (int i = 0; i < n; i++) {
159+
threadList.get(i).start();
160+
}
161+
for (int i = 0; i < n; i++) {
162+
threadList.get(i).join();
163+
}
164+
Assert.assertTrue(true);
165+
}
166+
149167
}

framework/src/test/java/org/tron/core/db/ManagerTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,14 +581,24 @@ public void pushSwitchFork()
581581
AccountResourceInsufficientException, EventBloomException {
582582

583583
String key = "f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62";
584+
String key2 = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4";
584585
byte[] privateKey = ByteArray.fromHexString(key);
585586
final ECKey ecKey = ECKey.fromPrivate(privateKey);
586587
byte[] address = ecKey.getAddress();
587-
588+
WitnessCapsule sr1 = new WitnessCapsule(
589+
ByteString.copyFrom(address), "www.tron.net/first");
590+
sr1.setVoteCount(1000000000L);
591+
byte[] privateKey2 = ByteArray.fromHexString(key2);
592+
final ECKey ecKey2 = ECKey.fromPrivate(privateKey2);
593+
byte[] address2 = ecKey2.getAddress();
594+
WitnessCapsule sr2 = new WitnessCapsule(
595+
ByteString.copyFrom(address2), "www.tron.net/second");
596+
sr2.setVoteCount(100000L);
597+
chainManager.getWitnessStore().put(address, sr1);
588598
WitnessCapsule witnessCapsule = new WitnessCapsule(ByteString.copyFrom(address));
589599
chainManager.getWitnessScheduleStore().saveActiveWitnesses(new ArrayList<>());
590600
chainManager.addWitness(ByteString.copyFrom(address));
591-
601+
List<WitnessCapsule> witnessStandby1 = chainManager.getWitnessStore().getWitnessStandby();
592602
Block block = getSignedBlock(witnessCapsule.getAddress(), 1533529947843L, privateKey);
593603
dbManager.pushBlock(new BlockCapsule(block));
594604

@@ -625,6 +635,9 @@ public void pushSwitchFork()
625635
} catch (Exception e) {
626636
Assert.assertTrue(e instanceof Exception);
627637
}
638+
chainManager.getWitnessStore().put(address, sr2);
639+
List<WitnessCapsule> witnessStandby2 = chainManager.getWitnessStore().getWitnessStandby();
640+
Assert.assertNotEquals(witnessStandby1, witnessStandby2);
628641
}
629642

630643

plugins/src/main/java/org/tron/plugins/DbLite.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,7 @@ private void generateInfoProperties(String propertyfile, long num)
355355
private long getLatestBlockHeaderNum(String databaseDir) throws IOException, RocksDBException {
356356
// query latest_block_header_number from checkpoint first
357357
final String latestBlockHeaderNumber = "latest_block_header_number";
358-
List<String> cpList = getCheckpointV2List(databaseDir);
359-
DBInterface checkpointDb;
360-
if (cpList.size() > 0) {
361-
String lastestCp = cpList.get(cpList.size() - 1);
362-
checkpointDb = DbTool.getDB(
363-
databaseDir + "/" + DBUtils.CHECKPOINT_DB_V2, lastestCp);
364-
} else {
365-
checkpointDb = DbTool.getDB(databaseDir, CHECKPOINT_DB);
366-
}
358+
DBInterface checkpointDb = getCheckpointDb(databaseDir);
367359
Long blockNumber = getLatestBlockHeaderNumFromCP(checkpointDb,
368360
latestBlockHeaderNumber.getBytes());
369361
if (blockNumber != null) {
@@ -594,7 +586,7 @@ private void mergeBak2Database(String liteDir, BlockNumInfo blockNumInfo) throws
594586
private byte[] getDataFromSourceDB(String sourceDir, String dbName, byte[] key)
595587
throws IOException, RocksDBException {
596588
DBInterface sourceDb = DbTool.getDB(sourceDir, dbName);
597-
DBInterface checkpointDb = DbTool.getDB(sourceDir, CHECKPOINT_DB);
589+
DBInterface checkpointDb = getCheckpointDb(sourceDir);
598590
// get data from tmp first.
599591
byte[] valueFromTmp = checkpointDb.get(Bytes.concat(simpleEncode(dbName), key));
600592
byte[] value;
@@ -672,6 +664,19 @@ private long getSecondBlock(String databaseDir) throws RocksDBException, IOExcep
672664
return num;
673665
}
674666

667+
private DBInterface getCheckpointDb(String sourceDir) throws IOException, RocksDBException {
668+
List<String> cpList = getCheckpointV2List(sourceDir);
669+
DBInterface checkpointDb;
670+
if (cpList.size() > 0) {
671+
String latestCp = cpList.get(cpList.size() - 1);
672+
checkpointDb = DbTool.getDB(
673+
sourceDir + "/" + DBUtils.CHECKPOINT_DB_V2, latestCp);
674+
} else {
675+
checkpointDb = DbTool.getDB(sourceDir, CHECKPOINT_DB);
676+
}
677+
return checkpointDb;
678+
}
679+
675680
@VisibleForTesting
676681
public static void setRecentBlks(long recentBlks) {
677682
RECENT_BLKS = recentBlks;

0 commit comments

Comments
 (0)