|
|
|
@ -74,16 +74,19 @@ public abstract class AbstractGetHeadersFromPeerTask |
|
|
|
|
final List<BlockHeader> headers = headersMessage.getHeaders(protocolSchedule); |
|
|
|
|
if (headers.isEmpty()) { |
|
|
|
|
// Message contains no data - nothing to do
|
|
|
|
|
LOG.debug("headers.isEmpty. Peer: {}", peer); |
|
|
|
|
return Optional.empty(); |
|
|
|
|
} |
|
|
|
|
if (headers.size() > count) { |
|
|
|
|
// Too many headers - this isn't our response
|
|
|
|
|
LOG.debug("headers.size()>count. Peer: {}", peer); |
|
|
|
|
return Optional.empty(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final BlockHeader firstHeader = headers.get(0); |
|
|
|
|
if (!matchesFirstHeader(firstHeader)) { |
|
|
|
|
// This isn't our message - nothing to do
|
|
|
|
|
LOG.debug("!matchesFirstHeader. Peer: {}", peer); |
|
|
|
|
return Optional.empty(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -95,6 +98,7 @@ public abstract class AbstractGetHeadersFromPeerTask |
|
|
|
|
final BlockHeader header = headers.get(i); |
|
|
|
|
if (header.getNumber() != prevBlockHeader.getNumber() + expectedDelta) { |
|
|
|
|
// Skip doesn't match, this isn't our data
|
|
|
|
|
LOG.debug("header not matching the expected number. Peer: {}", peer); |
|
|
|
|
return Optional.empty(); |
|
|
|
|
} |
|
|
|
|
// if headers are supposed to be sequential check if a chain is formed
|
|
|
|
@ -103,8 +107,7 @@ public abstract class AbstractGetHeadersFromPeerTask |
|
|
|
|
final BlockHeader child = reverse ? prevBlockHeader : header; |
|
|
|
|
if (!parent.getHash().equals(child.getParentHash())) { |
|
|
|
|
LOG.debug( |
|
|
|
|
"Sequential headers must form a chain through hashes, disconnecting peer: {}", |
|
|
|
|
peer.toString()); |
|
|
|
|
"Sequential headers must form a chain through hashes, disconnecting peer: {}", peer); |
|
|
|
|
peer.disconnect(DisconnectMessage.DisconnectReason.BREACH_OF_PROTOCOL); |
|
|
|
|
return Optional.empty(); |
|
|
|
|
} |
|
|
|
@ -113,7 +116,7 @@ public abstract class AbstractGetHeadersFromPeerTask |
|
|
|
|
headersList.add(header); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
LOG.debug("Received {} of {} headers requested from peer.", headersList.size(), count); |
|
|
|
|
LOG.debug("Received {} of {} headers requested from peer {}", headersList.size(), count, peer); |
|
|
|
|
return Optional.of(headersList); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|