diff --git a/contrib/example.conf b/contrib/example.conf new file mode 100644 index 00000000000..43a638b68b1 --- /dev/null +++ b/contrib/example.conf @@ -0,0 +1,16 @@ + +chain=signet + +[signet] +con_genesis_style=signet_old +signet_blockscript=512103e464a9f3070da4d3e0b34ce971ff36f3e07c47a8f4beadf32e8ea7e2afa8a82451ae +signet_siglen=77 +# DG seed node +seednode=178.128.221.177 +bech32_hrp=sb +pchmessagestart=F0C7706A +pubkeyprefix=125 +scriptprefix=87 +secretprefix=217 +extpubkeyprefix=043587CF +extprvkeyprefix=04358394 diff --git a/contrib/signet/issuer/issuer.sh b/contrib/signet/issuer/issuer.sh new file mode 100755 index 00000000000..f21a9153d78 --- /dev/null +++ b/contrib/signet/issuer/issuer.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# Copyright (c) 2018 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +export LC_ALL=C + +# +# Issue blocks using a local node at a given interval. +# + +if [ $# -lt 3 ]; then + echo "syntax: $0 []" ; exit 1 +fi + +function log() +{ + echo "- $(date +%H:%M:%S): $*" +} + +min_time=$1 +shift +max_time=$1 +shift +bcli=$1 +shift + +# https://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash +re='^[0-9]+$' +if ! [[ $min_time =~ $re ]] ; then + echo "error: min_time $min_time is not a number" ; exit 1 +fi +if ! [[ $max_time =~ $re ]] ; then + echo "error: max_time $max_time is not a number" ; exit 1 +fi + +let randinterval=max_time-min_time +if [ $randinterval -lt 1 ]; then + echo "error: interval min..max must be positive and greater than 0" ; exit 1 +fi + +if ! [ -e "$bcli" ]; then + which "$bcli" &> /dev/null + if [ $? -ne 0 ]; then + echo "error: unable to find bitcoin binary: $bcli" ; exit 1 + fi +fi + +echo "- checking node status" +conns=$($bcli "$@" getconnectioncount) + +if [ $? -ne 0 ]; then + echo "node error" ; exit 1 +fi + +if [ $conns -lt 1 ]; then + echo "warning: node is not connected to any other node" +fi + +log "node OK with $conns connection(s)" +log "mining in random intervals between $min_time .. $max_time seconds" +log "hit ^C to stop" + +while true; do + let rv=$RANDOM%$randinterval + echo -n -e "- $(date +%H:%M:%S): next block in $rv seconds..." + sleep $rv + echo -n -e " [submit]" + blockhash=$($bcli "$@" getnewblockhex true) + if [ $? -ne 0 ]; then + echo "node error; aborting" ; exit 1 + fi + echo "" + log "broadcasting block $($bcli "$@" getblockcount) $blockhash to $($bcli "$@" getconnectioncount) peer(s)" +done diff --git a/src/chain.h b/src/chain.h index 01011d54f19..5ebac95290e 100644 --- a/src/chain.h +++ b/src/chain.h @@ -405,6 +405,16 @@ class CDiskBlockIndex : public CBlockIndex READWRITE(nTime); READWRITE(nBits); READWRITE(nNonce); + if (g_solution_blocks && !(s.GetType() & SER_GETHASH)) { + uint256 hash = GetBlockHash(); + READWRITE(g_blockheader_payload_map[hash]); + size_t len = GetSizeOfCompactSize(g_blockheader_payload_map[hash].size()) + g_blockheader_payload_map[hash].size(); + while (len < g_solution_block_len) { + uint8_t padding = 0; + READWRITE(padding); + len++; + } + } } uint256 GetBlockHash() const diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 2f2b2d5c30f..42718f6a5b8 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -4,9 +4,10 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include -#include #include +#include +#include #include #include #include @@ -17,13 +18,13 @@ #include #include -static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward) +static CBlock CreateGenesisBlock(const CScript& coinbase_sig, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward) { CMutableTransaction txNew; txNew.nVersion = 1; txNew.vin.resize(1); txNew.vout.resize(1); - txNew.vin[0].scriptSig = CScript() << 486604799 << CScriptNum(4) << std::vector((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); + txNew.vin[0].scriptSig = coinbase_sig; txNew.vout[0].nValue = genesisReward; txNew.vout[0].scriptPubKey = genesisOutputScript; @@ -38,6 +39,12 @@ static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesi return genesis; } +static CBlock CreateGenesisBlock(const char* pszTimestamp, const CScript& genesisOutputScript, uint32_t nTime, uint32_t nNonce, uint32_t nBits, int32_t nVersion, const CAmount& genesisReward) +{ + CScript coinbase_sig = CScript() << 486604799 << CScriptNum(4) << std::vector((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp)); + return CreateGenesisBlock(coinbase_sig, genesisOutputScript, nTime, nNonce, nBits, nVersion, genesisReward); +} + /** * Build the genesis block. Note that the output of its generation * transaction cannot be spent since it did not originally exist in the @@ -403,6 +410,7 @@ class CCustomParams : public CRegTestParams { { UpdateVersionBitsParametersFromArgs(args); + consensus.genesis_style = args.GetArg("-con_genesis_style", "default_style"); consensus.nSubsidyHalvingInterval = args.GetArg("-con_nsubsidyhalvinginterval", consensus.nSubsidyHalvingInterval); consensus.BIP16Exception = uint256S(args.GetArg("-con_bip16exception", "0x0")); consensus.BIP34Height = args.GetArg("-con_bip34height", consensus.BIP34Height); @@ -420,6 +428,10 @@ class CCustomParams : public CRegTestParams { consensus.nMinimumChainWork = uint256S(args.GetArg("-con_nminimumchainwork", "0x0")); consensus.defaultAssumeValid = uint256S(args.GetArg("-con_defaultassumevalid", "0x00")); + consensus.blockscript = ParseHex(args.GetArg("-signet_blockscript", "")); + g_solution_blocks = !consensus.blockscript.empty(); + g_solution_block_len = consensus.siglen = args.GetArg("-signet_siglen", 77); + nPruneAfterHeight = (uint64_t)args.GetArg("-npruneafterheight", nPruneAfterHeight); fDefaultConsistencyChecks = args.GetBoolArg("-fdefaultconsistencychecks", fDefaultConsistencyChecks); fMineBlocksOnDemand = args.GetBoolArg("-fmineblocksondemand", fMineBlocksOnDemand); @@ -452,12 +464,44 @@ class CCustomParams : public CRegTestParams { } } + void SetGenesisBlock() + { + if (consensus.genesis_style == "regtest2_style") { + // Same style as in https://github.com/bitcoin/bitcoin/pull/8994 + assert(consensus.blockscript.empty() && "consensus.blockscript is for signets"); + genesis = CreateGenesisBlock(strNetworkID.c_str(), CScript(OP_TRUE), 1296688602, 2, 0x207fffff, 1, 50 * COIN); + + } else if (consensus.genesis_style == "default_style") { + CHashWriter h(SER_DISK, 0); + h << strNetworkID; + if (!consensus.blockscript.empty()) { + h << consensus.blockscript << consensus.siglen; + } + uint256 hash = h.GetHash(); + CScript coinbase_sig = CScript() << std::vector(hash.begin(), hash.end()); + genesis = CreateGenesisBlock(coinbase_sig, CScript(OP_TRUE), 1296688602, 2, 0x207fffff, 1, 50 * COIN); + + } else if (consensus.genesis_style == "signet_old") { + // Same style as in https://github.com/kallewoof/bitcoin/pull/5 + assert(!consensus.blockscript.empty() && "Signets require consensus.blockscript"); + CHashWriter h(SER_DISK, 0); + h << consensus.blockscript << consensus.siglen; + uint256 hash = h.GetHash(); + CScript coinbase_sig = CScript() << std::vector(hash.begin(), hash.end()); + CScript genesis_out = CScript() << OP_RETURN; + genesis = CreateGenesisBlock(coinbase_sig, genesis_out, 1534313275, 0, 0x1d00ffff, 1, 50 * COIN); + + } else { + throw std::runtime_error(strprintf("%s: Unknown consensus.genesis_style %s.", __func__, consensus.genesis_style)); + } + } + public: CCustomParams(const std::string& chain, ArgsManager& args) : CRegTestParams(args) { strNetworkID = chain; UpdateFromArgs(args); - genesis = CreateGenesisBlock(strNetworkID.c_str(), CScript(OP_TRUE), 1296688602, 2, 0x207fffff, 1, 50 * COIN); + SetGenesisBlock(); consensus.hashGenesisBlock = genesis.GetHash(); } }; diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 1a4b53a3524..d3aba017050 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -21,8 +21,11 @@ void SetupChainParamsBaseOptions() gArgs.AddArg("-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.", true, OptionsCategory::CHAINPARAMS); gArgs.AddArg("-testnet", "Use the test chain", false, OptionsCategory::CHAINPARAMS); + gArgs.AddArg("-con_genesis_style=