Skip to content

Commit

Permalink
First sketch of the Docker image for Mokamint Hotmoka nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
spoto committed Aug 13, 2024
1 parent d43c023 commit 0f14371
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ modules/
docs/
chain/
mokamint-chain/
mokamint_node*
hotmoka-chain/
disk-chain/
.metadata/
Expand Down
4 changes: 4 additions & 0 deletions build_and_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ DOCKER_FILE_BLUEKNOT=dockerfiles/tendermint-node/blueknot-tendermint-node-arm64
docker buildx build --push --platform linux/arm64 -t ${DOCKER_IMAGE_HOTMOKA} -f ${DOCKER_FILE_HOTMOKA} .
#docker buildx build --push --platform linux/arm64 -t ${DOCKER_IMAGE_BLUEKNOT} -f ${DOCKER_FILE_BLUEKNOT} .

DOCKER_IMAGE_HOTMOKA=hotmoka/mokamint-node:${VERSION}
DOCKER_FILE_HOTMOKA=dockerfiles/mokamint-node/mokamint-node
docker buildx build --push --platform linux/amd64 -t ${DOCKER_IMAGE_HOTMOKA} -f ${DOCKER_FILE_HOTMOKA} .

tar -cvf moka_${VERSION}.tar --directory io-hotmoka-moka modules moka moka.bat; gzip moka_${VERSION}.tar
15 changes: 0 additions & 15 deletions dockerfiles/mokamint-node/help
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ echo
echo " help: prints this help"
echo
echo " init: creates a node for a brand new blockchain"
echo " CHAIN_ID: the chain identifier of the new blockchain"
echo " [default: the string \"missing\"]"
echo " DELTA_SUPPLY: the number of coins that can be minted during the life of the node,"
echo " as effect of inflation"
echo " [default: equal to INITIAL_SUPPLY, hence the supply can double at most]"
Expand Down Expand Up @@ -38,19 +36,6 @@ echo
echo " start: creates a node that connects to an already existing node of a blockchain"
echo " MAX_GAS_PER_VIEW: the maximal gas limit allowed when running @View methods"
echo " [default: 10000000]"
echo " NETWORK_URI: the URI of the already existing node"
echo " [default: ws://panarea.hotmoka.io]"
echo " TIMEOUT_COMMIT: commit timeout in seconds, which determines the block creation time"
echo " [default: 5]"
echo " PUBLIC_KEY_BASE58: the base58-encoded public key of the node if it becomes a validator"
echo " [default: a new automatically-generated public key]"
echo " PUBLIC_KEY_BASE64: the base64-encoded public key of the node if it becomes a validator"
echo " [default: a new automatically-generated private key]"
echo " CONCATENATED_KEYS_BASE64: the base64-encoded concatenation of the private and public keys"
echo " of the node if it becomes a validator"
echo " [default: a new automatically-generated concatenation key]"
echo " TENDERMINT_ADDRESS: the Tendermint address of the node if it becomes a validator"
echo " [default: a new automatically-generated Tendermint address]"
echo
echo " resume: resumes a node whose container was previously turned off with \"docker stop\""
echo " MAX_GAS_PER_VIEW: the maximal gas limit allowed when running @View methods"
Expand Down
8 changes: 1 addition & 7 deletions dockerfiles/mokamint-node/init
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ INITIAL_SUPPLY=${INITIAL_SUPPLY:-100000000000000000000000000000}
DELTA_SUPPLY=${DELTA_SUPPLY:-${INITIAL_SUPPLY}}
OPEN_UNSIGNED_FAUCET=${OPEN_UNSIGNED_FAUCET:-false}
KEY_OF_GAMETE=${KEY_OF_GAMETE:-missing}
CHAIN_ID=${CHAIN_ID:-missing}
MAX_GAS_PER_VIEW=${MAX_GAS_PER_VIEW:-10000000}
OBLIVION=${OBLIVION:-250000}
INFLATION=${INFLATION:-100000}
INITIAL_GAS_PRICE=${INITIAL_GAS_PRICE:-100}

echo
echo "Starting a Mokamint node as the single initial node of a brand new blockchain"
echo " CHAIN_ID=$CHAIN_ID"
echo " INITIAL_SUPPLY=$INITIAL_SUPPLY"
echo " DELTA_SUPPLY=$DELTA_SUPPLY"
echo " KEY_OF_GAMETE=$KEY_OF_GAMETE"
Expand All @@ -22,8 +20,4 @@ echo " MAX_GAS_PER_VIEW=$MAX_GAS_PER_VIEW"
echo " OBLIVION=$OBLIVION"
echo " INFLATION=$INFLATION"

# set the chain id as requested
sed -i "s/chain_id = .*/chain_id = \"$CHAIN_ID\"/" mokamint_config.cfg

# invoke moka in a way that uses the mokamint configuration that was previously created inside the chain directory
moka init-mokamint ${INITIAL_SUPPLY} --delta-supply=${DELTA_SUPPLY} --interactive=true --open-unsigned-faucet=${OPEN_UNSIGNED_FAUCET} --key-of-gamete=${KEY_OF_GAMETE} --takamaka-code /modules/explicit/io-takamaka-code-TAKAMAKA-VERSION.jar --mokamint-config=mokamint_config.cfg --plot mokamint_node/plot.plot --keys mokamint_node/node.pem --keys-of-plot mokamint_node/miner.pem --max-gas-per-view ${MAX_GAS_PER_VIEW} --oblivion ${OBLIVION} --inflation ${INFLATION} --initial-gas-price ${INITIAL_GAS_PRICE}
moka init-mokamint ${INITIAL_SUPPLY} --delta-supply=${DELTA_SUPPLY} --interactive=true --open-unsigned-faucet=${OPEN_UNSIGNED_FAUCET} --key-of-gamete=${KEY_OF_GAMETE} --takamaka-code /modules/explicit/io-takamaka-code-TAKAMAKA-VERSION.jar --mokamint-config=mokamint_node/mokamint_config.cfg --plot mokamint_node/plot.plot --keys mokamint_node/node.pem --keys-of-plot mokamint_node/miner.pem --max-gas-per-view ${MAX_GAS_PER_VIEW} --oblivion ${OBLIVION} --inflation ${INFLATION} --initial-gas-price ${INITIAL_GAS_PRICE}
26 changes: 15 additions & 11 deletions dockerfiles/mokamint-node/mokamint-node
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@
# docker buildx build --platform linux/amd64 -t hotmoka/mokamint-node:latest -f dockerfiles/mokamint-node/mokamint-node .
#
# In order to publish a node at port 8001 whose underlying Mokamint node is published at port 8030:
# create a local directory "mokamint_node" containing three files, named exactly as follows:
# create a local directory "mokamint_node" containing four files, named exactly as follows:
#
# miner.pem
# node.pem
# plot.plot
# mokamint_config.cfg
#
# Then run:
#
# docker run -it --name mokamint_node -e KEY_OF_GAMETE=BFtoCuWq962dRyW5Mq311Na7qQmXjhH9gk4kp1AfAxMz -e CHAIN_ID=caatinga -p 8001:8001 -p 8030:8030 -v chain:/home/hotmoka/chain -v ./mokamint_node:/home/hotmoka/mokamint_node hotmoka/mokamint-node:latest init
# docker run -it --name mokamint_node -e KEY_OF_GAMETE=BFtoCuWq962dRyW5Mq311Na7qQmXjhH9gk4kp1AfAxMz -p 8001:8001 -p 8030:8030 -p 8031:8031 -v chain:/home/hotmoka/chain -v ./mokamint_node:/home/hotmoka/mokamint_node hotmoka/mokamint-node:latest init
#
# (assuming that the public Base58 key of the gamete will be BFtoCuWq962dRyW5Mq311Na7qQmXjhH9gk4kp1AfAxMz and that the chain identifier will be caatinga; this chain identifier
# must coincide with that used in plot.plot; similarly, plot.plot must use node.pem as key for signing the blocks and miner.pem as key for signing the deadlines)
# (assuming that the public Base58 key of the gamete will be BFtoCuWq962dRyW5Mq311Na7qQmXjhH9gk4kp1AfAxMz; plot.plot must use node.pem as key for signing the blocks, miner.pem as key for signing the deadlines
# and the chain identifier in mokamint_config.cfg)
#
# When the docker container has initialized the node, you can detach from it with CTRL+P CTRL+Q
#
# Later you can stop the container with:
# Or run instead:
#
# docker run -it --name mokamint_node -p 8001:8001 -p 8030:8030 -p 8031:8031 -v chain:/home/hotmoka/chain -v ./mokamint_node:/home/hotmoka/mokamint_node hotmoka/mokamint-node:latest start
#
# after which you should add a peer to the Mokamint node, or otherwise it will never start mining.
#
# In all cases, later you can stop the container with:
# docker stop mokamint_node

FROM openjdk:19-jdk-slim
Expand Down Expand Up @@ -51,18 +58,15 @@ RUN echo java -Djava.util.logging.config.file=logging.properties --module-path /
# install the control scripts
COPY dockerfiles/mokamint-node/help help
COPY dockerfiles/mokamint-node/init init
#COPY dockerfiles/mokamint-node/resume resume
#COPY dockerfiles/mokamint-node/start start
RUN chmod 755 help && chmod 755 init #&& chmod 755 resume && chmod 755 start
COPY dockerfiles/mokamint-node/resume resume
COPY dockerfiles/mokamint-node/start start
RUN chmod 755 help && chmod 755 init && chmod 755 resume && chmod 755 start

USER hotmoka
WORKDIR /home/hotmoka

# install the logging configuration
COPY --chown=hotmoka dockerfiles/logging.properties logging.properties

# install the default Mokamint configuration
COPY --chown=hotmoka io-hotmoka-moka/mokamint_configs/default.cfg mokamint_config.cfg

# by default, print a help message
CMD help
9 changes: 9 additions & 0 deletions dockerfiles/mokamint-node/resume
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

MAX_GAS_PER_VIEW=${MAX_GAS_PER_VIEW:-10000000}

echo
echo "Resuming an already existing node:"
echo " MAX_GAS_PER_VIEW=$MAX_GAS_PER_VIEW"

moka resume-mokamint --interactive=true --mokamint-config=mokamint_node/mokamint_config.cfg --plot mokamint_node/plot.plot --keys mokamint_node/node.pem --keys-of-plot mokamint_node/miner.pem --max-gas-per-view ${MAX_GAS_PER_VIEW}
9 changes: 9 additions & 0 deletions dockerfiles/mokamint-node/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

MAX_GAS_PER_VIEW=${MAX_GAS_PER_VIEW:-10000000}

echo
echo "Starting a Mokamint node connected to the node at $NETWORK_URI:"
echo " MAX_GAS_PER_VIEW=$MAX_GAS_PER_VIEW"

moka start-mokamint --interactive=true --mokamint-config=mokamint_node/mokamint_config.cfg --plot mokamint_node/plot.plot --keys mokamint_node/node.pem --keys-of-plot mokamint_node/miner.pem --max-gas-per-view ${MAX_GAS_PER_VIEW}
2 changes: 0 additions & 2 deletions dockerfiles/tendermint-node/start
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,9 @@ sed -i "s/create_empty_blocks = true/create_empty_blocks = false/g" node0/config
sed -i '/timeout_commit = /s/".*"/"'${TIMEOUT_COMMIT}s'"/' node0/config/config.toml
# set the remote node as persistent seed
echo "3"
sed -i '/persistent_peers =/s/".*"/"'$REMOTE_NODE_ID@$BASE_NETWORK_URI:26656'"/' node0/config/config.toml
# invoke moka in a way that deletes the tendermint configuration that was initially
# created into node0, so that we do not leave garbage around;
# in any case, it has been copied inside the chain directory
echo "4"
moka start-tendermint --interactive=false --tendermint-config=node0 --delete-tendermint-config --max-gas-per-view ${MAX_GAS_PER_VIEW}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.mokamint.miner.local.LocalMiners;
import io.mokamint.node.local.LocalNodeConfigBuilders;
import io.mokamint.node.service.PublicNodeServices;
import io.mokamint.node.service.RestrictedNodeServices;
import io.mokamint.plotter.PlotAndKeyPairs;
import io.mokamint.plotter.Plots;
import io.mokamint.plotter.api.PlotAndKeyPair;
Expand Down Expand Up @@ -95,6 +96,9 @@ public class InitMokamint extends AbstractCommand {
@Option(names = { "--mokamint-port" }, description = "the network port for the publication of the Mokamint service", defaultValue="8030")
private int mokamintPort;

@Option(names = { "--mokamint-port-restricted" }, description = "the network port for the publication of the restricted Mokamint service", defaultValue="8031")
private int mokamintPortRestricted;

@Option(names = { "--dir" }, description = "the directory that will contain blocks and state of the node", defaultValue = "chain")
private Path dir;

Expand Down Expand Up @@ -154,6 +158,7 @@ private Run() throws Exception {
var consensus = ConsensusConfigBuilders.defaults()
.allowUnsignedFaucet(openUnsignedFaucet)
.ignoreGasPrice(ignoreGasPrice)
.setChainId(mokamintConfig.getChainId()) // we use the same chain id as the underlying Mokamint engine, although this is not needed in general
.setSignatureForRequests(signature)
.setInitialGasPrice(initialGasPrice)
.setOblivion(oblivion)
Expand All @@ -173,8 +178,9 @@ private Run() throws Exception {

node.getMokamintNode().add(miner).orElseThrow(() -> new CommandException("Could not add a miner to the test node"));

// the next service will be closed when the node will be closed
// the next services will be closed when the node will be closed
PublicNodeServices.open(node.getMokamintNode(), mokamintPort, 1800000, 1000, Optional.of(URI.create("ws://localhost:" + mokamintPort)));
RestrictedNodeServices.open(node.getMokamintNode(), mokamintPortRestricted);

try (var initialized = this.initialized = InitializedNodes.of(node, consensus, Paths.get(takamakaCode.replace("TAKAMAKA-VERSION", Constants.TAKAMAKA_VERSION)));
var service = NodeServices.of(initialized, port)) {
Expand All @@ -199,7 +205,7 @@ private void waitForEnterKey() throws IOException {

private void printBanner() {
System.out.println("The Hotmoka node has been published at ws://localhost:" + port);
System.out.println("The Mokamint node has been published at ws://localhost:" + mokamintPort);
System.out.println("The Mokamint node has been published at ws://localhost:" + mokamintPort + " (public) and ws://localhost:" + mokamintPortRestricted + " (restricted)");
}

private void printManifest() throws TransactionRejectedException, TransactionException, CodeExecutionException, NoSuchElementException, NodeException, TimeoutException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.mokamint.miner.local.LocalMiners;
import io.mokamint.node.local.LocalNodeConfigBuilders;
import io.mokamint.node.service.PublicNodeServices;
import io.mokamint.node.service.RestrictedNodeServices;
import io.mokamint.plotter.PlotAndKeyPairs;
import io.mokamint.plotter.Plots;
import io.mokamint.plotter.api.PlotAndKeyPair;
Expand Down Expand Up @@ -69,6 +70,9 @@ public class ResumeMokamint extends AbstractCommand {
@Option(names = { "--mokamint-port" }, description = "the network port for the publication of the Mokamint service", defaultValue="8030")
private int mokamintPort;

@Option(names = { "--mokamint-port-restricted" }, description = "the network port for the publication of the restricted Mokamint service", defaultValue="8031")
private int mokamintPortRestricted;

@Option(names = { "--keys-of-plot" }, description = "the path to the keys of the plot file")
private Path keysOfPlot;

Expand Down Expand Up @@ -132,8 +136,9 @@ private void createPlotAndMinerAndPublish(MokamintNode node) throws Exception {
}

private void publish(MokamintNode node) throws Exception {
// the next service will be closed when the node will be closed
// the next services will be closed when the node will be closed
PublicNodeServices.open(node.getMokamintNode(), mokamintPort, 1800000, 1000, Optional.of(URI.create("ws://localhost:" + mokamintPort)));
RestrictedNodeServices.open(node.getMokamintNode(), mokamintPortRestricted);

printManifest(node);
printBanner();
Expand All @@ -147,7 +152,7 @@ private void waitForEnterKey() {

private void printBanner() {
System.out.println("The Hotmoka node has been published at ws://localhost:" + port);
System.out.println("The Mokamint node has been published at ws://localhost:" + mokamintPort);
System.out.println("The Mokamint node has been published at ws://localhost:" + mokamintPort + " (public) and ws://localhost:" + mokamintPortRestricted + " (restricted)");
}

private void printManifest(MokamintNode node) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.mokamint.miner.local.LocalMiners;
import io.mokamint.node.local.LocalNodeConfigBuilders;
import io.mokamint.node.service.PublicNodeServices;
import io.mokamint.node.service.RestrictedNodeServices;
import io.mokamint.plotter.PlotAndKeyPairs;
import io.mokamint.plotter.Plots;
import io.mokamint.plotter.api.PlotAndKeyPair;
Expand Down Expand Up @@ -58,6 +59,9 @@ public class StartMokamint extends AbstractCommand {
@Option(names = { "--mokamint-port" }, description = "the network port for the publication of the Mokamint service", defaultValue="8030")
private int mokamintPort;

@Option(names = { "--mokamint-port-restricted" }, description = "the network port for the publication of the restricted Mokamint service", defaultValue="8031")
private int mokamintPortRestricted;

@Option(names = { "--keys-of-mokamint-node", "--keys" }, description = "the path to the keys of the Mokamint node", required = true)
private Path keysOfMokamintNode;

Expand Down Expand Up @@ -104,8 +108,9 @@ private Run() throws Exception {

node.getMokamintNode().add(miner).orElseThrow(() -> new CommandException("Could not add a miner to the test node"));

// the service below will be closed when the node will be closed
// the services below will be closed when the node will be closed
PublicNodeServices.open(node.getMokamintNode(), mokamintPort, 1800000, 1000, Optional.of(URI.create("ws://localhost:" + mokamintPort)));
RestrictedNodeServices.open(node.getMokamintNode(), mokamintPortRestricted);

printBanner();
waitForEnterKey();
Expand All @@ -124,7 +129,7 @@ private void waitForEnterKey() throws IOException {

private void printBanner() {
System.out.println("The Hotmoka node has been published at ws://localhost:" + port);
System.out.println("The Mokamint node has been published at ws://localhost:" + mokamintPort);
System.out.println("The Mokamint node has been published at ws://localhost:" + mokamintPort + " (public) and ws://localhost:" + mokamintPortRestricted + " (restricted)");
}
}
}

0 comments on commit 0f14371

Please sign in to comment.