|
2 | 2 |
|
3 | 3 | import static org.tron.core.witness.BlockProductionCondition.NOT_MY_TURN; |
4 | 4 |
|
| 5 | +import com.google.common.cache.Cache; |
| 6 | +import com.google.common.cache.CacheBuilder; |
5 | 7 | import com.google.common.collect.Maps; |
6 | 8 | import com.google.protobuf.ByteString; |
7 | 9 | import java.util.Arrays; |
8 | 10 | import java.util.Map; |
9 | 11 | import java.util.Random; |
| 12 | +import java.util.concurrent.TimeUnit; |
10 | 13 | import java.util.concurrent.atomic.AtomicInteger; |
11 | 14 | import java.util.concurrent.atomic.AtomicLong; |
12 | 15 | import lombok.Getter; |
|
36 | 39 | import org.tron.core.exception.ValidateSignatureException; |
37 | 40 | import org.tron.core.net.TronNetService; |
38 | 41 | import org.tron.core.net.message.BlockMessage; |
| 42 | +import org.tron.core.net.peer.Item; |
39 | 43 | import org.tron.core.witness.BlockProductionCondition; |
40 | 44 | import org.tron.core.witness.WitnessController; |
41 | 45 |
|
@@ -77,6 +81,7 @@ public class WitnessService implements Service { |
77 | 81 | private AtomicLong dupBlockTime = new AtomicLong(0); |
78 | 82 | private long blockCycle = |
79 | 83 | ChainConstant.BLOCK_PRODUCED_INTERVAL * ChainConstant.MAX_ACTIVE_WITNESS_NUM; |
| 84 | + private Cache<ByteString, Long> blocks = CacheBuilder.newBuilder().maximumSize(10).build(); |
80 | 85 |
|
81 | 86 | /** |
82 | 87 | * Construction method. |
@@ -338,6 +343,11 @@ private boolean dupWitnessCheck() { |
338 | 343 |
|
339 | 344 | public void checkDupWitness(BlockCapsule block) { |
340 | 345 | if (block.generatedByMyself) { |
| 346 | + blocks.put(block.getBlockId().getByteString(), System.currentTimeMillis()); |
| 347 | + return; |
| 348 | + } |
| 349 | + |
| 350 | + if (blocks.getIfPresent(block.getBlockId().getByteString()) != null) { |
341 | 351 | return; |
342 | 352 | } |
343 | 353 |
|
|
0 commit comments