This repository has been archived by the owner on Dec 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use BeaconValidator interface for beacon validations
- Loading branch information
Showing
6 changed files
with
95 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...j-core/src/main/java/org/ethereum/sharding/processing/validation/BeaconValidatorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) [2016] [ <ether.camp> ] | ||
* This file is part of the ethereumJ library. | ||
* | ||
* The ethereumJ library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* The ethereumJ library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.ethereum.sharding.processing.validation; | ||
|
||
import org.ethereum.sharding.domain.Beacon; | ||
import org.ethereum.sharding.processing.db.BeaconStore; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.ethereum.sharding.processing.validation.ValidationResult.Exist; | ||
import static org.ethereum.sharding.processing.validation.ValidationResult.NoParent; | ||
import static org.ethereum.sharding.processing.validation.ValidationResult.Success; | ||
|
||
/** | ||
* Runs a set of basic validations that is triggered before block processing. | ||
* | ||
* @author Mikhail Kalinin | ||
* @since 16.08.2018 | ||
*/ | ||
public class BeaconValidatorImpl implements BeaconValidator { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger("beacon"); | ||
|
||
BeaconStore store; | ||
List<ValidationRule<BeaconStore>> rules; | ||
|
||
public BeaconValidatorImpl(BeaconStore store) { | ||
this.store = store; | ||
|
||
rules = new ArrayList<>(); | ||
rules.add((block, st) -> st.exist(block.getHash()) ? Exist : Success); | ||
rules.add((block, st) -> st.exist(block.getParentHash()) ? Success : NoParent); | ||
} | ||
|
||
@Override | ||
public ValidationResult validateAndLog(Beacon block) { | ||
for (ValidationRule<BeaconStore> rule : rules) { | ||
ValidationResult res = rule.apply(block, store); | ||
if (res != Success) { | ||
logger.info("Process block {}, status: {}", block.toString(), res); | ||
return res; | ||
} | ||
} | ||
|
||
return Success; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters