From 9a8e387217c6f006826d06c36bae18ae6998fec3 Mon Sep 17 00:00:00 2001 From: Grigorov-Georgi Date: Fri, 3 Jan 2025 13:23:49 +0200 Subject: [PATCH] chore: refactor --- .../exception/grandpa/GhostExecutionException.java | 7 +++++++ .../exception/grandpa/GrandpaGenericException.java | 7 +++++++ src/main/java/com/limechain/grandpa/GrandpaService.java | 7 ++++--- .../java/com/limechain/grandpa/GrandpaServiceTest.java | 4 ++-- 4 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/limechain/exception/grandpa/GhostExecutionException.java create mode 100644 src/main/java/com/limechain/exception/grandpa/GrandpaGenericException.java diff --git a/src/main/java/com/limechain/exception/grandpa/GhostExecutionException.java b/src/main/java/com/limechain/exception/grandpa/GhostExecutionException.java new file mode 100644 index 00000000..087ac158 --- /dev/null +++ b/src/main/java/com/limechain/exception/grandpa/GhostExecutionException.java @@ -0,0 +1,7 @@ +package com.limechain.exception.grandpa; + +public class GhostExecutionException extends GrandpaGenericException { + public GhostExecutionException(String message) { + super(message); + } +} diff --git a/src/main/java/com/limechain/exception/grandpa/GrandpaGenericException.java b/src/main/java/com/limechain/exception/grandpa/GrandpaGenericException.java new file mode 100644 index 00000000..7d4f33f2 --- /dev/null +++ b/src/main/java/com/limechain/exception/grandpa/GrandpaGenericException.java @@ -0,0 +1,7 @@ +package com.limechain.exception.grandpa; + +public class GrandpaGenericException extends RuntimeException { + public GrandpaGenericException(String message) { + super(message); + } +} diff --git a/src/main/java/com/limechain/grandpa/GrandpaService.java b/src/main/java/com/limechain/grandpa/GrandpaService.java index 55b33d80..e923bb25 100644 --- a/src/main/java/com/limechain/grandpa/GrandpaService.java +++ b/src/main/java/com/limechain/grandpa/GrandpaService.java @@ -1,6 +1,6 @@ package com.limechain.grandpa; -import com.limechain.exception.global.ExecutionFailedException; +import com.limechain.exception.grandpa.GhostExecutionException; import com.limechain.exception.storage.BlockStorageGenericException; import com.limechain.grandpa.state.GrandpaState; import com.limechain.network.protocol.grandpa.messages.commit.Vote; @@ -21,6 +21,7 @@ @Log @Component public class GrandpaService { + private final GrandpaState grandpaState; private final BlockState blockState; @@ -36,13 +37,13 @@ public GrandpaService(GrandpaState grandpaState, BlockState blockState) { * * @return GRANDPA GHOST block as a vote */ - public Vote getGrandpaGHOST() { + public Vote getGrandpaGhost() { var threshold = grandpaState.getThreshold(); Map blocks = getPossibleSelectedBlocks(threshold, Subround.PREVOTE); if (blocks.isEmpty() || threshold.equals(BigInteger.ZERO)) { - throw new ExecutionFailedException("GHOST not found"); + throw new GhostExecutionException("GHOST not found"); } return selectBlockWithMostVotes(blocks); diff --git a/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java b/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java index 1686c4f1..11716c81 100644 --- a/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java +++ b/src/test/java/com/limechain/grandpa/GrandpaServiceTest.java @@ -55,7 +55,7 @@ void setUp() { void testGetGrandpaGHOSTWhereNoBlocksPassThreshold() { when(grandpaState.getThreshold()).thenReturn(BigInteger.valueOf(10)); when(grandpaState.getPrevotes()).thenReturn(Map.of()); - assertThrows(ExecutionFailedException.class, () -> grandpaService.getGrandpaGHOST()); + assertThrows(ExecutionFailedException.class, () -> grandpaService.getGrandpaGhost()); } @Test @@ -77,7 +77,7 @@ void testGetGrandpaGHOSTWithBlockPassingThreshold() { when(blockState.isDescendantOf(firstVote.getBlockHash(), firstVote.getBlockHash())).thenReturn(true); when(blockState.isDescendantOf(secondVote.getBlockHash(), secondVote.getBlockHash())).thenReturn(true); - Vote result = grandpaService.getGrandpaGHOST(); + Vote result = grandpaService.getGrandpaGhost(); assertNotNull(result); assertEquals(firstVote.getBlockHash(), result.getBlockHash()); }