use of org.aion.zero.impl.types.BlockHeader in project aion by aionnetwork.
the class SyncMgrTest method testRequestBodies_withTwoRequests.
@Test
public void testRequestBodies_withTwoRequests() {
BlockHeader header1 = mock(BlockHeader.class);
when(header1.getNumber()).thenReturn(101L);
byte[] hash1 = Hex.decode("6fd8dae3304a9864f460ec7aec21bc94e14e34876e5dddd0a74d9c68ac7bc9ed");
when(header1.getHash()).thenReturn(hash1);
when(header1.getTxTrieRootWrapper()).thenReturn(EMPTY_TRIE_HASH);
List<BlockHeader> list1 = new ArrayList<>();
list1.add(header1);
syncMgr.syncHeaderRequestManager.storeHeaders(1, list1);
BlockHeader header2 = mock(BlockHeader.class);
when(header2.getNumber()).thenReturn(102L);
byte[] hash2 = Hex.decode("f2652dde61042e9306dce95ecdc41a1be2be7eb374f19427aef2a79101b471ea");
when(header2.getHash()).thenReturn(hash2);
when(header2.getTxTrieRootWrapper()).thenReturn(EMPTY_TRIE_HASH);
List<BlockHeader> list2 = new ArrayList<>();
list2.add(header1);
list2.add(header2);
syncMgr.syncHeaderRequestManager.storeHeaders(1, list2);
syncMgr.requestBodies(1, "peer1");
// ensure that 1 request was sent
verify(p2pMgr, times(2)).send(anyInt(), anyString(), any(ReqBlocksBodies.class));
// both lists are still stored and can be retrieved in order
assertThat(syncMgr.syncHeaderRequestManager.matchAndDropHeaders(1, 1, EMPTY_TRIE_HASH)).isEqualTo(list1);
assertThat(syncMgr.syncHeaderRequestManager.matchAndDropHeaders(1, 2, EMPTY_TRIE_HASH)).isEqualTo(list2);
}
use of org.aion.zero.impl.types.BlockHeader in project aion by aionnetwork.
the class SyncMgrTest method testRequestBodies_withFilteringOnBlockNumber.
@Test
public void testRequestBodies_withFilteringOnBlockNumber() {
BlockHeader header = mock(BlockHeader.class);
when(header.getNumber()).thenReturn(bestBlockNumber);
byte[] hash = Hex.decode("6fd8dae3304a9864f460ec7aec21bc94e14e34876e5dddd0a74d9c68ac7bc9ed");
when(header.getHash()).thenReturn(hash);
when(header.getTxTrieRootWrapper()).thenReturn(EMPTY_TRIE_HASH);
List<BlockHeader> list = new ArrayList<>();
list.add(header);
INode peer1 = mock(INode.class);
when(peer1.getIdHash()).thenReturn(1);
when(peer1.getIdShort()).thenReturn("peer1");
when(peer1.getBestBlockNumber()).thenReturn(2 * bestBlockNumber);
// ensure that peer1 exists in the syncHeaderRequestManager
syncMgr.syncHeaderRequestManager.assertUpdateActiveNodes(Map.of(1, peer1), null, null, Set.of(1), Set.of(1), 2 * bestBlockNumber);
syncMgr.syncHeaderRequestManager.storeHeaders(1, list);
syncMgr.syncHeaderRequestManager.runInMode(1, SyncMode.NORMAL);
syncMgr.requestBodies(1, "peer1");
// ensure that 1 request was sent
verify(p2pMgr, never()).send(anyInt(), anyString(), any(ReqBlocksBodies.class));
assertThat(syncMgr.syncHeaderRequestManager.matchAndDropHeaders(1, 1, EMPTY_TRIE_HASH)).isNull();
}
use of org.aion.zero.impl.types.BlockHeader in project aion by aionnetwork.
the class SyncMgrTest method testValidateAndAddHeaders_withCorrectHeaders.
@Test
public void testValidateAndAddHeaders_withCorrectHeaders() {
int nodeId = 1;
String displayId = "peer1";
syncMgr.validateAndAddHeaders(nodeId, displayId, consecutiveHeaders);
verify(p2pMgr, never()).errCheck(nodeId, displayId);
// Check that all the headers were stored.
List<BlockHeader> stored = syncMgr.syncHeaderRequestManager.matchAndDropHeaders(nodeId, consecutiveHeaders.size(), consecutiveHeaders.get(0).getTxTrieRootWrapper());
assertThat(stored.size()).isEqualTo(consecutiveHeaders.size());
assertThat(stored).containsAllIn(consecutiveHeaders);
}
use of org.aion.zero.impl.types.BlockHeader in project aion by aionnetwork.
the class AionBlockStore method getListHeadersEndWith.
public List<BlockHeader> getListHeadersEndWith(byte[] hash, long qty) {
if (hash == null || qty < 0) {
return null;
}
lock.lock();
try {
List<Block> blocks = getListBlocksEndWith(hash, qty);
List<BlockHeader> headers = new ArrayList<>(blocks.size());
for (Block b : blocks) {
headers.add(b.getHeader());
}
return headers;
} finally {
lock.unlock();
}
}
use of org.aion.zero.impl.types.BlockHeader in project aion by aionnetwork.
the class SyncMgrTest method testRequestBodies_withOneRequest.
@Test
public void testRequestBodies_withOneRequest() {
BlockHeader header = mock(BlockHeader.class);
when(header.getNumber()).thenReturn(101L);
byte[] hash = Hex.decode("6fd8dae3304a9864f460ec7aec21bc94e14e34876e5dddd0a74d9c68ac7bc9ed");
when(header.getHash()).thenReturn(hash);
when(header.getTxTrieRootWrapper()).thenReturn(EMPTY_TRIE_HASH);
List<BlockHeader> list = new ArrayList<>();
list.add(header);
syncMgr.syncHeaderRequestManager.storeHeaders(1, list);
syncMgr.requestBodies(1, "peer1");
// ensure that 1 request was sent
verify(p2pMgr, times(1)).send(anyInt(), anyString(), any(ReqBlocksBodies.class));
// the list is still stored
assertThat(syncMgr.syncHeaderRequestManager.matchAndDropHeaders(1, 1, EMPTY_TRIE_HASH)).isEqualTo(list);
}
Aggregations