Coverage Summary for Class: PrevMinGasPriceRule (co.rsk.validators)

Class Class, % Method, % Line, %
PrevMinGasPriceRule 0% (0/1) 0% (0/4) 0% (0/15)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * 5  * This program is free software: you can redistribute it and/or modify 6  * it under the terms of the GNU Lesser General Public License as published by 7  * the Free Software Foundation, either version 3 of the License, or 8  * (at your option) any later version. 9  * 10  * This program is distributed in the hope that it will be useful, 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13  * GNU Lesser General Public License for more details. 14  * 15  * You should have received a copy of the GNU Lesser General Public License 16  * along with this program. If not, see <http://www.gnu.org/licenses/>. 17  */ 18  19 package co.rsk.validators; 20  21 import co.rsk.mine.BlockGasPriceRange; 22 import co.rsk.panic.PanicProcessor; 23 import org.ethereum.core.Block; 24 import org.ethereum.core.BlockHeader; 25 import org.slf4j.Logger; 26 import org.slf4j.LoggerFactory; 27  28 /** 29  * Created by mario on 26/12/16. 30  */ 31 public class PrevMinGasPriceRule implements BlockParentDependantValidationRule, BlockHeaderParentDependantValidationRule { 32  33  private static final Logger logger = LoggerFactory.getLogger("blockvalidator"); 34  private static final PanicProcessor panicProcessor = new PanicProcessor(); 35  36  @Override 37  public boolean isValid(Block block, Block parent) { 38  return isValid(block.getHeader(), parent); 39  } 40  41  @Override 42  public boolean isValid(BlockHeader header, Block parent) { 43  if (header.isGenesis()) { 44  return true; 45  } 46  47  if (header.getMinimumGasPrice() == null || parent == null) { 48  logger.warn("PrevMinGasPriceRule - blockmingasprice or parent are null"); 49  return false; 50  } 51  52  BlockGasPriceRange range = new BlockGasPriceRange(parent.getMinimumGasPrice()); 53  boolean result = range.inRange(header.getMinimumGasPrice()); 54  if (!result) { 55  logger.warn("Error validating Min Gas Price."); 56  panicProcessor.panic("invalidmingasprice", "Error validating Min Gas Price."); 57  } 58  59  return range.inRange(header.getMinimumGasPrice()); 60  } 61 }