diff --git a/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java b/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java index 58824e11f2..72e55d1b0a 100644 --- a/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java +++ b/modAionImpl/src/org/aion/zero/impl/db/AionRepositoryImpl.java @@ -115,7 +115,7 @@ public TransactionStore<AionTransaction, AionTxReceipt, AionTxInfo> getTransacti } private Trie createStateTrie() { - return new SecureTrie(stateDatabase).withPruningEnabled(pruneBlockCount >= 0); + return new SecureTrie(stateDSPrune).withPruningEnabled(pruneBlockCount >= 0); } @Override @@ -501,34 +501,31 @@ public void commitBlock(A0BlockHeader blockHeader) { worldState.sync(); detailsDS.syncLargeStorage(); - // temporarily removed since never used - /* if (pruneBlockCount >= 0) { - stateDSPrune.storeBlockChanges(blockHeader); - detailsDS.getStorageDSPrune().storeBlockChanges(blockHeader); - pruneBlocks(blockHeader); - } */ + if (pruneBlockCount >= 0) { + stateDSPrune.storeBlockChanges(blockHeader); + detailsDS.getStorageDSPrune().storeBlockChanges(blockHeader); + pruneBlocks(blockHeader); + } } finally { rwLock.writeLock().unlock(); } } - // TODO-AR: reenable state pruning - // temporarily removed since never used - /* private void pruneBlocks(A0BlockHeader curBlock) { - if (curBlock.getNumber() > bestBlockNumber) { // pruning only on - // increasing blocks + private void pruneBlocks(A0BlockHeader curBlock) { + if (curBlock.getNumber() > bestBlockNumber) { + // pruning only on increasing blocks long pruneBlockNumber = curBlock.getNumber() - pruneBlockCount; if (pruneBlockNumber >= 0) { byte[] pruneBlockHash = blockStore.getBlockHashByNumber(pruneBlockNumber); if (pruneBlockHash != null) { A0BlockHeader header = blockStore.getBlockByHash(pruneBlockHash).getHeader(); - // stateDSPrune.prune(header); - // detailsDS.getStorageDSPrune().prune(header); + stateDSPrune.prune(header); + detailsDS.getStorageDSPrune().prune(header); } } } bestBlockNumber = curBlock.getNumber(); - } */ + } public Trie getWorldState() { return worldState; @@ -543,7 +540,7 @@ public IRepository getSnapshotTo(byte[] root) { repo.blockStore = blockStore; repo.cfg = cfg; repo.stateDatabase = this.stateDatabase; - // repo.stateDSPrune = this.stateDSPrune; + repo.stateDSPrune = this.stateDSPrune; repo.pruneBlockCount = this.pruneBlockCount; repo.detailsDS = this.detailsDS; repo.isSnapshot = true; diff --git a/modMcf/src/org/aion/mcf/db/AbstractRepository.java b/modMcf/src/org/aion/mcf/db/AbstractRepository.java index 9125791d61..c6ae945010 100644 --- a/modMcf/src/org/aion/mcf/db/AbstractRepository.java +++ b/modMcf/src/org/aion/mcf/db/AbstractRepository.java @@ -48,7 +48,7 @@ import static org.aion.db.impl.DatabaseFactory.Props; //import org.aion.dbmgr.exception.DriverManagerNoSuitableDriverRegisteredException; -// import org.aion.mcf.trie.JournalPruneDataSource; +import org.aion.mcf.trie.JournalPruneDataSource; /** * Abstract Repository class. @@ -94,7 +94,7 @@ public abstract class AbstractRepository<BLK extends AbstractBlock<BH, ? extends protected Collection<IByteArrayKeyValueDatabase> databaseGroup; - // protected JournalPruneDataSource<BLK, BH> stateDSPrune; + protected JournalPruneDataSource<BLK, BH> stateDSPrune; protected DetailsDataStore<BLK, BH> detailsDS; // Read Write Lock @@ -241,9 +241,7 @@ protected void initializeDatabasesAndCaches() throws Exception { // Setup the cache for transaction data source. this.detailsDS = new DetailsDataStore<>(detailsDatabase, storageDatabase, this.cfg); - // disabling use of JournalPruneDataSource until functionality properly tested - // TODO-AR: enable pruning with the JournalPruneDataSource - // stateDSPrune = new JournalPruneDataSource<>(stateDatabase); + stateDSPrune = new JournalPruneDataSource<>(stateDatabase); pruneBlockCount = pruneEnabled ? this.cfg.getPrune() : -1; } catch (Exception e) { // Setting up databases and caches went wrong. throw e; diff --git a/modMcf/src/org/aion/mcf/db/DetailsDataStore.java b/modMcf/src/org/aion/mcf/db/DetailsDataStore.java index dd01eee23c..c97997f95f 100644 --- a/modMcf/src/org/aion/mcf/db/DetailsDataStore.java +++ b/modMcf/src/org/aion/mcf/db/DetailsDataStore.java @@ -27,6 +27,7 @@ import org.aion.base.type.IBlockHeader; import org.aion.base.type.ITransaction; import org.aion.base.util.ByteArrayWrapper; +import org.aion.mcf.trie.JournalPruneDataSource; import org.aion.mcf.types.AbstractBlock; import org.aion.mcf.vm.types.DataWord; @@ -34,14 +35,12 @@ import static org.aion.base.util.ByteArrayWrapper.wrap; -// import org.aion.mcf.trie.JournalPruneDataSource; - /** * Detail data storage , */ public class DetailsDataStore<BLK extends AbstractBlock<BH, ? extends ITransaction>, BH extends IBlockHeader> { - // private JournalPruneDataSource<BLK, BH> storageDSPrune; + private JournalPruneDataSource<BLK, BH> storageDSPrune; private IRepositoryConfig repoConfig; private IByteArrayKeyValueDatabase detailsSrc; @@ -62,7 +61,7 @@ public DetailsDataStore<BLK, BH> withDb(IByteArrayKeyValueDatabase detailsSrc, IByteArrayKeyValueDatabase storageSrc) { this.detailsSrc = detailsSrc; this.storageSrc = storageSrc; - // this.storageDSPrune = new JournalPruneDataSource<>(storageSrc); + this.storageDSPrune = new JournalPruneDataSource<>(storageSrc); return this; } @@ -91,7 +90,7 @@ public synchronized IContractDetails<DataWord> get(byte[] key) { // Found something from cache or database, return it by decoding it. IContractDetails<DataWord> detailsImpl = repoConfig.contractDetailsImpl(); - detailsImpl.setDataSource(storageSrc); + detailsImpl.setDataSource(storageDSPrune); detailsImpl.decode(rawDetails.get()); // We can safely get as we checked // if it is present. @@ -162,7 +161,7 @@ public void syncLargeStorage() { // Decode the details. IContractDetails<DataWord> detailsImpl = repoConfig.contractDetailsImpl(); - detailsImpl.setDataSource(storageSrc); + detailsImpl.setDataSource(storageDSPrune); detailsImpl.decode(rawDetails.get()); // We can safely get as we // checked if it is present. @@ -171,9 +170,9 @@ public void syncLargeStorage() { } } - /* public JournalPruneDataSource<BLK, BH> getStorageDSPrune() { + public JournalPruneDataSource<BLK, BH> getStorageDSPrune() { return storageDSPrune; - } */ + } public synchronized Set<ByteArrayWrapper> keys() { // TODO - @yao do we wanted a sorted set? diff --git a/modMcf/src/org/aion/mcf/trie/Cache.java b/modMcf/src/org/aion/mcf/trie/Cache.java index e0235d5df5..cc52f5f5fb 100644 --- a/modMcf/src/org/aion/mcf/trie/Cache.java +++ b/modMcf/src/org/aion/mcf/trie/Cache.java @@ -164,9 +164,9 @@ public synchronized void commit(boolean flushCache) { // batchMemorySize += length(key, value); } } - /* for (ByteArrayWrapper removedNode : removedNodes) { + for (ByteArrayWrapper removedNode : removedNodes) { batch.put(removedNode.getData(), null); - } */ + } this.dataSource.putBatch(batch); this.isDirty = false;