diff --git a/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/InitDisk.java b/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/InitDisk.java index 6424d1724..3b2e9b28f 100644 --- a/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/InitDisk.java +++ b/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/InitDisk.java @@ -130,9 +130,9 @@ private Run() throws Exception { .setPublicKeyOfGamete(signature.publicKeyFromEncoding(Base58.decode(keyOfGamete))) .build(); - try (var node = this.node = DiskNodes.init(nodeConfig, consensus); + try (var node = this.node = DiskNodes.init(nodeConfig); var initialized = this.initialized = InitializedNodes.of(node, consensus, - Paths.get(takamakaCode.replace("TAKAMAKA-VERSION", Constants.TAKAMAKA_VERSION))); + Paths.get(takamakaCode.replace("TAKAMAKA-VERSION", Constants.TAKAMAKA_VERSION))); var service = NodeServices.of(node, port)) { printManifest(); diff --git a/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/InitTendermint.java b/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/InitTendermint.java index 076c26a48..fd1352017 100644 --- a/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/InitTendermint.java +++ b/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/InitTendermint.java @@ -167,7 +167,7 @@ private Run() throws Exception { .setPublicKeyOfGamete(signature.publicKeyFromEncoding(Base58.decode(keyOfGamete))) .build(); - try (var node = TendermintNodes.init(nodeConfig, consensus); + try (var node = TendermintNodes.init(nodeConfig); var initialized = this.initialized = TendermintInitializedNodes.of(node, consensus, Paths.get(takamakaCode.replace("TAKAMAKA-VERSION", Constants.TAKAMAKA_VERSION))); var service = NodeServices.of(initialized, port)) { diff --git a/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/StartTendermint.java b/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/StartTendermint.java index 658d9ca39..cfd5399e5 100644 --- a/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/StartTendermint.java +++ b/io-hotmoka-moka/src/main/java/io/hotmoka/moka/internal/StartTendermint.java @@ -23,7 +23,6 @@ import java.nio.file.Path; import java.util.Comparator; -import io.hotmoka.node.ValidatorsConsensusConfigBuilders; import io.hotmoka.node.service.NodeServices; import io.hotmoka.node.tendermint.TendermintNodeConfigBuilders; import io.hotmoka.node.tendermint.TendermintNodes; @@ -69,10 +68,7 @@ private Run() throws Exception { .setDir(dir) .build(); - var consensus = ValidatorsConsensusConfigBuilders.defaults() - .build(); - - try (var node = TendermintNodes.init(nodeConfig, consensus); var service = NodeServices.of(node, port)) { + try (var node = TendermintNodes.init(nodeConfig); var service = NodeServices.of(node, port)) { cleanUp(); printBanner(); waitForEnterKey(); diff --git a/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/DiskNodes.java b/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/DiskNodes.java index 76d8421d2..c842c594b 100644 --- a/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/DiskNodes.java +++ b/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/DiskNodes.java @@ -18,7 +18,6 @@ import io.hotmoka.annotations.ThreadSafe; import io.hotmoka.node.api.NodeException; -import io.hotmoka.node.api.nodes.ConsensusConfig; import io.hotmoka.node.disk.api.DiskNode; import io.hotmoka.node.disk.api.DiskNodeConfig; import io.hotmoka.node.disk.internal.DiskNodeImpl; @@ -38,12 +37,11 @@ private DiskNodes() {} * Creates a brand new node whose store is kept in disk memory. * * @param config the configuration of the node - * @param consensus the consensus configuration of the node * @return the node * @throws NodeException if the operation cannot be completed correctly * @throws InterruptedException if the current thread is interrupted before completing the operation */ - public static DiskNode init(DiskNodeConfig config, ConsensusConfig consensus) throws NodeException, InterruptedException { - return new DiskNodeImpl(config, consensus); + public static DiskNode init(DiskNodeConfig config) throws NodeException, InterruptedException { + return new DiskNodeImpl(config); } } \ No newline at end of file diff --git a/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskNodeImpl.java b/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskNodeImpl.java index 66f9a7f49..4cf520177 100644 --- a/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskNodeImpl.java +++ b/io-hotmoka-node-disk/src/main/java/io/hotmoka/node/disk/internal/DiskNodeImpl.java @@ -16,7 +16,6 @@ package io.hotmoka.node.disk.internal; -import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeoutException; @@ -26,7 +25,6 @@ import io.hotmoka.node.NodeInfos; import io.hotmoka.node.api.NodeException; import io.hotmoka.node.api.TransactionRejectedException; -import io.hotmoka.node.api.nodes.ConsensusConfig; import io.hotmoka.node.api.nodes.NodeInfo; import io.hotmoka.node.api.requests.TransactionRequest; import io.hotmoka.node.disk.api.DiskNode; @@ -49,15 +47,14 @@ public class DiskNodeImpl extends AbstractLocalNode consensus) throws NodeException, InterruptedException { - super(Optional.of(consensus), config); + public DiskNodeImpl(DiskNodeConfig config) throws NodeException, InterruptedException { + super(config, true); try { initWithEmptyStore(); diff --git a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/AbstractCheckableLocalNode.java b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/AbstractCheckableLocalNode.java index f2a208d7b..c0691601a 100644 --- a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/AbstractCheckableLocalNode.java +++ b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/AbstractCheckableLocalNode.java @@ -16,11 +16,8 @@ package io.hotmoka.node.local; -import java.util.Optional; - import io.hotmoka.annotations.ThreadSafe; import io.hotmoka.node.api.NodeException; -import io.hotmoka.node.api.nodes.ConsensusConfig; import io.hotmoka.node.local.api.CheckableStore; import io.hotmoka.node.local.api.LocalNodeConfig; import io.hotmoka.node.local.internal.AbstractCheckableLocalNodeImpl; @@ -38,12 +35,11 @@ public abstract class AbstractCheckableLocalNode, /** * Creates a new node. * - * @param consensus the consensus configuration of the node; if missing, this will be extracted - * from the saved state of the node * @param config the configuration of the node + * @param init if true, the working directory of the node gets initialized * @throws NodeException if the operation cannot be completed correctly */ - protected AbstractCheckableLocalNode(Optional> consensus, C config) throws NodeException { - super(consensus, config); + protected AbstractCheckableLocalNode(C config, boolean init) throws NodeException { + super(config, init); } } \ No newline at end of file diff --git a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/AbstractLocalNode.java b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/AbstractLocalNode.java index 634c69324..f6f5903fa 100644 --- a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/AbstractLocalNode.java +++ b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/AbstractLocalNode.java @@ -16,11 +16,8 @@ package io.hotmoka.node.local; -import java.util.Optional; - import io.hotmoka.annotations.ThreadSafe; import io.hotmoka.node.api.NodeException; -import io.hotmoka.node.api.nodes.ConsensusConfig; import io.hotmoka.node.local.api.LocalNodeConfig; import io.hotmoka.node.local.internal.AbstractLocalNodeImpl; @@ -38,12 +35,11 @@ public abstract class AbstractLocalNode, S extend /** * Creates a node. * - * @param consensus the consensus configuration of the node; if missing, this will be extracted - * from the saved state of the node * @param config the local configuration of the node + * @param init if true, the working directory of the node gets initialized * @throws NodeException if the node could not be created */ - protected AbstractLocalNode(Optional> consensus, C config) throws NodeException { - super(consensus, config); + protected AbstractLocalNode(C config, boolean init) throws NodeException { + super(config, init); } } \ No newline at end of file diff --git a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/AbstractCheckableLocalNodeImpl.java b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/AbstractCheckableLocalNodeImpl.java index 7ae7e9602..4fe4fa96a 100644 --- a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/AbstractCheckableLocalNodeImpl.java +++ b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/AbstractCheckableLocalNodeImpl.java @@ -25,7 +25,6 @@ import io.hotmoka.annotations.ThreadSafe; import io.hotmoka.crypto.Hex; import io.hotmoka.node.api.NodeException; -import io.hotmoka.node.api.nodes.ConsensusConfig; import io.hotmoka.node.local.AbstractLocalNode; import io.hotmoka.node.local.AbstractStore; import io.hotmoka.node.local.AbstractStoreTranformation; @@ -79,13 +78,12 @@ public abstract class AbstractCheckableLocalNodeImpl> consensus, C config) throws NodeException { - super(consensus, config); + protected AbstractCheckableLocalNodeImpl(C config, boolean init) throws NodeException { + super(config, init); this.env = new Environment(config.getDir() + "/node"); this.storeOfNode = env.computeInTransaction(txn -> env.openStoreWithoutDuplicates("node", txn)); diff --git a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/AbstractLocalNodeImpl.java b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/AbstractLocalNodeImpl.java index ab19db357..975806ebc 100644 --- a/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/AbstractLocalNodeImpl.java +++ b/io-hotmoka-node-local/src/main/java/io/hotmoka/node/local/internal/AbstractLocalNodeImpl.java @@ -165,12 +165,11 @@ public abstract class AbstractLocalNodeImpl, S ex /** * Creates a new node. * - * @param consensus the consensus configuration of the node; if missing, this will be extracted - * from the saved state of the node * @param config the configuration of the node + * @param init if true, the working directory of the node gets initialized * @throws NodeException if the operation cannot be completed correctly */ - protected AbstractLocalNodeImpl(Optional> consensus, C config) throws NodeException { + protected AbstractLocalNodeImpl(C config, boolean init) throws NodeException { super(ClosedNodeException::new); this.config = config; @@ -184,7 +183,7 @@ protected AbstractLocalNodeImpl(Optional> consensus, C conf throw new NodeException(e); } - if (consensus.isPresent()) + if (init) initWorkingDirectory(); this.executors = Executors.newCachedThreadPool(); diff --git a/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/TendermintNodes.java b/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/TendermintNodes.java index 4de238a4c..412a999e5 100644 --- a/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/TendermintNodes.java +++ b/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/TendermintNodes.java @@ -16,10 +16,7 @@ package io.hotmoka.node.tendermint; -import java.util.Optional; - import io.hotmoka.node.api.NodeException; -import io.hotmoka.node.api.nodes.ValidatorsConsensusConfig; import io.hotmoka.node.tendermint.api.TendermintNode; import io.hotmoka.node.tendermint.api.TendermintNodeConfig; import io.hotmoka.node.tendermint.internal.TendermintNodeImpl; @@ -36,16 +33,12 @@ private TendermintNodes() {} * It spawns the Tendermint process and connects it to an ABCI application for handling its transactions. * * @param config the configuration of the blockchain - * @param consensus the consensus parameters at the beginning of the life of the blockchain; - * when creating a node that starts synchronization with an already - * existing network, these must be the parameters at the beginning of the - * history of the network * @return the Tendermint node * @throws InterruptedException if the current thread is interrupted before completing the operation * @throws NodeException if the operation cannot be completed correctly */ - public static TendermintNode init(TendermintNodeConfig config, ValidatorsConsensusConfig consensus) throws NodeException, InterruptedException { - return new TendermintNodeImpl(config, Optional.of(consensus)); + public static TendermintNode init(TendermintNodeConfig config) throws NodeException, InterruptedException { + return new TendermintNodeImpl(config, true); } /** @@ -60,6 +53,6 @@ public static TendermintNode init(TendermintNodeConfig config, ValidatorsConsens * @throws NodeException if the operation cannot be completed correctly */ public static TendermintNode resume(TendermintNodeConfig config) throws NodeException, InterruptedException { - return new TendermintNodeImpl(config, Optional.empty()); + return new TendermintNodeImpl(config, false); } } \ No newline at end of file diff --git a/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/internal/TendermintNodeImpl.java b/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/internal/TendermintNodeImpl.java index 935cf67c1..b078a6ed7 100644 --- a/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/internal/TendermintNodeImpl.java +++ b/io-hotmoka-node-tendermint/src/main/java/io/hotmoka/node/tendermint/internal/TendermintNodeImpl.java @@ -40,7 +40,6 @@ import io.hotmoka.node.NodeInfos; import io.hotmoka.node.api.NodeException; import io.hotmoka.node.api.TransactionRejectedException; -import io.hotmoka.node.api.nodes.ConsensusConfig; import io.hotmoka.node.api.nodes.NodeInfo; import io.hotmoka.node.api.requests.TransactionRequest; import io.hotmoka.node.local.AbstractCheckableLocalNode; @@ -85,18 +84,17 @@ public class TendermintNodeImpl extends AbstractCheckableLocalNode> consensus) throws NodeException, InterruptedException { - super(consensus, config); + public TendermintNodeImpl(TendermintNodeConfig config, boolean init) throws NodeException, InterruptedException { + super(config, init); this.isWindows = System.getProperty("os.name").startsWith("Windows"); try { - if (consensus.isPresent()) { + if (init) { initWithEmptyStore(); initWorkingDirectoryOfTendermintProcess(config); } diff --git a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/HotmokaTest.java b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/HotmokaTest.java index 61c81d203..8bec8a56a 100644 --- a/io-hotmoka-tests/src/test/java/io/hotmoka/tests/HotmokaTest.java +++ b/io-hotmoka-tests/src/test/java/io/hotmoka/tests/HotmokaTest.java @@ -252,8 +252,7 @@ private static void initializeNodeIfNeeded(Node node) throws TransactionRejected @SuppressWarnings("unused") private static Node mkTendermintBlockchain() throws NodeException, InterruptedException { try { - var consensus = fillConsensusConfig(ValidatorsConsensusConfigBuilders.defaults()).build(); - HotmokaTest.consensus = consensus; + consensus = fillConsensusConfig(ValidatorsConsensusConfigBuilders.defaults()).build(); var config = TendermintNodeConfigBuilders.defaults() .setDir(Files.createTempDirectory("hotmoka-chain")) @@ -261,7 +260,7 @@ private static Node mkTendermintBlockchain() throws NodeException, InterruptedEx .setMaxGasPerViewTransaction(_10_000_000) .build(); - return TendermintNodes.init(config, consensus); + return TendermintNodes.init(config); } catch (IOException | NoSuchAlgorithmException e) { throw new NodeException(e); @@ -285,8 +284,7 @@ private static > B fillConsensusConfig(Con @SuppressWarnings("unused") private static Node mkDiskBlockchain() throws NodeException, InterruptedException { try { - var consensus = fillConsensusConfig(ConsensusConfigBuilders.defaults()).build(); - HotmokaTest.consensus = consensus; + consensus = fillConsensusConfig(ConsensusConfigBuilders.defaults()).build(); var config = DiskNodeConfigBuilders.defaults() .setDir(Files.createTempDirectory("hotmoka-chain")) @@ -295,7 +293,7 @@ private static Node mkDiskBlockchain() throws NodeException, InterruptedExceptio .setPollingDelay(10) .build(); - return DiskNodes.init(config, consensus); + return DiskNodes.init(config); } catch (IOException | NoSuchAlgorithmException e) { throw new NodeException(e);