Search in sources :

Example 36 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class BlockHeadersMessage method encode.

private void encode() {
    List<byte[]> encodedElements = new ArrayList<>();
    for (BlockHeader blockHeader : blockHeaders) {
        encodedElements.add(blockHeader.getEncoded());
    }
    byte[][] encodedElementArray = encodedElements.toArray(new byte[encodedElements.size()][]);
    this.encoded = RLP.encodeList(encodedElementArray);
}
Also used : ArrayList(java.util.ArrayList) BlockHeader(org.ethereum.core.BlockHeader)

Example 37 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class BlockHeadersMessage method parse.

private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
    blockHeaders = new ArrayList<>();
    for (int i = 0; i < paramsList.size(); ++i) {
        RLPList rlpData = ((RLPList) paramsList.get(i));
        blockHeaders.add(new BlockHeader(rlpData, true));
    }
    parsed = true;
}
Also used : BlockHeader(org.ethereum.core.BlockHeader) RLPList(org.ethereum.util.RLPList)

Example 38 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class DownloadingBodiesSyncState method newBody.

@Override
public void newBody(BodyResponseMessage message, MessageChannel peer) {
    NodeID peerId = peer.getPeerNodeID();
    if (!isExpectedBody(message.getId(), peerId)) {
        handleUnexpectedBody(peerId);
        return;
    }
    // we already checked that this message was expected
    BlockHeader header = pendingBodyResponses.remove(message.getId()).header;
    Block block = Block.fromValidData(header, message.getTransactions(), message.getUncles());
    if (!blockUnclesHashValidationRule.isValid(block) || !blockTransactionsValidationRule.isValid(block)) {
        handleInvalidMessage(peerId, header);
        return;
    }
    // handle block
    if (syncInformation.processBlock(block, peer).isInvalidBlock()) {
        handleInvalidBlock(peerId, header);
        return;
    }
    // updates peer downloading information
    tryRequestNextBody(peerId);
    // check if this was the last block to download
    verifyDownloadIsFinished();
}
Also used : NodeID(co.rsk.net.NodeID) Block(org.ethereum.core.Block) BlockHeader(org.ethereum.core.BlockHeader)

Example 39 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class DownloadingBodiesSyncState method updateHeadersAndChunks.

private Optional<BlockHeader> updateHeadersAndChunks(NodeID peerId, Integer currentChunk) {
    Deque<BlockHeader> headers = pendingHeaders.get(currentChunk);
    BlockHeader header = headers.poll();
    while (header != null) {
        // we double check if the header was not downloaded or obtained by another way
        if (!syncInformation.isKnownBlock(header.getHash().getBytes())) {
            return Optional.of(header);
        }
        header = headers.poll();
    }
    Optional<BlockHeader> blockHeader = tryFindBlockHeader(peerId);
    if (!blockHeader.isPresent()) {
        chunksBeingDownloaded.remove(peerId);
        segmentsBeingDownloaded.remove(peerId);
        messagesByPeers.remove(peerId);
    }
    return blockHeader;
}
Also used : BlockHeader(org.ethereum.core.BlockHeader)

Example 40 with BlockHeader

use of org.ethereum.core.BlockHeader in project rskj by rsksmart.

the class DownloadingBodiesSyncState method handleTimeoutMessage.

private void handleTimeoutMessage(NodeID peerId) {
    syncInformation.reportEvent("Timeout waiting body from node {}", EventType.TIMEOUT_MESSAGE, peerId, peerId);
    Long messageId = messagesByPeers.remove(peerId);
    BlockHeader header = pendingBodyResponses.remove(messageId).header;
    clearPeerInfo(peerId);
    resetChunkAndHeader(peerId, header);
}
Also used : BlockHeader(org.ethereum.core.BlockHeader)

Aggregations

BlockHeader (org.ethereum.core.BlockHeader)65 Test (org.junit.Test)36 Block (org.ethereum.core.Block)27 ArrayList (java.util.ArrayList)13 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)9 BlockDifficulty (co.rsk.core.BlockDifficulty)5 Keccak256 (co.rsk.crypto.Keccak256)5 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)4 BlockBuilder (co.rsk.test.builders.BlockBuilder)4 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)4 BlockStore (org.ethereum.db.BlockStore)4 SimpleMessageChannel (co.rsk.net.simples.SimpleMessageChannel)3 BigInteger (java.math.BigInteger)3 MainNetConfig (org.ethereum.config.net.MainNetConfig)3 DataWord (org.ethereum.vm.DataWord)3 DifficultyCalculator (co.rsk.core.DifficultyCalculator)2 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)2 HashSet (java.util.HashSet)2 Bloom (org.ethereum.core.Bloom)2 Transaction (org.ethereum.core.Transaction)2