Search in sources :

Example 6 with ByteArrayWrapper

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());
    }
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Example 7 with ByteArrayWrapper

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);
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Example 8 with ByteArrayWrapper

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;
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Example 9 with ByteArrayWrapper

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;
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Example 10 with ByteArrayWrapper

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--;
    }
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Aggregations

ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)45 BigInteger (java.math.BigInteger)10 Address (org.aion.base.type.Address)5 ITransaction (org.aion.base.type.ITransaction)4 Entry (java.util.Map.Entry)3 DataWord (org.aion.mcf.vm.types.DataWord)3 AionBlock (org.aion.zero.impl.types.AionBlock)3 Test (org.junit.Test)3 java.util (java.util)2 SimpleEntry (java.util.AbstractMap.SimpleEntry)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ImportResult (org.aion.mcf.core.ImportResult)2 Value (org.aion.rlp.Value)2 AccountState (org.aion.txpool.common.AccountState)2 TxDependList (org.aion.txpool.common.TxDependList)2 AionTxReceipt (org.aion.zero.types.AionTxReceipt)2