diff --git a/framework/src/main/java/org/tron/core/services/event/BlockEventCache.java b/framework/src/main/java/org/tron/core/services/event/BlockEventCache.java index aac457ba29b..3548859262e 100644 --- a/framework/src/main/java/org/tron/core/services/event/BlockEventCache.java +++ b/framework/src/main/java/org/tron/core/services/event/BlockEventCache.java @@ -43,8 +43,8 @@ public static void init(BlockCapsule.BlockId blockId) { } public static void add(BlockEvent blockEvent) throws EventException { - logger.info("Add block event, {}, {}", blockEvent.getBlockId().getString(), - blockEvent.getParentId().getString()); + logger.info("Add block event, {}, {}, {}", blockEvent.getBlockId().getString(), + blockEvent.getParentId().getString(), blockEvent.getSolidId().getString()); if (blockEventMap.get(blockEvent.getParentId()) == null) { throw new EventException("unlink BlockEvent, " + blockEvent.getBlockId().getString() + ", " @@ -83,6 +83,7 @@ public static void remove(BlockCapsule.BlockId solidId) { } public static List getSolidBlockEvents(BlockCapsule.BlockId solidId) { + logger.info("Get solid events {}, {}", solidNum, solidId); List blockEvents = new ArrayList<>(); BlockCapsule.BlockId tmp = solidId; while (tmp.getNum() > solidNum) { diff --git a/framework/src/main/java/org/tron/core/services/event/SolidEventService.java b/framework/src/main/java/org/tron/core/services/event/SolidEventService.java index 6178b247b1d..e67a1618ce1 100644 --- a/framework/src/main/java/org/tron/core/services/event/SolidEventService.java +++ b/framework/src/main/java/org/tron/core/services/event/SolidEventService.java @@ -47,7 +47,14 @@ public void work() { return; } - List blockEvents = BlockEventCache.getSolidBlockEvents(solidId); + List blockEvents; + + try { + blockEvents = BlockEventCache.getSolidBlockEvents(solidId); + } catch (Exception e) { + logger.warn("Get solid events failed. {}", e.getMessage()); + return; + } blockEvents.forEach(v -> flush(v)); diff --git a/framework/src/test/java/org/tron/core/event/BlockEventCacheTest.java b/framework/src/test/java/org/tron/core/event/BlockEventCacheTest.java index a23c4b5c9c8..e99433db3c6 100644 --- a/framework/src/test/java/org/tron/core/event/BlockEventCacheTest.java +++ b/framework/src/test/java/org/tron/core/event/BlockEventCacheTest.java @@ -17,6 +17,7 @@ public void test() throws Exception { BlockCapsule.BlockId b1 = new BlockCapsule.BlockId(getBlockId(), 1); be1.setBlockId(b1); be1.setParentId(b1); + be1.setSolidId(b1); try { BlockEventCache.add(be1); Assert.fail(); diff --git a/framework/src/test/java/org/tron/core/event/SolidEventServiceTest.java b/framework/src/test/java/org/tron/core/event/SolidEventServiceTest.java index ef71a3d39a9..de0300e31d7 100644 --- a/framework/src/test/java/org/tron/core/event/SolidEventServiceTest.java +++ b/framework/src/test/java/org/tron/core/event/SolidEventServiceTest.java @@ -32,6 +32,15 @@ public class SolidEventServiceTest { @Test public void test() throws Exception { + BlockEvent be0 = new BlockEvent(); + BlockCapsule.BlockId b0 = new BlockCapsule.BlockId(BlockEventCacheTest.getBlockId(), 1); + be0.setBlockId(b0); + be0.setParentId(b0); + be0.setSolidId(new BlockCapsule.BlockId(BlockEventCacheTest.getBlockId(), 100)); + BlockEventCache.init(b0); + BlockEventCache.add(be0); + solidEventService.work(); + BlockEvent be1 = new BlockEvent(); BlockCapsule.BlockId b1 = new BlockCapsule.BlockId(BlockEventCacheTest.getBlockId(), 1); be1.setBlockId(b1);