Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public BlockId getKhaosDbHeadBlockId() {
return chainBaseManager.getKhaosDbHead().getBlockId();
}

public long getSolidifiedBlockNum() {
return chainBaseManager.getDynamicPropertiesStore().getLatestSolidifiedBlockNum();
}

public BlockId getSolidBlockId() {
return chainBaseManager.getSolidBlockId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,16 @@ public boolean addInv(Item item) {
if (item.getType().equals(InventoryType.TRX) && trxCache.getIfPresent(item) != null) {
return false;
}
if (item.getType().equals(InventoryType.BLOCK) && blockCache.getIfPresent(item) != null) {
return false;

if (item.getType().equals(InventoryType.BLOCK)) {
if (blockCache.getIfPresent(item) != null) {
return false;
}

long solidNum = tronNetDelegate.getSolidifiedBlockNum();
if (new BlockId(item.getHash()).getNum() <= solidNum) {
return false;
}
}

synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,17 @@ private void testAddInv() {

Item itemBlock = new Item(Sha256Hash.ZERO_HASH, InventoryType.BLOCK);
flag = service.addInv(itemBlock);
Assert.assertFalse(flag);

BlockCapsule.BlockId blockId = new BlockCapsule.BlockId(Sha256Hash.ZERO_HASH, 1000L);
itemBlock = new Item(blockId, InventoryType.BLOCK);
flag = service.addInv(itemBlock);
Assert.assertTrue(flag);
flag = service.addInv(itemBlock);
Assert.assertFalse(flag);

blockId = new BlockCapsule.BlockId(Sha256Hash.ZERO_HASH, 10000L);
itemBlock = new Item(blockId, InventoryType.BLOCK);
service.addInvToCache(itemBlock);
flag = service.addInv(itemBlock);
Assert.assertFalse(flag);
Expand Down
Loading