File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed
main/java/org/tron/core/net
test/java/org/tron/core/net/services Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,10 @@ public BlockId getKhaosDbHeadBlockId() {
156156 return chainBaseManager .getKhaosDbHead ().getBlockId ();
157157 }
158158
159+ public long getSolidifiedBlockNum () {
160+ return chainBaseManager .getDynamicPropertiesStore ().getLatestSolidifiedBlockNum ();
161+ }
162+
159163 public BlockId getSolidBlockId () {
160164 return chainBaseManager .getSolidBlockId ();
161165 }
Original file line number Diff line number Diff line change @@ -121,8 +121,16 @@ public boolean addInv(Item item) {
121121 if (item .getType ().equals (InventoryType .TRX ) && trxCache .getIfPresent (item ) != null ) {
122122 return false ;
123123 }
124- if (item .getType ().equals (InventoryType .BLOCK ) && blockCache .getIfPresent (item ) != null ) {
125- return false ;
124+
125+ if (item .getType ().equals (InventoryType .BLOCK )) {
126+ if (blockCache .getIfPresent (item ) != null ) {
127+ return false ;
128+ }
129+
130+ long solidNum = tronNetDelegate .getSolidifiedBlockNum ();
131+ if (new BlockId (item .getHash ()).getNum () <= solidNum ) {
132+ return false ;
133+ }
126134 }
127135
128136 synchronized (this ) {
Original file line number Diff line number Diff line change @@ -74,10 +74,17 @@ private void testAddInv() {
7474
7575 Item itemBlock = new Item (Sha256Hash .ZERO_HASH , InventoryType .BLOCK );
7676 flag = service .addInv (itemBlock );
77+ Assert .assertFalse (flag );
78+
79+ BlockCapsule .BlockId blockId = new BlockCapsule .BlockId (Sha256Hash .ZERO_HASH , 1000L );
80+ itemBlock = new Item (blockId , InventoryType .BLOCK );
81+ flag = service .addInv (itemBlock );
7782 Assert .assertTrue (flag );
7883 flag = service .addInv (itemBlock );
7984 Assert .assertFalse (flag );
8085
86+ blockId = new BlockCapsule .BlockId (Sha256Hash .ZERO_HASH , 10000L );
87+ itemBlock = new Item (blockId , InventoryType .BLOCK );
8188 service .addInvToCache (itemBlock );
8289 flag = service .addInv (itemBlock );
8390 Assert .assertFalse (flag );
You can’t perform that action at this time.
0 commit comments