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);
}
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;
}
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();
}
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;
}
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);
}
Aggregations