Skip to content

Commit 9a70395

Browse files
Merge pull request #6223 from zeusoo001/log-opt-1
feat(event): optimize event service log
2 parents f9a4544 + a75e41d commit 9a70395

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

framework/src/main/java/org/tron/core/services/event/BlockEventCache.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public static void init(BlockCapsule.BlockId blockId) {
4343
}
4444

4545
public static void add(BlockEvent blockEvent) throws EventException {
46-
logger.info("Add block event, {}, {}", blockEvent.getBlockId().getString(),
47-
blockEvent.getParentId().getString());
46+
logger.info("Add block event, {}, {}, {}", blockEvent.getBlockId().getString(),
47+
blockEvent.getParentId().getString(), blockEvent.getSolidId().getString());
4848
if (blockEventMap.get(blockEvent.getParentId()) == null) {
4949
throw new EventException("unlink BlockEvent, "
5050
+ blockEvent.getBlockId().getString() + ", "
@@ -83,6 +83,7 @@ public static void remove(BlockCapsule.BlockId solidId) {
8383
}
8484

8585
public static List<BlockEvent> getSolidBlockEvents(BlockCapsule.BlockId solidId) {
86+
logger.info("Get solid events {}, {}", solidNum, solidId);
8687
List<BlockEvent> blockEvents = new ArrayList<>();
8788
BlockCapsule.BlockId tmp = solidId;
8889
while (tmp.getNum() > solidNum) {

framework/src/main/java/org/tron/core/services/event/SolidEventService.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ public void work() {
4747
return;
4848
}
4949

50-
List<BlockEvent> blockEvents = BlockEventCache.getSolidBlockEvents(solidId);
50+
List<BlockEvent> blockEvents;
51+
52+
try {
53+
blockEvents = BlockEventCache.getSolidBlockEvents(solidId);
54+
} catch (Exception e) {
55+
logger.warn("Get solid events failed. {}", e.getMessage());
56+
return;
57+
}
5158

5259
blockEvents.forEach(v -> flush(v));
5360

framework/src/test/java/org/tron/core/event/BlockEventCacheTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public void test() throws Exception {
1717
BlockCapsule.BlockId b1 = new BlockCapsule.BlockId(getBlockId(), 1);
1818
be1.setBlockId(b1);
1919
be1.setParentId(b1);
20+
be1.setSolidId(b1);
2021
try {
2122
BlockEventCache.add(be1);
2223
Assert.fail();

framework/src/test/java/org/tron/core/event/SolidEventServiceTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ public class SolidEventServiceTest {
3232

3333
@Test
3434
public void test() throws Exception {
35+
BlockEvent be0 = new BlockEvent();
36+
BlockCapsule.BlockId b0 = new BlockCapsule.BlockId(BlockEventCacheTest.getBlockId(), 1);
37+
be0.setBlockId(b0);
38+
be0.setParentId(b0);
39+
be0.setSolidId(new BlockCapsule.BlockId(BlockEventCacheTest.getBlockId(), 100));
40+
BlockEventCache.init(b0);
41+
BlockEventCache.add(be0);
42+
solidEventService.work();
43+
3544
BlockEvent be1 = new BlockEvent();
3645
BlockCapsule.BlockId b1 = new BlockCapsule.BlockId(BlockEventCacheTest.getBlockId(), 1);
3746
be1.setBlockId(b1);

0 commit comments

Comments
 (0)