Search in sources :

Example 11 with ByteArrayWrapper

use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.

the class DetailsDataStore method get.

/**
 * Fetches the ContractDetails from the cache, and if it doesn't exist, add
 * to the remove set.
 *
 * @param key
 * @return
 */
public synchronized IContractDetails<DataWord> get(byte[] key) {
    ByteArrayWrapper wrappedKey = wrap(key);
    Optional<byte[]> rawDetails = detailsSrc.get(key);
    // If it doesn't exist in cache or database.
    if (!rawDetails.isPresent()) {
        // If it isn't in removes set, we add it to removes set.
        if (!removes.contains(wrappedKey)) {
            removes.add(wrappedKey);
        }
        return null;
    }
    // Found something from cache or database, return it by decoding it.
    IContractDetails<DataWord> detailsImpl = repoConfig.contractDetailsImpl();
    detailsImpl.setDataSource(storageSrc);
    // We can safely get as we checked
    detailsImpl.decode(rawDetails.get());
    return detailsImpl;
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper) DataWord(org.aion.mcf.vm.types.DataWord)

Example 12 with ByteArrayWrapper

use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.

the class DetailsDataStore method remove.

public synchronized void remove(byte[] key) {
    ByteArrayWrapper wrappedKey = wrap(key);
    detailsSrc.put(key, null);
    removes.add(wrappedKey);
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Example 13 with ByteArrayWrapper

use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.

the class AbstractDatabaseWithCache method deleteBatch.

@Override
public void deleteBatch(Collection<byte[]> keys) {
    AbstractDB.check(keys);
    // acquire write lock
    lock.writeLock().lock();
    try {
        check();
        for (byte[] k : keys) {
            ByteArrayWrapper key = ByteArrayWrapper.wrap(k);
            this.loadingCache.put(key, Optional.empty());
            // keeping track of dirty data
            this.dirtyEntries.put(key, null);
        }
        if (enableAutoCommit) {
            flushInternal();
        }
    } finally {
        // releasing write lock
        lock.writeLock().unlock();
    }
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Example 14 with ByteArrayWrapper

use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.

the class AbstractDatabaseWithCache method putBatch.

@Override
public void putBatch(Map<byte[], byte[]> inputMap) {
    AbstractDB.check(inputMap.keySet());
    // acquire write lock
    lock.writeLock().lock();
    try {
        check();
        for (Map.Entry<byte[], byte[]> entry : inputMap.entrySet()) {
            ByteArrayWrapper key = ByteArrayWrapper.wrap(entry.getKey());
            byte[] value = entry.getValue();
            this.loadingCache.put(key, Optional.ofNullable(value));
            // keeping track of dirty data
            this.dirtyEntries.put(key, value);
        }
        if (enableAutoCommit) {
            flushInternal();
        }
    } finally {
        // releasing write lock
        lock.writeLock().unlock();
    }
}
Also used : ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper)

Example 15 with ByteArrayWrapper

use of org.aion.base.util.ByteArrayWrapper in project aion by aionnetwork.

the class AbstractTxPool method updateFeeMap.

protected void updateFeeMap() {
    for (Entry<Address, List<PoolState>> e : this.poolStateView.entrySet()) {
        ByteArrayWrapper dependTx = null;
        for (PoolState ps : e.getValue()) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("updateFeeMap addr[{}] inFp[{}] fn[{}] cb[{}] fee[{}]", e.getKey().toString(), ps.isInFeePool(), ps.getFirstNonce().toString(), ps.getCombo(), ps.getFee().toString());
            }
            if (ps.isInFeePool()) {
                dependTx = this.accountView.get(e.getKey()).getMap().get(ps.getFirstNonce()).getKey();
                if (LOG.isTraceEnabled()) {
                    LOG.trace("updateFeeMap isInFeePool [{}]", dependTx.toString());
                }
            } else {
                TxDependList<ByteArrayWrapper> txl = new TxDependList<>();
                for (BigInteger i = ps.firstNonce; i.compareTo(ps.firstNonce.add(BigInteger.valueOf(ps.combo))) < 0; i = i.add(BigInteger.ONE)) {
                    txl.addTx(this.accountView.get(e.getKey()).getMap().get(i).getKey());
                }
                if (!txl.isEmpty()) {
                    txl.setDependTx(dependTx);
                    dependTx = txl.getTxList().get(0);
                    txl.setAddress(e.getKey());
                }
                if (this.feeView.get(ps.fee) == null) {
                    Map<ByteArrayWrapper, TxDependList<ByteArrayWrapper>> set = new LinkedHashMap<>();
                    set.put(txl.getTxList().get(0), txl);
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("updateFeeMap new feeView put fee[{}]", ps.fee);
                    }
                    this.feeView.put(ps.fee, set);
                } else {
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("updateFeeMap update feeView put fee[{}]", ps.fee);
                    }
                    Map<ByteArrayWrapper, TxDependList<ByteArrayWrapper>> preset = this.feeView.get(ps.fee);
                    preset.put(txl.getTxList().get(0), txl);
                    this.feeView.put(ps.fee, preset);
                }
                ps.setInFeePool();
            }
        }
    }
}
Also used : Address(org.aion.base.type.Address) ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper) BigInteger(java.math.BigInteger)

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