diff --git a/Earthfile b/Earthfile new file mode 100644 index 0000000000..6bbf7dd592 --- /dev/null +++ b/Earthfile @@ -0,0 +1,105 @@ +# Set the Earthly version to 0.7 +VERSION 0.7 +FROM debian:stable-slim + +rust-toolchain: + FROM rust:1.70-slim-bullseye + RUN rustup component add rustfmt + +# Installs Cargo chef +install-chef: + FROM +rust-toolchain + RUN cargo install --debug cargo-chef + +# Prepares the local cache +prepare-cache: + FROM +install-chef + COPY --dir jormungandr jormungandr-lib jcli explorer modules testing . + COPY --dir Cargo.lock Cargo.toml . + RUN cargo chef prepare + SAVE ARTIFACT recipe.json + SAVE IMAGE --cache-hint + +# Builds the local cache +build-cache: + FROM +install-chef + COPY +prepare-cache/recipe.json ./ + + # Install build dependencies + RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + libssl-dev \ + libpq-dev \ + libsqlite3-dev \ + pkg-config \ + protobuf-compiler + + RUN cargo chef cook --release + SAVE ARTIFACT target + SAVE ARTIFACT $CARGO_HOME cargo_home + SAVE IMAGE --cache-hint + +# This is the default builder that all other builders should inherit from +builder: + FROM +rust-toolchain + + WORKDIR /src + + # Install build dependencies + RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + libssl-dev \ + libpq-dev \ + libsqlite3-dev \ + pkg-config \ + protobuf-compiler + COPY --dir jormungandr jormungandr-lib jcli explorer modules testing . + COPY --dir Cargo.lock Cargo.toml . + COPY +build-cache/cargo_home $CARGO_HOME + COPY +build-cache/target target + SAVE ARTIFACT /src + +build: + FROM +builder + + COPY --dir jormungandr jormungandr-lib jcli explorer modules testing . + COPY Cargo.toml Cargo.lock ./ + + RUN cargo build --locked --release -p jormungandr -p jcli -p explorer + + SAVE ARTIFACT /src/target/release/explorer explorer + SAVE ARTIFACT /src/target/release/jcli jcli + SAVE ARTIFACT /src/target/release/jormungandr jormungandr + SAVE IMAGE --cache-hint + +docker: + FROM debian:stable-slim + + WORKDIR /app + ARG tag="latest" + ARG registry + + # Install voting-node system dependencies + RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + libpq5 \ + openssh-client \ + build-essential \ + libxml2-dev \ + libxslt-dev \ + zlib1g-dev + + ## apt cleanup + RUN apt-get clean && \ + rm -rf /var/lib/apt/lists/* + + COPY +build/jormungandr . + COPY +build/jcli . + COPY entry.sh . + RUN chmod +x entry.sh + + ENV BIN_PATH=/app/jormungandr + ENTRYPOINT ["/app/entry.sh"] + SAVE IMAGE --push ${registry}jormungandr:$tag diff --git a/entry.sh b/entry.sh new file mode 100644 index 0000000000..243b4c662e --- /dev/null +++ b/entry.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +# Enable strict mode +set +x +set -o errexit +set -o pipefail +set -o nounset +set -o functrace +set -o errtrace +set -o monitor +set -o posix +shopt -s dotglob + +echo ">>> Entering entrypoint script..." +# Verify the storage path exists +if [[ ! -d "$STORAGE_PATH" ]]; then + echo "ERROR: storage path does not exist at: $STORAGE_PATH"; + echo ">>> Aborting..." + exit 1 +fi +# Verify config is present +if [[ ! -f "$NODE_CONFIG_PATH" ]]; then + echo "ERROR: node configuration is absent at: $NODE_CONFIG_PATH" + echo ">>> Aborting..." + exit 1 +fi +# Verify genesis block is present +if [[ ! -f "$GENESIS_PATH" ]]; then + echo "ERROR: genesis block is absent at: $GENESIS_PATH" + echo ">>> Aborting..." + exit 1 +fi +# Allow overriding jormungandr binary +if [[ ! -f "$BIN_PATH" ]]; then + echo "ERROR: path to jormungandr binary is absent at: $BIN_PATH" + echo ">>> Aborting..." + exit 1 +fi +echo ">>> Using the following parameters:" +echo "Storage path: $STORAGE_PATH" +echo "Node config: $NODE_CONFIG_PATH" +echo "Genesis block: $GENESIS_PATH" +echo "Binary path: $BIN_PATH" +args=() +args+=("--storage" "$STORAGE_PATH") +args+=("--config" "$NODE_CONFIG_PATH") +args+=("--genesis-block" "$GENESIS_PATH") +if [[ -n "${LEADER:-}" ]]; then + echo ">>> Configuring node as leader..." + # shellcheck disable=SC2153 + if [[ ! -f "$BFT_PATH" ]]; then + echo "ERROR: BFT is absent at: $BFT_PATH" + echo ">>> Aborting..." + exit 1 + fi + echo ">>> Using BFT at: $BFT_PATH" + args+=("--secret" "$BFT_PATH") +fi +# Nodes will fail to start if they cannot resolve the domain names of +# their respective peers. If domains are used for peers, it's necessary +# to wait for them to resolve first before starting the node. +if [[ -n "${DNS_PEERS:-}" ]]; then + for PEER in $DNS_PEERS + do + while ! nslookup "$PEER"; do + echo ">>> Waiting for $PEER to be resolvable..." + sleep 1 + done + echo "Successfully resolved $PEER" + done +fi +# Allows resetting our footprint in persistent storage +if [[ -f "$STORAGE_PATH/reset" ]]; then + echo ">>> Reset file detected at $STORAGE_PATH/reset" + rm -rf "$STORAGE_PATH/reset" + if [[ -d "$STORAGE_PATH/fragments" ]]; then + echo ">>> Deleting $STORAGE_PATH/fragments" + rm -rf "$STORAGE_PATH/fragments" + fi + if [[ -d "$STORAGE_PATH/permanent" ]]; then + echo ">>> Deleting $STORAGE_PATH/permanent" + rm -rf "$STORAGE_PATH/permanent" + fi + if [[ -d "$STORAGE_PATH/volatile" ]]; then + echo ">>> Deleting $STORAGE_PATH/volatile" + rm -rf "$STORAGE_PATH/volatile" + fi + echo ">>> Reset complete" +fi + +# Define the command to be executed +ARGS="${args[*]}" +EXTRA_ARGS=$* +CMD="$BIN_PATH $ARGS $EXTRA_ARGS" +echo ">>> Executing command: $CMD" + +# Wait for DEBUG_SLEEP seconds if the DEBUG_SLEEP environment variable is set +if [ -n "${DEBUG_SLEEP:-}" ]; then + echo "DEBUG_SLEEP is set to $DEBUG_SLEEP. Sleeping..." + sleep "$DEBUG_SLEEP" +fi + +echo "Starting node..." +# Expand the command with arguments and capture the exit code +set +e +eval "$CMD" +EXIT_CODE=$? +set -e + +# If the exit code is 0, the executable returned successfully +if [ $EXIT_CODE -ne 0 ]; then + echo "Error: jormungandr returned with exit code $EXIT_CODE" + exit 1 +fi diff --git a/jormungandr/src/fragment/pool.rs b/jormungandr/src/fragment/pool.rs index 811d086fb7..b2cbe02614 100644 --- a/jormungandr/src/fragment/pool.rs +++ b/jormungandr/src/fragment/pool.rs @@ -1,6 +1,6 @@ use crate::{ blockcfg::{ApplyBlockLedger, LedgerParameters}, - blockchain::{Ref, Tip}, + blockchain::Tip, fragment::{ selection::{ FragmentSelectionAlgorithm, FragmentSelectionAlgorithmParams, FragmentSelectionResult, @@ -13,9 +13,7 @@ use crate::{ utils::async_msg::MessageBox, }; use chain_core::{packer::Codec, property::Serialize}; -use chain_impl_mockchain::{ - block::BlockDate, fragment::Contents, setting::Settings, transaction::Transaction, -}; +use chain_impl_mockchain::{block::BlockDate, fragment::Contents, transaction::Transaction}; use futures::channel::mpsc::SendError; use futures::sink::SinkExt; use jormungandr_lib::{ @@ -44,6 +42,7 @@ pub struct Pool { pool: internal::Pool, network_msg_box: MessageBox, persistent_log: Option>, + #[allow(dead_code)] tip: Tip, metrics: Metrics, }