@ -17,6 +17,7 @@ package org.hyperledger.besu.consensus.clique;
import static org.hyperledger.besu.ethereum.mainnet.AbstractGasLimitSpecification.DEFAULT_MAX_GAS_LIMIT ;
import static org.hyperledger.besu.ethereum.mainnet.AbstractGasLimitSpecification.DEFAULT_MIN_GAS_LIMIT ;
import org.hyperledger.besu.config.MergeConfigOptions ;
import org.hyperledger.besu.consensus.clique.headervalidationrules.CliqueDifficultyValidationRule ;
import org.hyperledger.besu.consensus.clique.headervalidationrules.CliqueExtraDataValidationRule ;
import org.hyperledger.besu.consensus.clique.headervalidationrules.CoinbaseHeaderValidationRule ;
@ -28,6 +29,7 @@ import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.mainnet.BlockHeaderValidator ;
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket ;
import org.hyperledger.besu.ethereum.mainnet.headervalidationrules.AncestryValidationRule ;
import org.hyperledger.besu.ethereum.mainnet.headervalidationrules.AttachedComposedFromDetachedRule ;
import org.hyperledger.besu.ethereum.mainnet.headervalidationrules.BaseFeeMarketBlockHeaderGasPriceValidationRule ;
import org.hyperledger.besu.ethereum.mainnet.headervalidationrules.ConstantFieldValidationRule ;
import org.hyperledger.besu.ethereum.mainnet.headervalidationrules.GasLimitRangeAndDeltaValidationRule ;
@ -37,6 +39,8 @@ import org.hyperledger.besu.ethereum.mainnet.headervalidationrules.TimestampMore
import java.util.Optional ;
import com.google.common.annotations.VisibleForTesting ;
public class BlockHeaderValidationRulesetFactory {
/ * *
@ -54,22 +58,28 @@ public class BlockHeaderValidationRulesetFactory {
final long secondsBetweenBlocks ,
final EpochManager epochManager ,
final Optional < BaseFeeMarket > baseFeeMarket ) {
return cliqueBlockHeaderValidator (
secondsBetweenBlocks , epochManager , baseFeeMarket , MergeConfigOptions . isMergeEnabled ( ) ) ;
}
@VisibleForTesting
public static BlockHeaderValidator . Builder cliqueBlockHeaderValidator (
final long secondsBetweenBlocks ,
final EpochManager epochManager ,
final Optional < BaseFeeMarket > baseFeeMarket ,
final boolean isMergeEnabled ) {
final BlockHeaderValidator . Builder builder =
new BlockHeaderValidator . Builder ( )
. addRule ( new AncestryValidationRule ( ) )
. addRule ( new TimestampBoundedByFutureParameter ( 10 ) )
. addRule ( new TimestampMoreRecentThanParent ( secondsBetweenBlocks ) )
. addRule (
new GasLimitRangeAndDeltaValidationRule (
DEFAULT_MIN_GAS_LIMIT , DEFAULT_MAX_GAS_LIMIT , baseFeeMarket ) )
. addRule (
new ConstantFieldValidationRule < > ( "MixHash" , BlockHeader : : getMixHash , Hash . ZERO ) )
. addRule (
new ConstantFieldValidationRule < > (
"OmmersHash" , BlockHeader : : getOmmersHash , Hash . EMPTY_LIST_HASH ) )
. addRule ( new CliqueExtraDataValidationRule ( epochManager ) )
. addRule ( new VoteValidationRule ( ) )
. addRule ( new CliqueDifficultyValidationRule ( ) )
. addRule ( new SignerRateLimitValidationRule ( ) )
. addRule ( new CoinbaseHeaderValidationRule ( epochManager ) )
@ -79,6 +89,20 @@ public class BlockHeaderValidationRulesetFactory {
builder . addRule ( new BaseFeeMarketBlockHeaderGasPriceValidationRule ( baseFeeMarket . get ( ) ) ) ;
}
var mixHashRule =
new ConstantFieldValidationRule < > ( "MixHash" , BlockHeader : : getMixHash , Hash . ZERO ) ;
var voteValidationRule = new VoteValidationRule ( ) ;
var cliqueTimestampRule = new TimestampMoreRecentThanParent ( secondsBetweenBlocks ) ;
if ( isMergeEnabled ) {
builder
. addRule ( new AttachedComposedFromDetachedRule ( mixHashRule ) )
. addRule ( new AttachedComposedFromDetachedRule ( voteValidationRule ) )
. addRule ( new AttachedComposedFromDetachedRule ( cliqueTimestampRule ) ) ;
} else {
builder . addRule ( mixHashRule ) . addRule ( voteValidationRule ) . addRule ( cliqueTimestampRule ) ;
}
return builder ;
}
}