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