From 2230019f7afb18215cda99860a7d290d9046c487 Mon Sep 17 00:00:00 2001 From: Alexandra Roatis Date: Wed, 9 Oct 2019 16:29:23 -0400 Subject: [PATCH] Switched transaction storage to an overwrite policy: - the ability to overwrite previously stored transaction information is necessary to apply config updates to store internal transactions or not to store them; - removed caching optimization: not particularly useful; - removed unused return value for putTxInfoToBatch method. --- .../aion/zero/impl/db/TransactionStore.java | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/modAionImpl/src/org/aion/zero/impl/db/TransactionStore.java b/modAionImpl/src/org/aion/zero/impl/db/TransactionStore.java index d7f6889b41..e81633d1bd 100644 --- a/modAionImpl/src/org/aion/zero/impl/db/TransactionStore.java +++ b/modAionImpl/src/org/aion/zero/impl/db/TransactionStore.java @@ -1,7 +1,5 @@ package org.aion.zero.impl.db; -import static org.aion.util.others.Utils.dummy; - import java.io.Closeable; import java.io.IOException; import java.util.HashMap; @@ -17,45 +15,35 @@ import org.aion.types.InternalTransaction; import org.aion.util.types.ByteArrayWrapper; import org.aion.zero.impl.types.AionTxInfo; -import org.apache.commons.collections4.map.LRUMap; public class TransactionStore implements Closeable { - private final LRUMap lastSavedTxHash = new LRUMap<>(5000); private final ObjectStore> txInfoSource; private final ObjectStore> aliasSource; private final ReadWriteLock lock = new ReentrantReadWriteLock(); public TransactionStore(ByteArrayKeyValueDatabase txInfoSrc, Serializer> serializer) { + // TODO AKI-436: introduce caching of recent transactions txInfoSource = Stores.newObjectStore(txInfoSrc, serializer); aliasSource = Stores.newObjectStore(txInfoSrc, aliasSerializer); } - public boolean putTxInfoToBatch(AionTxInfo tx) { + public void putTxInfoToBatch(AionTxInfo tx) { lock.writeLock().lock(); try { byte[] txHash = tx.getReceipt().getTransaction().getTransactionHash(); - Map existingInfos = null; - if (lastSavedTxHash.put(ByteArrayWrapper.wrap(txHash), dummy) != null - || !lastSavedTxHash.isFull()) { - existingInfos = txInfoSource.get(txHash); - } - + Map existingInfos = txInfoSource.get(txHash); if (existingInfos == null) { existingInfos = new HashMap<>(); - } else { - // TODO: switch to an overwrite policy - if (existingInfos.containsKey(tx.blockHash)) { - return false; - } } + + // overwrites existing entry to update it with/without internal transactions + // depending on the chosen configuration at block import existingInfos.put(tx.blockHash, tx); txInfoSource.putToBatch(txHash, existingInfos); - - return true; } finally { lock.writeLock().unlock(); }