From 5b047d10a24a43dd23af040dc55d8ffc1692a024 Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Fri, 27 Sep 2024 13:52:42 +0300 Subject: [PATCH 1/3] build: allow plus symbol in branch names --- .github/workflows/rit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rit.yml b/.github/workflows/rit.yml index e772cc51..a1427429 100644 --- a/.github/workflows/rit.yml +++ b/.github/workflows/rit.yml @@ -37,7 +37,7 @@ jobs: run: | PR_DESCRIPTION=pr-description.txt - ALLOWED_BRANCH_CHARACTERS='[-./0-9A-Z_a-z]' + ALLOWED_BRANCH_CHARACTERS='[-+./0-9A-Z_a-z]' default_rskj_branch=master default_powpeg_branch=master From 1029abc91f7aae6a2e382a259ce17de4713cfe1d Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Wed, 4 Oct 2023 14:43:13 +0300 Subject: [PATCH 2/3] Used 'compressed' header encoding for hsm messages' payload --- .../java/co/rsk/federate/signing/hsm/message/ParsedHeader.java | 2 +- .../signing/hsm/message/UpdateAncestorBlockMessage.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/co/rsk/federate/signing/hsm/message/ParsedHeader.java b/src/main/java/co/rsk/federate/signing/hsm/message/ParsedHeader.java index 32f4ea01..7e0e2089 100644 --- a/src/main/java/co/rsk/federate/signing/hsm/message/ParsedHeader.java +++ b/src/main/java/co/rsk/federate/signing/hsm/message/ParsedHeader.java @@ -27,7 +27,7 @@ public String[] getBrothers() { } private String serializeBlockHeader(BlockHeader blockHeader) { - return Hex.toHexString(blockHeader.getFullEncoded()); + return Hex.toHexString(blockHeader.getEncoded(true, true, true)); } private String[] serializeBrothers(List brothers) { diff --git a/src/main/java/co/rsk/federate/signing/hsm/message/UpdateAncestorBlockMessage.java b/src/main/java/co/rsk/federate/signing/hsm/message/UpdateAncestorBlockMessage.java index 87bb439e..305338e3 100644 --- a/src/main/java/co/rsk/federate/signing/hsm/message/UpdateAncestorBlockMessage.java +++ b/src/main/java/co/rsk/federate/signing/hsm/message/UpdateAncestorBlockMessage.java @@ -17,7 +17,7 @@ public UpdateAncestorBlockMessage(List blockHeaders) { } private String parseBlockHeader(BlockHeader blockHeader) { - return Hex.toHexString(blockHeader.getEncoded(true, false)); + return Hex.toHexString(blockHeader.getEncoded(true, false, true)); } public List getData() { From 28629f7b7ec3ae2e1720db683a6636538f7164a6 Mon Sep 17 00:00:00 2001 From: Volodymyr Kravets Date: Wed, 4 Oct 2023 15:08:20 +0300 Subject: [PATCH 3/3] Fixed tests --- .../HsmBookkeepingClientImplTest.java | 8 ++++---- .../hsm/message/AdvanceBlockchainMessageTest.java | 12 ++++++------ .../signing/hsm/message/ParsedHeaderTest.java | 4 ++-- .../hsm/requirements/AncestorBlockUpdaterTest.java | 4 ++-- .../co/rsk/federate/signing/utils/TestUtils.java | 5 +---- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/test/java/co/rsk/federate/signing/hsm/advanceblockchain/HsmBookkeepingClientImplTest.java b/src/test/java/co/rsk/federate/signing/hsm/advanceblockchain/HsmBookkeepingClientImplTest.java index a8a56fc6..d491f260 100644 --- a/src/test/java/co/rsk/federate/signing/hsm/advanceblockchain/HsmBookkeepingClientImplTest.java +++ b/src/test/java/co/rsk/federate/signing/hsm/advanceblockchain/HsmBookkeepingClientImplTest.java @@ -293,14 +293,14 @@ void updateAncestorBlock_ok(HSMVersion hsmVersion, int maxChunkSize) throws HSMC for (int j = 0; j < blocksInRequest.size() - 1; j++) { assertEquals( - Hex.toHexString(Objects.requireNonNull(blockHeadersInOriginalOrder.poll()).getFullEncoded()), + Hex.toHexString(Objects.requireNonNull(blockHeadersInOriginalOrder.poll()).getEncoded(true, false, true)), blocksInRequest.get(j).asText() ); } // The last element asserted should not be removed from the queue since it will be the first element in the next chunk assertEquals( - Hex.toHexString(Objects.requireNonNull(blockHeadersInOriginalOrder.peek()).getFullEncoded()), + Hex.toHexString(Objects.requireNonNull(blockHeadersInOriginalOrder.peek()).getEncoded(true, false, true)), blocksInRequest.get(blocksInRequest.size() - 1).asText() ); } @@ -411,7 +411,7 @@ void advanceBlockchain_ok( // Headers should have been parsed in the reverse order for (int j = 0; j < blocksInRequest.size(); j++) { assertEquals( - Hex.toHexString(blockHeadersInverted.pop().getFullEncoded()), + Hex.toHexString(blockHeadersInverted.pop().getEncoded(true, true, true)), blocksInRequest.get(j).asText() ); } @@ -437,7 +437,7 @@ private void assertBrothers(JsonNode brothersInRequest, Stack> for (BlockHeader brother : blockBrothers) { byte[] brotherFromPayload = Hex.decode(brothersPayload.next().asText()); - assertArrayEquals(brother.getFullEncoded(), brotherFromPayload); + assertArrayEquals(brother.getEncoded(true, true, true), brotherFromPayload); } assertFalse(brothersPayload.hasNext()); // No more brothers } diff --git a/src/test/java/co/rsk/federate/signing/hsm/message/AdvanceBlockchainMessageTest.java b/src/test/java/co/rsk/federate/signing/hsm/message/AdvanceBlockchainMessageTest.java index 810e4abb..06e884bf 100644 --- a/src/test/java/co/rsk/federate/signing/hsm/message/AdvanceBlockchainMessageTest.java +++ b/src/test/java/co/rsk/federate/signing/hsm/message/AdvanceBlockchainMessageTest.java @@ -48,7 +48,7 @@ void getParsedBlockHeaders_ok_sorted() { // Headers should have been parsed in the reverse order int blockIndex = blocks.size() - 1 - i; assertEquals( - Hex.toHexString(blocks.get(blockIndex).getHeader().getFullEncoded()), + Hex.toHexString(blocks.get(blockIndex).getHeader().getEncoded(true, true, true)), parsedBlockHeaders.get(i) ); } @@ -63,7 +63,7 @@ void getParsedBrothers_ok() throws HSMBlockchainBookkeepingRelatedException { // Headers should have been parsed in the reverse order int blockIndex = blocks.size() - 1 - i; assertEquals( - Hex.toHexString(blocks.get(blockIndex).getHeader().getFullEncoded()), + Hex.toHexString(blocks.get(blockIndex).getHeader().getEncoded(true, true, true)), parsedBlockHeaders.get(i) ); @@ -76,7 +76,7 @@ void getParsedBrothers_ok() throws HSMBlockchainBookkeepingRelatedException { for (int j = 0; j < parsedBrothers.length; j++) { assertEquals( - Hex.toHexString(expectedBrothers.get(j).getFullEncoded()), + Hex.toHexString(expectedBrothers.get(j).getEncoded(true, true, true)), parsedBrothers[j] ); } @@ -90,7 +90,7 @@ void getParsedBrothers_invalid_blockHeader() { assertThrows( HSMBlockchainBookkeepingRelatedException.class, - () -> message.getParsedBrothers(Hex.toHexString(invalidBlockHeader.getFullEncoded())) + () -> message.getParsedBrothers(Hex.toHexString(invalidBlockHeader.getEncoded(true, true, true))) ); } @@ -107,7 +107,7 @@ void getParsedBrothers_with_more_than_10_brothers() throws HSMBlockchainBookkeep // Headers should have been parsed in the reverse order int blockIndex = blocksWithMultipleBrothers.size() - 1 - i; assertEquals( - Hex.toHexString(blocksWithMultipleBrothers.get(blockIndex).getHeader().getFullEncoded()), + Hex.toHexString(blocksWithMultipleBrothers.get(blockIndex).getHeader().getEncoded(true, true, true)), parsedBlockHeaders.get(i) ); @@ -119,7 +119,7 @@ void getParsedBrothers_with_more_than_10_brothers() throws HSMBlockchainBookkeep for (int j = 0; j < parsedBrothers.length; j++) { assertEquals( - Hex.toHexString(expectedBrothers.get(j).getFullEncoded()), + Hex.toHexString(expectedBrothers.get(j).getEncoded(true, true, true)), parsedBrothers[j] ); } diff --git a/src/test/java/co/rsk/federate/signing/hsm/message/ParsedHeaderTest.java b/src/test/java/co/rsk/federate/signing/hsm/message/ParsedHeaderTest.java index c358e325..4ba6cf06 100644 --- a/src/test/java/co/rsk/federate/signing/hsm/message/ParsedHeaderTest.java +++ b/src/test/java/co/rsk/federate/signing/hsm/message/ParsedHeaderTest.java @@ -39,7 +39,7 @@ void setup() { @Test void getBlockHeader() { - String serializedHeader = Hex.toHexString(blockHeader.getFullEncoded()); + String serializedHeader = Hex.toHexString(blockHeader.getEncoded(true, true, true)); assertEquals(serializedHeader, parsedHeader.getBlockHeader()); } @@ -50,7 +50,7 @@ void getBrothers() { brothers.sort(Comparator.comparing(BlockHeader::getHash)); for (int i = 0; i < actualBrothers.length; i++) { - assertEquals(Hex.toHexString(brothers.get(i).getFullEncoded()), actualBrothers[i]); + assertEquals(Hex.toHexString(brothers.get(i).getEncoded(true, true, true)), actualBrothers[i]); } } diff --git a/src/test/java/co/rsk/federate/signing/hsm/requirements/AncestorBlockUpdaterTest.java b/src/test/java/co/rsk/federate/signing/hsm/requirements/AncestorBlockUpdaterTest.java index a5599d1c..f486e73b 100644 --- a/src/test/java/co/rsk/federate/signing/hsm/requirements/AncestorBlockUpdaterTest.java +++ b/src/test/java/co/rsk/federate/signing/hsm/requirements/AncestorBlockUpdaterTest.java @@ -59,7 +59,7 @@ void ensureAncestorBlockInPosition_ancestor_ok_after_update() Block targetBlock = mock(Block.class); when(targetBlock.getHash()).thenReturn(targetBlockHash); BlockHeader blockHeader = mock(BlockHeader.class); - when(blockHeader.getEncoded(true, false)).thenReturn(TestUtils.createHash(2).getBytes()); + when(blockHeader.getEncoded(true, false, true)).thenReturn(TestUtils.createHash(2).getBytes()); when(targetBlock.getHeader()).thenReturn(blockHeader); Keccak256 initialAncestorBlockHash = TestUtils.createHash(1); @@ -69,7 +69,7 @@ void ensureAncestorBlockInPosition_ancestor_ok_after_update() // Ancestor is just one block ahead of the target block when(initialAncestorBlock.getParentHash()).thenReturn(targetBlockHash); when(initialAncestorBlock.getHeader()).thenReturn(initialAncestorBlockHeader); - when(initialAncestorBlockHeader.getEncoded(true, false)).thenReturn(initialAncestorBlockHash.getBytes()); + when(initialAncestorBlockHeader.getEncoded(true, false, true)).thenReturn(initialAncestorBlockHash.getBytes()); PowHSMState initialState = new PowHSMState(initialAncestorBlockHash.toHexString(), initialAncestorBlockHash.toHexString(), false); PowHSMState secondState = new PowHSMState(targetBlockHash.toHexString(), targetBlockHash.toHexString(), false); diff --git a/src/test/java/co/rsk/federate/signing/utils/TestUtils.java b/src/test/java/co/rsk/federate/signing/utils/TestUtils.java index d7bf96da..ccf80e01 100644 --- a/src/test/java/co/rsk/federate/signing/utils/TestUtils.java +++ b/src/test/java/co/rsk/federate/signing/utils/TestUtils.java @@ -65,7 +65,6 @@ public static Block mockBlock(long number, Keccak256 hash) { when(block.getUncleList()).thenReturn(Collections.emptyList()); BlockHeader blockHeader = mock(BlockHeader.class); when(blockHeader.getHash()).thenReturn(hash); - when(blockHeader.getFullEncoded()).thenReturn(hash.getBytes()); when(block.getHeader()).thenReturn(blockHeader); return block; @@ -77,8 +76,7 @@ public static Block mockBlock(long number, Keccak256 hash, Keccak256 parentHash) when(block.getNumber()).thenReturn(number); when(block.getParentHash()).thenReturn(parentHash); BlockHeader blockHeader = mock(BlockHeader.class); - when(blockHeader.getEncoded(true, false)).thenReturn(hash.getBytes()); - when(blockHeader.getFullEncoded()).thenReturn(hash.getBytes()); + when(blockHeader.getEncoded(true, false, true)).thenReturn(hash.getBytes()); when(block.getHeader()).thenReturn(blockHeader); return block; @@ -89,7 +87,6 @@ public static Block mockBlock(long number, Keccak256 hash, long difficultyValue) when(block.getHash()).thenReturn(hash); when(block.getNumber()).thenReturn(number); BlockHeader blockHeader = mock(BlockHeader.class); - when(blockHeader.getFullEncoded()).thenReturn(hash.getBytes()); when(blockHeader.getHash()).thenReturn(hash); when(block.getHeader()).thenReturn(blockHeader); when(block.getDifficulty()).thenReturn(new BlockDifficulty(BigInteger.valueOf(difficultyValue)));