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;
}
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);
}
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();
}
}
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();
}
}
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();
}
}
}
}
Aggregations