From c52975b275b24be774a3c34a1f72d36016142e04 Mon Sep 17 00:00:00 2001 From: Matt Whitehead Date: Thu, 13 Jun 2024 02:14:36 +0100 Subject: [PATCH] Don't persist BFT proposed blocks, only committed ones (#7204) * Don't persist BFT proposed blocks, only committed ones Signed-off-by: Matthew Whitehead * Fix unit tests, update copyright Signed-off-by: Matthew Whitehead * Update changelog Signed-off-by: Matthew Whitehead --------- Signed-off-by: Matthew Whitehead Signed-off-by: Matt Whitehead --- CHANGELOG.md | 2 ++ .../validation/ProposalPayloadValidator.java | 4 ++-- .../ProposalPayloadValidatorTest.java | 18 ++++++++++++------ .../qbft/validation/ProposalValidatorTest.java | 8 +++++--- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cba041d31d..520a087fc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ ### Bug fixes - Make `eth_gasPrice` aware of the base fee market [#7102](https://github.com/hyperledger/besu/pull/7102) - Validation errors ignored in accounts-allowlist and empty list [#7138](https://github.com/hyperledger/besu/issues/7138) +- Fix "Invalid block detected" for BFT chains using Bonsai DB [#7204](https://github.com/hyperledger/besu/pull/7204) + ## 24.5.2 ### Upcoming Breaking Changes diff --git a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidator.java b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidator.java index bdb4ebd14c..640216e9a9 100644 --- a/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidator.java +++ b/consensus/qbft/src/main/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 ConsenSys AG. + * Copyright contributors to Hyperledger Besu. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -150,7 +150,7 @@ public class ProposalPayloadValidator { final var validationResult = blockValidator.validateAndProcessBlock( - protocolContext, block, HeaderValidationMode.LIGHT, HeaderValidationMode.FULL); + protocolContext, block, HeaderValidationMode.LIGHT, HeaderValidationMode.FULL, false); if (!validationResult.isSuccessful()) { LOG.info( diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java index e80f302892..182393484e 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalPayloadValidatorTest.java @@ -105,7 +105,8 @@ public class ProposalPayloadValidatorTest { eq(protocolContext), eq(block), eq(HeaderValidationMode.LIGHT), - eq(HeaderValidationMode.FULL))) + eq(HeaderValidationMode.FULL), + eq(false))) .thenReturn(new BlockProcessingResult(Optional.empty())); assertThat(payloadValidator.validate(proposal.getSignedPayload())).isTrue(); @@ -129,7 +130,8 @@ public class ProposalPayloadValidatorTest { eq(protocolContext), eq(block), eq(HeaderValidationMode.LIGHT), - eq(HeaderValidationMode.FULL))) + eq(HeaderValidationMode.FULL), + eq(false))) .thenReturn(new BlockProcessingResult(Optional.empty())); assertThat(payloadValidator.validate(proposal.getSignedPayload())).isTrue(); @@ -152,7 +154,8 @@ public class ProposalPayloadValidatorTest { eq(protocolContext), eq(block), eq(HeaderValidationMode.LIGHT), - eq(HeaderValidationMode.FULL))) + eq(HeaderValidationMode.FULL), + eq(false))) .thenReturn(new BlockProcessingResult("Failed")); assertThat(payloadValidator.validate(proposal.getSignedPayload())).isFalse(); @@ -228,7 +231,8 @@ public class ProposalPayloadValidatorTest { eq(protocolContext), eq(block), eq(HeaderValidationMode.LIGHT), - eq(HeaderValidationMode.FULL))) + eq(HeaderValidationMode.FULL), + eq(false))) .thenReturn(new BlockProcessingResult(Optional.empty())); assertThat(payloadValidator.validate(proposal.getSignedPayload())).isFalse(); @@ -262,7 +266,8 @@ public class ProposalPayloadValidatorTest { eq(protocolContext), eq(block), eq(HeaderValidationMode.LIGHT), - eq(HeaderValidationMode.FULL))) + eq(HeaderValidationMode.FULL), + eq(false))) .thenReturn(new BlockProcessingResult(Optional.empty())); when(cmsValidator.validate(eq(cms), eq(hashWithoutCms))).thenReturn(false); @@ -297,7 +302,8 @@ public class ProposalPayloadValidatorTest { eq(protocolContext), eq(block), eq(HeaderValidationMode.LIGHT), - eq(HeaderValidationMode.FULL))) + eq(HeaderValidationMode.FULL), + eq(false))) .thenReturn(new BlockProcessingResult(Optional.empty())); when(cmsValidator.validate(eq(cms), eq(hashWithoutCms))).thenReturn(true); diff --git a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java index 53876f5b87..c28588a9d5 100644 --- a/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java +++ b/consensus/qbft/src/test/java/org/hyperledger/besu/consensus/qbft/validation/ProposalValidatorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 ConsenSys AG. + * Copyright contributors to Hyperledger Besu. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at @@ -111,7 +111,8 @@ public class ProposalValidatorTest { eq(protocolContext), any(), eq(HeaderValidationMode.LIGHT), - eq(HeaderValidationMode.FULL))) + eq(HeaderValidationMode.FULL), + eq(false))) .thenReturn(new BlockProcessingResult(Optional.empty())); when(protocolSchedule.getByBlockHeader(any())).thenReturn(protocolSpec); @@ -168,7 +169,8 @@ public class ProposalValidatorTest { eq(protocolContext), any(), eq(HeaderValidationMode.LIGHT), - eq(HeaderValidationMode.FULL))) + eq(HeaderValidationMode.FULL), + eq(false))) .thenReturn(new BlockProcessingResult("Failed")); assertThat(roundItem.messageValidator.validate(proposal)).isFalse();