use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.
the class JournalPruneDataSource method prune.
public synchronized void prune(BH header) {
if (!enabled) {
return;
}
ByteArrayWrapper blockHashW = new ByteArrayWrapper(header.getHash());
Updates updates = blockUpdates.remove(blockHashW);
if (updates != null) {
for (ByteArrayWrapper insertedKey : updates.insertedKeys) {
decRef(insertedKey).dbRef = true;
}
Map<byte[], byte[]> batchRemove = new HashMap<>();
for (ByteArrayWrapper key : updates.deletedKeys) {
Ref ref = refCount.get(key);
if (ref == null || ref.journalRefs == 0) {
batchRemove.put(key.getData(), null);
} else if (ref != null) {
ref.dbRef = false;
}
}
src.putBatch(batchRemove);
rollbackForkBlocks(header.getNumber());
}
}
use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.
the class JournalPruneDataSource method rollback.
private synchronized void rollback(BH header) {
ByteArrayWrapper blockHashW = new ByteArrayWrapper(header.getHash());
Updates updates = blockUpdates.remove(blockHashW);
Map<byte[], byte[]> batchRemove = new HashMap<>();
for (ByteArrayWrapper insertedKey : updates.insertedKeys) {
Ref ref = decRef(insertedKey);
if (ref.getTotRefs() == 0) {
batchRemove.put(insertedKey.getData(), null);
}
}
src.putBatch(batchRemove);
}
use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.
the class RLP method encodeSet.
public static byte[] encodeSet(Set<ByteArrayWrapper> data) {
int dataLength = 0;
for (ByteArrayWrapper element : data) {
// byte[] encodedElement = element.getEncodedData();
byte[] encodedElement = RLP.encodeElement(element.getData());
dataLength += encodedElement.length;
}
byte[] listHeader = encodeListHeader(dataLength);
byte[] output = new byte[listHeader.length + dataLength];
System.arraycopy(listHeader, 0, output, 0, listHeader.length);
int cummStart = listHeader.length;
for (ByteArrayWrapper element : data) {
byte[] encodedData = RLP.encodeElement(element.getData());
System.arraycopy(encodedData, 0, output, cummStart, encodedData.length);
cummStart += encodedData.length;
}
return output;
}
use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.
the class AbstractSyncQueue method addHeaderPriv.
protected boolean addHeaderPriv(BHW header) {
long num = header.getNumber();
Map<ByteArrayWrapper, HeaderElement<BLK, BHW>> genHeaders = headers.get(num);
if (genHeaders == null) {
genHeaders = new HashMap<>();
putGenHeaders(num, genHeaders);
}
ByteArrayWrapper wHash = new ByteArrayWrapper(header.getHash());
HeaderElement<BLK, BHW> headerElement = genHeaders.get(wHash);
if (headerElement != null) {
return false;
}
headerElement = new HeaderElement<BLK, BHW>();
headerElement.header = header;
genHeaders.put(wHash, headerElement);
return true;
}
use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.
the class AbstractSyncQueue method trimChain.
protected void trimChain() {
List<HeaderElement<BLK, BHW>> longestChain = getLongestChain();
if (longestChain.size() > MAX_CHAIN_LEN) {
long newTrimNum = getLongestChain().get(longestChain.size() - MAX_CHAIN_LEN).header.getNumber();
for (int i = 0; darkZoneNum < newTrimNum; darkZoneNum++, i++) {
ByteArrayWrapper wHash = new ByteArrayWrapper(longestChain.get(i).header.getHash());
putGenHeaders(darkZoneNum, Collections.singletonMap(wHash, longestChain.get(i)));
}
darkZoneNum--;
}
}
Aggregations