Skip to content

Commit

Permalink
fix the sonar error
Browse files Browse the repository at this point in the history
  • Loading branch information
lvs007 committed Jul 24, 2020
1 parent e26ac23 commit 38815ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ public Class<?> getAnswerMessage() {
return null;
}

@Override
public boolean equals(Object obj) {
return super.equals(obj);
}

@Override
public int hashCode() {
return super.hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

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

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -38,7 +41,8 @@
@Component
public class FetchInvDataMsgHandler implements TronMsgHandler {

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

private static final int MAX_SIZE = 1_000_000;
@Autowired
Expand Down Expand Up @@ -116,8 +120,8 @@ private void sendPbftCommitMessage(PeerConnection peer, BlockCapsule blockCapsul
epoch =
(blockCapsule.getTimeStamp() / maintenanceTimeInterval + 1) * maintenanceTimeInterval;
}
if (epoch > latestEpoch) {
latestEpoch = epoch;
if (epochCache.getIfPresent(epoch) == null) {
epochCache.put(epoch, true);
PbftSignCapsule srl = tronNetDelegate.getSRLPbftCommitData(epoch);
if (srl != null) {
peer.sendMessage(new PbftCommitMessage(srl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,12 @@ private void processPBFTCommitMessage(PbftCommitMessage pbftCommitMessage) {
chainBaseManager.getWitnesses())) {
return;
}
if (raw.getDataType() == DataType.BLOCK) {
if (pbftSignDataStore.getBlockSignData(raw.getViewN()) == null) {
pbftSignDataStore
.putBlockSignData(raw.getViewN(), pbftCommitMessage.getPbftSignCapsule());
}
} else if (raw.getDataType() == DataType.SRL) {
if (pbftSignDataStore.getSrSignData(raw.getEpoch()) == null) {
pbftSignDataStore.putSrSignData(raw.getEpoch(), pbftCommitMessage.getPbftSignCapsule());
}
if (raw.getDataType() == DataType.BLOCK
&& pbftSignDataStore.getBlockSignData(raw.getViewN()) == null) {
pbftSignDataStore.putBlockSignData(raw.getViewN(), pbftCommitMessage.getPbftSignCapsule());
} else if (raw.getDataType() == DataType.SRL
&& pbftSignDataStore.getSrSignData(raw.getEpoch()) == null) {
pbftSignDataStore.putSrSignData(raw.getEpoch(), pbftCommitMessage.getPbftSignCapsule());
}
} catch (InvalidProtocolBufferException e) {
logger.error("", e);
Expand Down Expand Up @@ -141,11 +138,11 @@ public boolean validPbftSign(Raw raw, List<ByteString> srSignList,

private class ValidPbftSignTask implements Callable<Boolean> {

long viewN;
Set<ByteString> srSignSet;
byte[] dataHash;
Set<ByteString> srSet;
ByteString sign;
private long viewN;
private Set<ByteString> srSignSet;
private byte[] dataHash;
private Set<ByteString> srSet;
private ByteString sign;

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

0 comments on commit 38815ff

Please sign in to comment.