diff --git a/.gitignore b/.gitignore index 073fc737..0779c625 100644 --- a/.gitignore +++ b/.gitignore @@ -56,6 +56,9 @@ core.* # Autotools-generated headers /src/config/bitcoin-config.h /src/config/bitcoin-config.h.in +/src/config/agrarian-config.h +/src/config/agrarian-config.h.in +/test/config.ini # ----------------------------- # Build outputs diff --git a/contrib/smoke-test-daemon.sh b/contrib/smoke-test-daemon.sh new file mode 100755 index 00000000..3d3dad12 --- /dev/null +++ b/contrib/smoke-test-daemon.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +DATADIR="${DATADIR:-$(mktemp -d /tmp/agrarian-smoke-regtest.XXXXXX)}" +RPCPORT="${RPCPORT:-36235}" +PORT="${PORT:-36236}" +BLOCKS="${BLOCKS:-1}" +WAIT_SECONDS="${WAIT_SECONDS:-90}" +AGRARIAND="${AGRARIAND:-$ROOT/src/agrariand}" +AGRARIAN_CLI="${AGRARIAN_CLI:-$ROOT/src/agrarian-cli}" + +cleanup() { + if [[ -x "$AGRARIAN_CLI" && -d "$DATADIR" ]]; then + "$AGRARIAN_CLI" -datadir="$DATADIR" -regtest \ + -rpcuser=smoke -rpcpassword=smoke-pass -rpcport="$RPCPORT" stop >/dev/null 2>&1 || true + fi +} +trap cleanup EXIT + +require_path() { + if [[ ! -x "$1" ]]; then + echo "Missing executable: $1" >&2 + exit 1 + fi +} + +rpc() { + "$AGRARIAN_CLI" -datadir="$DATADIR" -regtest \ + -rpcuser=smoke -rpcpassword=smoke-pass -rpcconnect=127.0.0.1 \ + -rpcport="$RPCPORT" "$@" +} + +require_path "$AGRARIAND" +require_path "$AGRARIAN_CLI" + +mkdir -p "$DATADIR" +cat > "$DATADIR/agrarian.conf" </dev/null 2>&1; then + break + fi + sleep 1 +done + +if ! rpc getinfo >/dev/null; then + echo "Timed out waiting for RPC on 127.0.0.1:$RPCPORT" >&2 + tail -n 80 "$DATADIR/regtest/debug.log" >&2 || true + exit 1 +fi +rpc getwalletinfo >/dev/null +rpc getmininginfo >/dev/null +rpc getstakingstatus >/dev/null +rpc getnewaddress smoke >/dev/null + +before="$(rpc getblockcount)" +rpc generate "$BLOCKS" >/dev/null +after="$(rpc getblockcount)" + +expected=$((before + BLOCKS)) +if [[ "$after" -ne "$expected" ]]; then + echo "Expected block count $expected after mining, got $after" >&2 + exit 1 +fi + +echo "Agrarian daemon smoke test passed" +echo " datadir: $DATADIR" +echo " blocks: $before -> $after" diff --git a/doc/build-ubuntu-24.md b/doc/build-ubuntu-24.md index 19b6e0df..8bd81a93 100644 --- a/doc/build-ubuntu-24.md +++ b/doc/build-ubuntu-24.md @@ -75,6 +75,17 @@ Qt 5.15 and protobuf 3.x emit compatibility/deprecation warnings in a few Qt translation units. Those warnings are expected while the Windows build remains pinned to Qt 5.9.7 and protobuf 2.6.1. +Functional smoke test +--------------------- + +After building the daemon, run the isolated regtest smoke test: + + ./contrib/smoke-test-daemon.sh + +The script starts `agrariand` with a temporary regtest datadir, confirms RPC and +wallet calls work, mines one block with `generate`, checks the block count, and +stops the daemon. + OpenSSL 3 --------- diff --git a/src/init.cpp b/src/init.cpp index e76f176e..c0ef1717 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -528,10 +528,9 @@ std::string HelpMessage(HelpMessageMode mode) if (GetBoolArg("-help-debug", false)) { strUsage += HelpMessageOpt("-printpriority", strprintf(_("Log transaction priority and fee per kB when mining blocks (default: %u)"), 0)); strUsage += HelpMessageOpt("-privdb", strprintf(_("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)"), 1)); - strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") + " " + - _("This is intended for regression testing tools and app development.") + " " + - _("In this mode -genproclimit controls how many blocks are generated immediately.")); } + strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") + " " + + _("This is intended for regression testing tools and app development.")); strUsage += HelpMessageOpt("-shrinkdebugfile", _("Shrink debug.log file on client startup (default: 1 when no -debug)")); strUsage += HelpMessageOpt("-testnet", _("Use the test network")); strUsage += HelpMessageOpt("-litemode=", strprintf(_("Disable all Agrarian specific functionality (Masternodes, Zerocoin, SwiftX, Budgeting) (0-1, default: %u)"), 0)); diff --git a/src/main.h b/src/main.h index 5997a936..faa717f6 100644 --- a/src/main.h +++ b/src/main.h @@ -255,6 +255,7 @@ int64_t GetMasternodePayment(int nHeight, int64_t blockValue, int nMasternodeCou unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader* pblock, bool fProofOfStake); bool ActivateBestChain(CValidationState& state, CBlock* pblock = NULL, bool fAlreadyChecked = false); +CAmount GetBlockValue(int nHeight, bool fProofOfStake); CAmount GetBlockValue(int nHeight); /** Create a new block index entry for a given block hash */ diff --git a/src/miner.cpp b/src/miner.cpp index fa24a71e..e67a68a1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -113,20 +113,11 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, pindexPrev = chainActive.Tip(); } - const int nHeight = pindexPrev->nHeight + 1; - - // Make sure to create the correct block version after zerocoin is enabled - bool fZerocoinActive = nHeight >= Params().Zerocoin_StartHeight(); pblock->nVersion = 5; // Supports CLTV activation // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios if (Params().MineBlocksOnDemand()) { - if (fZerocoinActive) - pblock->nVersion = 5; - else - pblock->nVersion = 3; - pblock->nVersion = GetArg("-blockversion", pblock->nVersion); } @@ -458,7 +449,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, if (txNew.vout.size() > 1) { pblock->payee = txNew.vout[1].scriptPubKey; } else { - CAmount blockValue = nFees + GetBlockValue(pindexPrev->nHeight); + CAmount blockValue = nFees + GetBlockValue(nHeight, false); txNew.vout[0].nValue = blockValue; txNew.vin[0].scriptSig = CScript() << nHeight << OP_0; } @@ -483,6 +474,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, pblock->nNonce = 0; //Calculate the accumulator checkpoint only if the previous cached checkpoint need to be updated + bool fZerocoinActive = nHeight >= Params().Zerocoin_StartHeight(); if (fZerocoinActive) { uint256 nCheckpoint; uint256 hashBlockLastAccumulated = chainActive[max(0, nHeight - (nHeight % 10) - 10)]->GetBlockHash();