From cc4f90f00833462746d7921d66ee3bc9373c0d4c Mon Sep 17 00:00:00 2001 From: Usman Saleem Date: Wed, 13 Mar 2024 13:01:00 +1000 Subject: [PATCH] Refactor BadBlockReason enum out of BadBlockCause (#6716) * Refactor BadBlockReason enum out of BadBlockCause Signed-off-by: Usman Saleem * Deleting ununsed enum value Signed-off-by: Usman Saleem --------- Signed-off-by: Usman Saleem Co-authored-by: Sally MacFarlane Signed-off-by: amsmota --- .../besu/ethereum/chain/BadBlockCause.java | 15 +++++-------- .../besu/ethereum/chain/BadBlockReason.java | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BadBlockReason.java diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BadBlockCause.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BadBlockCause.java index 7a014e99cd2..601e96de25f 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BadBlockCause.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BadBlockCause.java @@ -15,19 +15,14 @@ */ package org.hyperledger.besu.ethereum.chain; +import static org.hyperledger.besu.ethereum.chain.BadBlockReason.DESCENDS_FROM_BAD_BLOCK; +import static org.hyperledger.besu.ethereum.chain.BadBlockReason.SPEC_VALIDATION_FAILURE; + import org.hyperledger.besu.ethereum.core.Block; import com.google.common.base.MoreObjects; public class BadBlockCause { - public enum BadBlockReason { - // Standard spec-related validation failures - SPEC_VALIDATION_FAILURE, - // When an unexpected exception occurs during block processing - EXCEPTIONAL_BLOCK_PROCESSING, - // This block is bad because it descends from a bad block - DESCENDS_FROM_BAD_BLOCK, - } private final BadBlockReason reason; private final String description; @@ -35,11 +30,11 @@ public enum BadBlockReason { public static BadBlockCause fromBadAncestorBlock(final Block badAncestor) { final String description = String.format("Descends from bad block %s", badAncestor.toLogString()); - return new BadBlockCause(BadBlockReason.DESCENDS_FROM_BAD_BLOCK, description); + return new BadBlockCause(DESCENDS_FROM_BAD_BLOCK, description); } public static BadBlockCause fromValidationFailure(final String failureMessage) { - return new BadBlockCause(BadBlockReason.SPEC_VALIDATION_FAILURE, failureMessage); + return new BadBlockCause(SPEC_VALIDATION_FAILURE, failureMessage); } private BadBlockCause(final BadBlockReason reason, final String description) { diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BadBlockReason.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BadBlockReason.java new file mode 100644 index 00000000000..f38655cb830 --- /dev/null +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/chain/BadBlockReason.java @@ -0,0 +1,22 @@ +/* + * Copyright Hyperledger Besu Contributors. + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.ethereum.chain; + +public enum BadBlockReason { + // Standard spec-related validation failures + SPEC_VALIDATION_FAILURE, + // This block is bad because it descends from a bad block + DESCENDS_FROM_BAD_BLOCK, +}