Skip to content

Commit 38815ff

Browse files
committed
fix the sonar error
1 parent e26ac23 commit 38815ff

3 files changed

Lines changed: 18 additions & 22 deletions

File tree

framework/src/main/java/org/tron/core/net/message/PbftCommitMessage.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ public Class<?> getAnswerMessage() {
3232
return null;
3333
}
3434

35-
@Override
36-
public boolean equals(Object obj) {
37-
return super.equals(obj);
38-
}
39-
4035
@Override
4136
public int hashCode() {
4237
return super.hashCode();

framework/src/main/java/org/tron/core/net/messagehandler/FetchInvDataMsgHandler.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import static org.tron.core.config.Parameter.ChainConstant.BLOCK_PRODUCED_INTERVAL;
44

5+
import com.google.common.cache.Cache;
6+
import com.google.common.cache.CacheBuilder;
57
import com.google.common.collect.Lists;
68
import java.util.List;
9+
import java.util.concurrent.TimeUnit;
710
import lombok.extern.slf4j.Slf4j;
811
import org.springframework.beans.factory.annotation.Autowired;
912
import org.springframework.stereotype.Component;
@@ -38,7 +41,8 @@
3841
@Component
3942
public class FetchInvDataMsgHandler implements TronMsgHandler {
4043

41-
private static long latestEpoch = 0;
44+
private volatile Cache<Long, Boolean> epochCache = CacheBuilder.newBuilder().initialCapacity(100)
45+
.maximumSize(1000).expireAfterWrite(1, TimeUnit.HOURS).build();
4246

4347
private static final int MAX_SIZE = 1_000_000;
4448
@Autowired
@@ -116,8 +120,8 @@ private void sendPbftCommitMessage(PeerConnection peer, BlockCapsule blockCapsul
116120
epoch =
117121
(blockCapsule.getTimeStamp() / maintenanceTimeInterval + 1) * maintenanceTimeInterval;
118122
}
119-
if (epoch > latestEpoch) {
120-
latestEpoch = epoch;
123+
if (epochCache.getIfPresent(epoch) == null) {
124+
epochCache.put(epoch, true);
121125
PbftSignCapsule srl = tronNetDelegate.getSRLPbftCommitData(epoch);
122126
if (srl != null) {
123127
peer.sendMessage(new PbftCommitMessage(srl));

framework/src/main/java/org/tron/core/net/messagehandler/PbftDataSyncHandler.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,12 @@ private void processPBFTCommitMessage(PbftCommitMessage pbftCommitMessage) {
9090
chainBaseManager.getWitnesses())) {
9191
return;
9292
}
93-
if (raw.getDataType() == DataType.BLOCK) {
94-
if (pbftSignDataStore.getBlockSignData(raw.getViewN()) == null) {
95-
pbftSignDataStore
96-
.putBlockSignData(raw.getViewN(), pbftCommitMessage.getPbftSignCapsule());
97-
}
98-
} else if (raw.getDataType() == DataType.SRL) {
99-
if (pbftSignDataStore.getSrSignData(raw.getEpoch()) == null) {
100-
pbftSignDataStore.putSrSignData(raw.getEpoch(), pbftCommitMessage.getPbftSignCapsule());
101-
}
93+
if (raw.getDataType() == DataType.BLOCK
94+
&& pbftSignDataStore.getBlockSignData(raw.getViewN()) == null) {
95+
pbftSignDataStore.putBlockSignData(raw.getViewN(), pbftCommitMessage.getPbftSignCapsule());
96+
} else if (raw.getDataType() == DataType.SRL
97+
&& pbftSignDataStore.getSrSignData(raw.getEpoch()) == null) {
98+
pbftSignDataStore.putSrSignData(raw.getEpoch(), pbftCommitMessage.getPbftSignCapsule());
10299
}
103100
} catch (InvalidProtocolBufferException e) {
104101
logger.error("", e);
@@ -141,11 +138,11 @@ public boolean validPbftSign(Raw raw, List<ByteString> srSignList,
141138

142139
private class ValidPbftSignTask implements Callable<Boolean> {
143140

144-
long viewN;
145-
Set<ByteString> srSignSet;
146-
byte[] dataHash;
147-
Set<ByteString> srSet;
148-
ByteString sign;
141+
private long viewN;
142+
private Set<ByteString> srSignSet;
143+
private byte[] dataHash;
144+
private Set<ByteString> srSet;
145+
private ByteString sign;
149146

150147
ValidPbftSignTask(long viewN, Set<ByteString> srSignSet,
151148
byte[] dataHash, Set<ByteString> srSet, ByteString sign) {

0 commit comments

Comments
 (0)