use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class TrieTest method getSampleTrieUpdates.
/**
* Trie updates taken from real blockchain use with sample accounts.
*/
private Map<ByteArrayWrapper, byte[]> getSampleTrieUpdates() {
Map<ByteArrayWrapper, byte[]> data = new HashMap<>();
ByteArrayWrapper key;
byte[] value;
key = ByteArrayWrapper.wrap(new byte[] { -96, 29, -93, -108, -55, -59, 67, -121, -3, 10, 44, -128, -127, 73, 90, -26, 3, 62, 55, -60, -82, -11, -96, -54, 106, 114, 42, 70, 46, 31, 37, 29 });
value = new byte[] { -8, 78, -128, -118, -45, -62, 27, -50, -52, -19, -95, 0, 0, 0, -96, 69, -80, -49, -62, 32, -50, -20, 91, 124, 28, 98, -60, -44, 25, 61, 56, -28, -21, -92, -114, -120, 21, 114, -100, -25, 95, -100, 10, -80, -28, -63, -64, -96, 14, 87, 81, -64, 38, -27, 67, -78, -24, -85, 46, -80, 96, -103, -38, -95, -47, -27, -33, 71, 119, -113, 119, -121, -6, -85, 69, -51, -15, 47, -29, -88 };
data.put(key, value);
key = ByteArrayWrapper.wrap(new byte[] { -96, 44, -96, -3, -97, 10, 112, 111, 28, -32, 44, 18, 101, -106, 51, 6, -107, 0, 24, 13, 50, 81, -84, 68, 125, 110, 118, 97, -109, -96, -30, 107 });
value = new byte[] { -8, 78, -128, -118, -45, -62, 27, -50, -52, -19, -95, 0, 0, 0, -96, 69, -80, -49, -62, 32, -50, -20, 91, 124, 28, 98, -60, -44, 25, 61, 56, -28, -21, -92, -114, -120, 21, 114, -100, -25, 95, -100, 10, -80, -28, -63, -64, -96, 14, 87, 81, -64, 38, -27, 67, -78, -24, -85, 46, -80, 96, -103, -38, -95, -47, -27, -33, 71, 119, -113, 119, -121, -6, -85, 69, -51, -15, 47, -29, -88 };
data.put(key, value);
key = ByteArrayWrapper.wrap(new byte[] { -96, 53, 87, -10, 21, -118, 120, -87, 69, -83, 111, 41, -26, -81, 41, -82, -90, -108, -59, -19, -60, 87, -98, -88, 50, -127, 89, -11, -56, 114, -113, 27 });
value = new byte[] { -8, 78, -128, -118, -45, -62, 27, -50, -52, -19, -95, 0, 0, 0, -96, 69, -80, -49, -62, 32, -50, -20, 91, 124, 28, 98, -60, -44, 25, 61, 56, -28, -21, -92, -114, -120, 21, 114, -100, -25, 95, -100, 10, -80, -28, -63, -64, -96, 14, 87, 81, -64, 38, -27, 67, -78, -24, -85, 46, -80, 96, -103, -38, -95, -47, -27, -33, 71, 119, -113, 119, -121, -6, -85, 69, -51, -15, 47, -29, -88 };
data.put(key, value);
key = ByteArrayWrapper.wrap(new byte[] { -96, -118, 43, 113, -6, -115, 90, 79, -76, -32, -70, -7, -91, -98, 70, 111, 32, 97, 96, 55, -119, -89, 64, -34, -92, 94, 1, 58, -61, 63, 102, -92 });
value = new byte[] { -8, 78, -128, -118, -45, -62, 27, -50, -52, -19, -95, 0, 0, 0, -96, 69, -80, -49, -62, 32, -50, -20, 91, 124, 28, 98, -60, -44, 25, 61, 56, -28, -21, -92, -114, -120, 21, 114, -100, -25, 95, -100, 10, -80, -28, -63, -64, -96, 14, 87, 81, -64, 38, -27, 67, -78, -24, -85, 46, -80, 96, -103, -38, -95, -47, -27, -33, 71, 119, -113, 119, -121, -6, -85, 69, -51, -15, 47, -29, -88 };
data.put(key, value);
return data;
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class TrieTest method testGetMissingNodes_wIncompleteTrie.
@Test
public void testGetMissingNodes_wIncompleteTrie() {
MockDB mockDB = new MockDB("temp", log);
mockDB.open();
TrieImpl trie = new TrieImpl(mockDB);
for (Map.Entry<ByteArrayWrapper, byte[]> e : getSampleTrieUpdates().entrySet()) {
trie.update(e.getKey().toBytes(), e.getValue());
}
trie.getCache().commitForTest();
byte[] root = trie.getRootHash();
// System.out.println(trie.getTrieDump(root));
// removing two of the nodes from the trie
Set<ByteArrayWrapper> expected = new HashSet<>();
expected.add(ByteArrayWrapper.wrap(Hex.decode("59c2a26cebd0ed50053bba185a7d13e1ae58314e2c37d46c1f7b885fd93b687a")));
expected.add(ByteArrayWrapper.wrap(Hex.decode("ddf1b495a3e98e1897a9b1257d4172d59fcbe0dba23b8b87812ca2a55919d9ab")));
for (ByteArrayWrapper key : expected) {
mockDB.deleteAndCommit(key.toBytes());
}
trie = new TrieImpl(mockDB);
Set<ByteArrayWrapper> missing = trie.getMissingNodes(root);
assertThat(missing).hasSize(2);
assertThat(missing).isEqualTo(expected);
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class TrieTest method testGetMissingNodes_wIncompleteTrie_wStartFromValue.
@Test
public void testGetMissingNodes_wIncompleteTrie_wStartFromValue() {
MockDB mockDB = new MockDB("temp", log);
mockDB.open();
TrieImpl trie = new TrieImpl(mockDB);
for (Map.Entry<ByteArrayWrapper, byte[]> e : getSampleTrieUpdates().entrySet()) {
trie.update(e.getKey().toBytes(), e.getValue());
}
trie.getCache().commitForTest();
byte[] root = trie.getRootHash();
// System.out.println(trie.getTrieDump(root));
byte[] value = mockDB.get(root).get();
// removing two of the nodes from the trie
Set<ByteArrayWrapper> expected = new HashSet<>();
expected.add(ByteArrayWrapper.wrap(Hex.decode("59c2a26cebd0ed50053bba185a7d13e1ae58314e2c37d46c1f7b885fd93b687a")));
expected.add(ByteArrayWrapper.wrap(Hex.decode("ddf1b495a3e98e1897a9b1257d4172d59fcbe0dba23b8b87812ca2a55919d9ab")));
for (ByteArrayWrapper key : expected) {
mockDB.deleteAndCommit(key.toBytes());
}
trie = new TrieImpl(mockDB);
Set<ByteArrayWrapper> missing = trie.getMissingNodes(value);
assertThat(missing).hasSize(2);
assertThat(missing).isEqualTo(expected);
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class JournalPruneDataSource method prune.
public void prune(ByteArrayWrapper blockHash, long blockNumber) {
if (!enabled.get()) {
return;
}
lock.writeLock().lock();
try {
Updates updates = blockUpdates.remove(blockHash);
if (updates != null) {
for (ByteArrayWrapper insertedKey : updates.insertedKeys) {
decRef(insertedKey).dbRef = true;
}
List<byte[]> batchRemove = new ArrayList<>();
for (ByteArrayWrapper key : updates.deletedKeys) {
Ref ref = refCount.get(key);
if (ref == null || ref.journalRefs == 0) {
batchRemove.add(key.toBytes());
} else if (ref != null) {
ref.dbRef = false;
}
}
src.deleteBatch(batchRemove);
rollbackForkBlocks(blockNumber);
}
} finally {
lock.writeLock().unlock();
}
}
use of org.aion.util.types.ByteArrayWrapper in project aion by aionnetwork.
the class JournalPruneDataSource method rollback.
private void rollback(ByteArrayWrapper blockHashW) {
Updates updates = blockUpdates.remove(blockHashW);
List<byte[]> batchRemove = new ArrayList<>();
for (ByteArrayWrapper insertedKey : updates.insertedKeys) {
Ref ref = decRef(insertedKey);
if (ref.getTotRefs() == 0) {
batchRemove.add(insertedKey.toBytes());
}
}
src.deleteBatch(batchRemove);
}
Aggregations