use of neo.model.core.Header in project neo-java by coranos.
the class LocalNodeDataSynchronizedUtil method requestBlocksUnsynchronized.
/**
* request blocks from the remote node, this is the unsynchronized helper
* method..
*
* @param localNodeData
* the local node data to use.
* @param remoteNodeData
* the remote node data to use.
*/
private static void requestBlocksUnsynchronized(final LocalNodeData localNodeData, final RemoteNodeData remoteNodeData) {
if (!localNodeData.getVerifiedHeaderPoolMap().isEmpty()) {
final List<UInt256> hashs = new ArrayList<>();
final Iterator<Entry<Long, Header>> headerIt = localNodeData.getVerifiedHeaderPoolMap().entrySet().iterator();
while ((hashs.size() < InvPayload.MAX_HASHES) && headerIt.hasNext()) {
final Entry<Long, Header> headerElt = headerIt.next();
final Header header = headerElt.getValue();
final UInt256 hashRaw = header.hash;
if (localNodeData.getBlockDb().containsBlockWithHash(hashRaw)) {
headerIt.remove();
} else {
final byte[] ba = hashRaw.getBytesCopy();
final UInt256 hash = new UInt256(ba);
hashs.add(hash);
if (LOG.isDebugEnabled()) {
LOG.debug("requestBlocks send {} getblocks {} {}", remoteNodeData.getHostAddress(), header.getIndexAsLong(), hash.toReverseHexString());
}
}
}
MessageUtil.sendGetData(remoteNodeData, localNodeData, InventoryType.BLOCK, hashs.toArray(new UInt256[0]));
} else {
if (localNodeData.getBlockDb().getHeaderOfBlockWithMaxIndex() == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("requestBlocks send {} hash is genesis.", remoteNodeData.getHostAddress());
}
MessageUtil.sendGetData(remoteNodeData, localNodeData, InventoryType.BLOCK, GenesisBlockUtil.GENESIS_HASH);
} else {
LOG.info("SKIPPING requestBlocks, no hashes.");
}
}
}
use of neo.model.core.Header in project neo-java by coranos.
the class TestCoreToJson method test008Header.
/**
* test Header.
*/
@Test
public void test008Header() {
final int minSize = (UInt32.SIZE * 3) + (UInt256.SIZE * 2) + (UInt64.SIZE) + (UInt160.SIZE) + 4;
final String expectedStrRaw = TestUtil.getJsonTestResourceAsString(TEST_PACKAGE, getClass().getSimpleName(), "test008Header");
final String expectedStr = new JSONObject(expectedStrRaw).toString();
final String actualStr = new Header(ByteBuffer.wrap(new byte[minSize])).toString();
Assert.assertEquals(TestUtil.RESPONSES_MUST_MATCH, expectedStr, actualStr);
}
Aggregations