use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class CheckingBestHeaderSyncState method newBlockHeaders.
@Override
public void newBlockHeaders(List<BlockHeader> chunk) {
BlockHeader header = chunk.get(0);
if (!ByteUtil.fastEquals(header.getHash().getBytes(), miniChunk.getHash()) || !syncInformation.blockHeaderIsValid(header)) {
syncEventsHandler.onErrorSyncing("Invalid chunk received from node {}", EventType.INVALID_HEADER, this.getClass(), syncInformation.getSelectedPeerId());
return;
}
syncEventsHandler.startFindingConnectionPoint();
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class NodeBlockProcessor method processBlockHeadersRequest.
/**
* processBlockHeadersRequest sends a list of block headers.
*
* @param sender the sender of the BlockHeadersRequest message.
* @param requestId the id of the request
* @param hash the hash of the block to be processed
* @param count the number of headers to send
*/
@Override
public void processBlockHeadersRequest(@Nonnull final MessageChannel sender, long requestId, @Nonnull final byte[] hash, int count) {
logger.trace("Processing headers request {} {} from {}", requestId, Hex.toHexString(hash).substring(0, 10), sender.getPeerNodeID());
Block block = blockSyncService.getBlockFromStoreOrBlockchain(hash);
if (block == null) {
return;
}
List<BlockHeader> headers = new ArrayList<>();
headers.add(block.getHeader());
for (int k = 1; k < count; k++) {
block = blockSyncService.getBlockFromStoreOrBlockchain(block.getParentHash().getBytes());
if (block == null) {
break;
}
headers.add(block.getHeader());
}
BlockHeadersResponseMessage response = new BlockHeadersResponseMessage(requestId, headers);
sender.sendMessage(response);
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class FamilyUtils method getUnclesHeaders.
public static List<BlockHeader> getUnclesHeaders(@Nonnull BlockStore store, long blockNumber, byte[] parentHash, int levels) {
List<BlockHeader> uncles = new ArrayList<>();
Set<Keccak256> unclesHeaders = getUncles(store, blockNumber, parentHash, levels);
for (Keccak256 uncleHash : unclesHeaders) {
Block uncle = store.getBlockByHash(uncleHash.getBytes());
if (uncle != null) {
uncles.add(uncle.getHeader());
}
}
return uncles;
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockParentNumberRule method isValid.
@Override
public boolean isValid(Block block, Block parent) {
if (block == null || parent == null) {
logger.warn("BlockParentNumberRule - block or parent are null");
return false;
}
BlockHeader header = block.getHeader();
BlockHeader parentHeader = parent.getHeader();
if (header.getNumber() != (parentHeader.getNumber() + 1)) {
logger.warn(String.format("#%d: block number is not parentBlock number + 1", header.getNumber()));
return false;
}
return true;
}
use of org.ethereum.core.BlockHeader in project rskj by rsksmart.
the class BlockUnclesValidationRule method validateUncleList.
/**
* Validate an uncle list.
* It validates that the uncle list is not too large
* It validates that each uncle
* - is not an ancestor
* - is not a used uncle
* - has a common ancestor with the block
*
* @param blockNumber the number of the block containing the uncles
* @param uncles the uncle list to validate
* @param ancestors the list of direct ancestors of the block containing the uncles
* @param used used uncles
* @return true if the uncles in the list are valid, false if not
*/
public boolean validateUncleList(long blockNumber, List<BlockHeader> uncles, Set<Keccak256> ancestors, Set<Keccak256> used) {
if (uncles.size() > uncleListLimit) {
logger.error("Uncle list to big: block.getUncleList().size() > UNCLE_LIST_LIMIT");
panicProcessor.panic(INVALIDUNCLE, "Uncle list to big: block.getUncleList().size() > UNCLE_LIST_LIMIT");
return false;
}
Set<Keccak256> hashes = new HashSet<>();
for (BlockHeader uncle : uncles) {
Block blockForUncleHeader = new Block(uncle);
if (!this.validations.isValid(blockForUncleHeader) || !validateParentNumber(uncle, blockNumber)) {
return false;
}
Keccak256 uncleHash = uncle.getHash();
/* Just checking that the uncle is not added twice */
if (hashes.contains(uncleHash)) {
return false;
}
hashes.add(uncleHash);
if (!validateUnclesAncestors(ancestors, uncleHash) || !validateIfUncleWasNeverUsed(used, uncleHash) || !validateUncleParent(ancestors, blockForUncleHeader)) {
return false;
}
}
return true;
}
Aggregations