Skip to content

Commit cac05ff

Browse files
kallewoofjtimon
authored andcommitted
Signet implementation
test/functional/data/rpc_getblockstats.json needs to be touched because: Signet implementation changes the genesis block for custom chains
1 parent abca2d2 commit cac05ff

File tree

22 files changed

+422
-16
lines changed

22 files changed

+422
-16
lines changed

contrib/example.conf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
chain=signet
3+
4+
[signet]
5+
con_genesis_style=signet_old
6+
signet_blockscript=512103e464a9f3070da4d3e0b34ce971ff36f3e07c47a8f4beadf32e8ea7e2afa8a82451ae
7+
signet_siglen=77
8+
# DG seed node
9+
seednode=178.128.221.177
10+
bech32_hrp=sb
11+
pchmessagestart=F0C7706A
12+
pubkeyprefix=125
13+
scriptprefix=87
14+
secretprefix=217
15+
extpubkeyprefix=043587CF
16+
extprvkeyprefix=04358394

contrib/signet/issuer/issuer.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) 2018 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
export LC_ALL=C
7+
8+
#
9+
# Issue blocks using a local node at a given interval.
10+
#
11+
12+
if [ $# -lt 3 ]; then
13+
echo "syntax: $0 <min_time> <max_time> <bitcoin-cli path> [<bitcoin-cli args>]" ; exit 1
14+
fi
15+
16+
function log()
17+
{
18+
echo "- $(date +%H:%M:%S): $*"
19+
}
20+
21+
min_time=$1
22+
shift
23+
max_time=$1
24+
shift
25+
bcli=$1
26+
shift
27+
28+
# https://stackoverflow.com/questions/806906/how-do-i-test-if-a-variable-is-a-number-in-bash
29+
re='^[0-9]+$'
30+
if ! [[ $min_time =~ $re ]] ; then
31+
echo "error: min_time $min_time is not a number" ; exit 1
32+
fi
33+
if ! [[ $max_time =~ $re ]] ; then
34+
echo "error: max_time $max_time is not a number" ; exit 1
35+
fi
36+
37+
let randinterval=max_time-min_time
38+
if [ $randinterval -lt 1 ]; then
39+
echo "error: interval min..max must be positive and greater than 0" ; exit 1
40+
fi
41+
42+
if ! [ -e "$bcli" ]; then
43+
which "$bcli" &> /dev/null
44+
if [ $? -ne 0 ]; then
45+
echo "error: unable to find bitcoin binary: $bcli" ; exit 1
46+
fi
47+
fi
48+
49+
echo "- checking node status"
50+
conns=$($bcli "$@" getconnectioncount)
51+
52+
if [ $? -ne 0 ]; then
53+
echo "node error" ; exit 1
54+
fi
55+
56+
if [ $conns -lt 1 ]; then
57+
echo "warning: node is not connected to any other node"
58+
fi
59+
60+
log "node OK with $conns connection(s)"
61+
log "mining in random intervals between $min_time .. $max_time seconds"
62+
log "hit ^C to stop"
63+
64+
while true; do
65+
let rv=$RANDOM%$randinterval
66+
echo -n -e "- $(date +%H:%M:%S): next block in $rv seconds..."
67+
sleep $rv
68+
echo -n -e " [submit]"
69+
blockhash=$($bcli "$@" getnewblockhex true)
70+
if [ $? -ne 0 ]; then
71+
echo "node error; aborting" ; exit 1
72+
fi
73+
echo ""
74+
log "broadcasting block $($bcli "$@" getblockcount) $blockhash to $($bcli "$@" getconnectioncount) peer(s)"
75+
done

src/chain.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,16 @@ class CDiskBlockIndex : public CBlockIndex
405405
READWRITE(nTime);
406406
READWRITE(nBits);
407407
READWRITE(nNonce);
408+
if (g_solution_blocks && !(s.GetType() & SER_GETHASH)) {
409+
uint256 hash = GetBlockHash();
410+
READWRITE(g_blockheader_payload_map[hash]);
411+
size_t len = GetSizeOfCompactSize(g_blockheader_payload_map[hash].size()) + g_blockheader_payload_map[hash].size();
412+
while (len < g_solution_block_len) {
413+
uint8_t padding = 0;
414+
READWRITE(padding);
415+
len++;
416+
}
417+
}
408418
}
409419

410420
uint256 GetBlockHash() const

src/chainparams.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,10 @@ class CCustomParams : public CRegTestParams {
428428
consensus.nMinimumChainWork = uint256S(args.GetArg("-con_nminimumchainwork", "0x0"));
429429
consensus.defaultAssumeValid = uint256S(args.GetArg("-con_defaultassumevalid", "0x00"));
430430

431+
consensus.blockscript = ParseHex(args.GetArg("-signet_blockscript", ""));
432+
g_solution_blocks = !consensus.blockscript.empty();
433+
g_solution_block_len = consensus.siglen = args.GetArg("-signet_siglen", 77);
434+
431435
nPruneAfterHeight = (uint64_t)args.GetArg("-npruneafterheight", nPruneAfterHeight);
432436
fDefaultConsistencyChecks = args.GetBoolArg("-fdefaultconsistencychecks", fDefaultConsistencyChecks);
433437
fMineBlocksOnDemand = args.GetBoolArg("-fmineblocksondemand", fMineBlocksOnDemand);

src/chainparamsbase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ void SetupChainParamsBaseOptions()
2424
gArgs.AddArg("-con_genesis_style=<style>", "Use genesis style <style> (default: signet_new). Allowed values: genesis_style1, signet_new, signet_old", true, OptionsCategory::CHAINPARAMS);
2525
gArgs.AddArg("-vbparams=deployment:start:end", "Use given start/end times for specified version bits deployment (regtest or custom only)", true, OptionsCategory::CHAINPARAMS);
2626
gArgs.AddArg("-seednode=<ip>", "Use specified node as seed node. This option can be specified multiple times to connect to multiple nodes. (custom only)", true, OptionsCategory::CHAINPARAMS);
27+
gArgs.AddArg("-signet_blockscript", "Blocks must satisfy the given script to be considered valid instead of using pow. If empty, and by default, it is ignored. (custom only)", true, OptionsCategory::CHAINPARAMS);
28+
gArgs.AddArg("-signet_siglen", "The length of the signature must be exactly this long (padded to this length, if shorter). All block headers in this network are of length 80 + this value (custom only)", true, OptionsCategory::CHAINPARAMS);
2729
}
2830

2931
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;

src/miner.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
5555
BlockAssembler::Options::Options() {
5656
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
5757
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
58+
59+
// Make room for the signature in the block header, if this is a signet block
60+
if (g_solution_blocks) nBlockMaxWeight -= g_solution_block_len;
5861
}
5962

6063
BlockAssembler::BlockAssembler(const CChainParams& params, const Options& options) : chainparams(params)

src/policy/policy.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <util.h>
1515
#include <utilstrencodings.h>
1616

17+
unsigned int GetStandardScriptVerifyFlags() { return STANDARD_SCRIPT_VERIFY_FLAGS; }
1718

1819
CAmount GetDustThreshold(const CTxOut& txout, const CFeeRate& dustRelayFeeIn)
1920
{

src/policy/policy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ static constexpr unsigned int STANDARD_SCRIPT_VERIFY_FLAGS = MANDATORY_SCRIPT_VE
6868
SCRIPT_VERIFY_WITNESS_PUBKEYTYPE |
6969
SCRIPT_VERIFY_CONST_SCRIPTCODE;
7070

71+
unsigned int GetStandardScriptVerifyFlags();
72+
7173
/** For convenience, standard but not mandatory verify flags. */
7274
static constexpr unsigned int STANDARD_NOT_MANDATORY_VERIFY_FLAGS = STANDARD_SCRIPT_VERIFY_FLAGS & ~MANDATORY_SCRIPT_VERIFY_FLAGS;
7375

src/pow.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#include <chain.h>
1010
#include <primitives/block.h>
1111
#include <uint256.h>
12+
#include <script/interpreter.h>
13+
14+
unsigned int GetStandardScriptVerifyFlags();
1215

1316
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
1417
{
@@ -71,8 +74,17 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
7174
return bnNew.GetCompact();
7275
}
7376

74-
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& params)
77+
bool CheckProofOfWork(const uint256& hash, unsigned int nBits, const Consensus::Params& params)
7578
{
79+
if (g_solution_blocks) {
80+
if (hash == params.hashGenesisBlock) return true;
81+
SimpleSignatureChecker bsc(hash);
82+
const auto& payload = g_blockheader_payload_map.at(hash);
83+
CScript solution = CScript(payload.begin(), payload.end());
84+
CScript challenge = CScript(params.blockscript.begin(), params.blockscript.end());
85+
return VerifyScript(solution, challenge, nullptr, GetStandardScriptVerifyFlags(), bsc);
86+
}
87+
7688
bool fNegative;
7789
bool fOverflow;
7890
arith_uint256 bnTarget;

src/pow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
1818
unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params&);
1919

2020
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
21-
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&);
21+
bool CheckProofOfWork(const uint256& hash, unsigned int nBits, const Consensus::Params&);
2222

2323
#endif // BITCOIN_POW_H

0 commit comments

Comments
 (0)