Skip to content

Commit

Permalink
Simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
spoto committed May 28, 2024
1 parent 833b946 commit 8f00363
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.hotmoka.node.disk.internal;

import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeoutException;

Expand All @@ -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;
Expand All @@ -49,15 +47,14 @@ public class DiskNodeImpl extends AbstractLocalNode<DiskNodeConfig, DiskStore, D
private final Mempool mempool;

/**
* Builds a brand new blockchain in disk memory.
* Builds a new disk memory node.
*
* @param config the configuration of the blockchain
* @param consensus the consensus parameters of the blockchain
* @param config the configuration of the node
* @throws NodeException if the operation cannot be completed correctly
* @throws InterruptedException if the current thread is interrupted before completing the operation
*/
public DiskNodeImpl(DiskNodeConfig config, ConsensusConfig<?,?> consensus) throws NodeException, InterruptedException {
super(Optional.of(consensus), config);
public DiskNodeImpl(DiskNodeConfig config) throws NodeException, InterruptedException {
super(config, true);

try {
initWithEmptyStore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,12 +35,11 @@ public abstract class AbstractCheckableLocalNode<C extends LocalNodeConfig<C,?>,
/**
* 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<ConsensusConfig<?,?>> consensus, C config) throws NodeException {
super(consensus, config);
protected AbstractCheckableLocalNode(C config, boolean init) throws NodeException {
super(config, init);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -38,12 +35,11 @@ public abstract class AbstractLocalNode<C extends LocalNodeConfig<C,?>, 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<ConsensusConfig<?,?>> consensus, C config) throws NodeException {
super(consensus, config);
protected AbstractLocalNode(C config, boolean init) throws NodeException {
super(config, init);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,13 +78,12 @@ public abstract class AbstractCheckableLocalNodeImpl<C extends LocalNodeConfig<C
/**
* 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 AbstractCheckableLocalNodeImpl(Optional<ConsensusConfig<?,?>> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,11 @@ public abstract class AbstractLocalNodeImpl<C extends LocalNodeConfig<C,?>, 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<ConsensusConfig<?,?>> consensus, C config) throws NodeException {
protected AbstractLocalNodeImpl(C config, boolean init) throws NodeException {
super(ClosedNodeException::new);

this.config = config;
Expand All @@ -184,7 +183,7 @@ protected AbstractLocalNodeImpl(Optional<ConsensusConfig<?,?>> consensus, C conf
throw new NodeException(e);
}

if (consensus.isPresent())
if (init)
initWorkingDirectory();

this.executors = Executors.newCachedThreadPool();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,18 +84,17 @@ public class TendermintNodeImpl extends AbstractCheckableLocalNode<TendermintNod
* and connects it to an ABCI application for handling its transactions.
*
* @param config the configuration of the blockchain
* @param consensus the consensus parameters of the node; if empty, the previous store saved on disk will
* be resumed and the consensus extracted from there
* @param init if true, the working directory of the node gets initialized
* @throws NodeException if the operation cannot be completed correctly
* @throws InterruptedException the the currently thread is interrupted before completing the construction
*/
public TendermintNodeImpl(TendermintNodeConfig config, Optional<ConsensusConfig<?,?>> 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);
}
Expand Down
10 changes: 4 additions & 6 deletions io-hotmoka-tests/src/test/java/io/hotmoka/tests/HotmokaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,15 @@ 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"))
.setTendermintConfigurationToClone(Paths.get("tendermint_config"))
.setMaxGasPerViewTransaction(_10_000_000)
.build();

return TendermintNodes.init(config, consensus);
return TendermintNodes.init(config);
}
catch (IOException | NoSuchAlgorithmException e) {
throw new NodeException(e);
Expand All @@ -285,8 +284,7 @@ private static <B extends ConsensusConfigBuilder<?,B>> 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"))
Expand All @@ -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);
Expand Down

0 comments on commit 8f00363

Please sign in to comment.