Skip to content
/ besu Public
forked from hyperledger/besu

Commit

Permalink
Refactor BadBlockReason enum out of BadBlockCause (hyperledger#6716)
Browse files Browse the repository at this point in the history
* Refactor BadBlockReason enum out of BadBlockCause

Signed-off-by: Usman Saleem <[email protected]>

* Deleting ununsed enum value

Signed-off-by: Usman Saleem <[email protected]>

---------

Signed-off-by: Usman Saleem <[email protected]>
Co-authored-by: Sally MacFarlane <[email protected]>
Signed-off-by: amsmota <[email protected]>
  • Loading branch information
2 people authored and amsmota committed Apr 16, 2024
1 parent a592adc commit cc4f90f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,26 @@
*/
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;

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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit cc4f90f

Please sign in to comment.