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

Class Class, % Method, % Line, %
BlockParentNumberRule 0% (0/1) 0% (0/4) 0% (0/11)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package co.rsk.validators; 21  22 import org.ethereum.core.Block; 23 import org.ethereum.core.BlockHeader; 24 import org.slf4j.Logger; 25 import org.slf4j.LoggerFactory; 26  27 /** 28  * Checks if {@link BlockHeader#number} == {@link BlockHeader#number} + 1 of parent's block 29  * 30  * @author Mikhail Kalinin 31  * @since 02.09.2015 32  */ 33 public class BlockParentNumberRule implements BlockParentDependantValidationRule, BlockHeaderParentDependantValidationRule { 34  35  private static final Logger logger = LoggerFactory.getLogger("blockvalidator"); 36  37  @Override 38  public boolean isValid(BlockHeader header, Block parent) { 39  if (header == null || parent == null) { 40  logger.warn("BlockParentNumberRule - block or parent are null"); 41  return false; 42  } 43  BlockHeader parentHeader = parent.getHeader(); 44  if (header.getNumber() != (parentHeader.getNumber() + 1)) { 45  logger.warn("#{}: block number is not parentBlock number + 1", header.getNumber()); 46  return false; 47  } 48  return true; 49  } 50  51  @Override 52  public boolean isValid(Block block, Block parent) { 53  return isValid(block.getHeader(), parent); 54  } 55 }