From 7f6c1f0f8b8314e992ac98b514d82190e96754a6 Mon Sep 17 00:00:00 2001 From: Fausto Spoto Date: Wed, 1 May 2024 18:24:18 +0200 Subject: [PATCH] Clean-up --- .../hotmoka/node/disk/internal/DiskStore.java | 23 ------------------- .../disk/internal/DiskStoreTransaction.java | 11 +++++---- .../tendermint/internal/TendermintStore.java | 17 -------------- .../java/io/hotmoka/stores/AbstractStore.java | 4 ---- .../stores/AbstractStoreTransaction.java | 9 +++++++- .../AbstractTrieBasedStoreTransaction.java | 10 +++----- 6 files changed, 17 insertions(+), 57 deletions(-) diff --git a/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskStore.java b/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskStore.java index 898ac4552..c235526ed 100644 --- a/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskStore.java +++ b/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskStore.java @@ -90,19 +90,6 @@ class DiskStore extends AbstractStore { this.blockNumber = new AtomicInteger(0); } - /** - * Creates a clone of the given store. - * - * @param toClone the store to clone - */ - private DiskStore(DiskStore toClone) { - this.dir = toClone.dir; - this.histories = toClone.histories; - this.errors = toClone.errors; - this.manifest = toClone.manifest; - this.blockNumber = toClone.blockNumber; - } - @Override public Optional getResponse(TransactionReference reference) { try { @@ -158,16 +145,6 @@ public StoreTransaction beginTransaction() { return new DiskStoreTransaction(this); } - @Override - protected DiskStore getThis() { - return this; - } - - @Override - protected DiskStore mkClone() { - return new DiskStore(this); - } - protected void setRequest(int progressive, TransactionReference reference, TransactionRequest request) throws StoreException { try { Path requestPath = getPathFor(progressive, reference, "request"); diff --git a/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskStoreTransaction.java b/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskStoreTransaction.java index 1d82c14fe..d54089ffe 100644 --- a/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskStoreTransaction.java +++ b/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskStoreTransaction.java @@ -14,7 +14,6 @@ import io.hotmoka.stores.StoreException; public class DiskStoreTransaction extends AbstractStoreTransaction { - private final DiskStore store; private final ConcurrentMap> requests = new ConcurrentHashMap<>(); private final ConcurrentMap responses = new ConcurrentHashMap<>(); @@ -36,7 +35,7 @@ public class DiskStoreTransaction extends AbstractStoreTransaction { private final AtomicReference manifest = new AtomicReference<>(); public DiskStoreTransaction(DiskStore store) { - this.store = store; + super(store); } @Override @@ -45,7 +44,7 @@ public Optional getResponseUncommitted(TransactionReference if (uncommittedResponse != null) return Optional.of(uncommittedResponse); else - return store.getResponse(reference); + return getStore().getResponse(reference); } @Override @@ -54,7 +53,7 @@ public Stream getHistoryUncommitted(StorageReference objec if (uncommittedHistory != null) return Stream.of(uncommittedHistory); else - return store.getHistory(object); + return getStore().getHistory(object); } @Override @@ -63,11 +62,13 @@ public Optional getManifestUncommitted() { if (uncommittedManifest != null) return Optional.of(uncommittedManifest); else - return store.getManifest(); + return getStore().getManifest(); } @Override public DiskStore commit() throws StoreException { + var store = getStore(); + // we report all the updates occurred during this transaction into the store var manifest = this.manifest.get(); if (manifest != null) diff --git a/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/internal/TendermintStore.java b/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/internal/TendermintStore.java index d9e8c0fe4..7389074ea 100644 --- a/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/internal/TendermintStore.java +++ b/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/internal/TendermintStore.java @@ -67,13 +67,6 @@ public class TendermintStore extends AbstractTrieBasedStore { } } - private TendermintStore(TendermintStore toClone) { - super(toClone); - - this.nodeInternal = toClone.nodeInternal; - this.hasherOfHashes = toClone.hasherOfHashes; - } - private TendermintStore(TendermintStore toClone, Optional rootOfResponses, Optional rootOfInfo, Optional rootOfErrors, Optional rootOfHistories, Optional rootOfRequests) { super(toClone, rootOfResponses, rootOfInfo, rootOfErrors, rootOfHistories, rootOfRequests); @@ -130,16 +123,6 @@ private byte[] mergeRootsOfTriesWithoutInfo() throws StoreException { return bytes; } - @Override - protected TendermintStore getThis() { - return this; - } - - @Override - protected TendermintStore mkClone() { - return new TendermintStore(this); - } - @Override protected TendermintStore mkClone(Optional rootOfResponses, Optional rootOfInfo, Optional rootOfErrors, Optional rootOfHistories, Optional rootOfRequests) { return new TendermintStore(this, rootOfResponses, rootOfInfo, rootOfErrors, rootOfHistories, rootOfRequests); diff --git a/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractStore.java b/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractStore.java index 8d9cab49d..c211adcf8 100644 --- a/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractStore.java +++ b/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractStore.java @@ -30,10 +30,6 @@ public abstract class AbstractStore> implements Store */ protected AbstractStore() {} - protected abstract T mkClone(); - - protected abstract T getThis(); - @Override public void close() {} } \ No newline at end of file diff --git a/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractStoreTransaction.java b/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractStoreTransaction.java index 419883d2c..bfd2d5937 100644 --- a/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractStoreTransaction.java +++ b/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractStoreTransaction.java @@ -42,8 +42,15 @@ */ public abstract class AbstractStoreTransaction> implements StoreTransaction { private final static Logger LOGGER = Logger.getLogger(AbstractStoreTransaction.class.getName()); + private final T store; - protected AbstractStoreTransaction() {} + protected AbstractStoreTransaction(T store) { + this.store = store; + } + + protected final T getStore() { + return store; + } @Override public final void push(TransactionReference reference, TransactionRequest request, TransactionResponse response) throws StoreException { diff --git a/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractTrieBasedStoreTransaction.java b/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractTrieBasedStoreTransaction.java index a81c82357..5c16afa65 100644 --- a/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractTrieBasedStoreTransaction.java +++ b/io-hotmoka-stores/src/main/java/io/hotmoka/stores/AbstractTrieBasedStoreTransaction.java @@ -22,11 +22,6 @@ public abstract class AbstractTrieBasedStoreTransaction