Skip to content

Commit 8219893

Browse files
author
MarcoFalke
committed
Merge #19993: refactor: Signet fixups
facaf9e doc: Document signet BIP (MarcoFalke) faf0a26 doc: Update comments for new chain settings (-signet and -chain=signet) (MarcoFalke) fae0548 fuzz: Remove needless guard (MarcoFalke) 77771a0 refactor: Remove SignetTxs::m_valid and use optional instead (MarcoFalke) fa2ad5d test: Run signet test even when wallet was not compiled (MarcoFalke) Pull request description: Some doc and test fixups for #18267 ACKs for top commit: ajtowns: ACK facaf9e -- code review only dr-orlovsky: Reviewed & ACK bitcoin/bitcoin@facaf9e kallewoof: Code review ACK facaf9e Tree-SHA512: 8085027c488d84bb4bddccba78bd2d4c5af0d8e2644ee72265f1f30fa8c83f61a961d9da2c796f2940e69682291cbee7b1028b6a6ce123ad9134c0ebbf4723b0
2 parents b1291b2 + facaf9e commit 8219893

File tree

11 files changed

+34
-52
lines changed

11 files changed

+34
-52
lines changed

doc/bips.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ BIPs that are implemented by Bitcoin Core (up-to-date up to **v0.21.0**):
4242
* [`BIP 173`](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki): Bech32 addresses for native Segregated Witness outputs are supported as of **v0.16.0** ([PR 11167](https://github.com/bitcoin/bitcoin/pull/11167)). Bech32 addresses are generated by default as of **v0.20.0** ([PR 16884](https://github.com/bitcoin/bitcoin/pull/16884)).
4343
* [`BIP 174`](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki): RPCs to operate on Partially Signed Bitcoin Transactions (PSBT) are present as of **v0.17.0** ([PR 13557](https://github.com/bitcoin/bitcoin/pull/13557)).
4444
* [`BIP 176`](https://github.com/bitcoin/bips/blob/master/bip-0176.mediawiki): Bits Denomination [QT only] is supported as of **v0.16.0** ([PR 12035](https://github.com/bitcoin/bitcoin/pull/12035)).
45+
* [`BIP 325`](https://github.com/bitcoin/bips/blob/master/bip-0325.mediawiki): Signet test network is supported as of **v0.21.0** ([PR 18267](https://github.com/bitcoin/bitcoin/pull/18267)).
4546
* [`BIP 339`](https://github.com/bitcoin/bips/blob/master/bip-0339.mediawiki): Relay of transactions by wtxid is supported as of **v0.21.0** ([PR 18044](https://github.com/bitcoin/bitcoin/pull/18044)).

doc/release-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ RPC
335335
Tests
336336
-----
337337

338+
- The BIP 325 default signet can be enabled by the `-chain=signet` or `-signet`
339+
setting. The settings `-signetchallenge` and `-signetseednode` allow
340+
enabling a custom signet.
341+
338342
Credits
339343
=======
340344

src/bitcoin-cli.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ static void libevent_log_cb(int severity, const char *msg)
8787
}
8888
}
8989

90-
//////////////////////////////////////////////////////////////////////////////
91-
//
92-
// Start
93-
//
94-
9590
//
9691
// Exception thrown on connection error. This error is used to determine
9792
// when to wait if -rpcwait is given.
@@ -112,9 +107,6 @@ class CConnectionFailed : public std::runtime_error
112107
//
113108
static int AppInitRPC(int argc, char* argv[])
114109
{
115-
//
116-
// Parameters
117-
//
118110
SetupCliArgs(gArgs);
119111
std::string error;
120112
if (!gArgs.ParseParameters(argc, argv, error)) {
@@ -147,7 +139,7 @@ static int AppInitRPC(int argc, char* argv[])
147139
tfm::format(std::cerr, "Error reading configuration file: %s\n", error);
148140
return EXIT_FAILURE;
149141
}
150-
// Check for -chain, -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
142+
// Check for chain settings (BaseParams() calls are only valid after this clause)
151143
try {
152144
SelectBaseParams(gArgs.GetChainName());
153145
} catch (const std::exception& e) {

src/bitcoin-tx.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,14 @@ static void SetupBitcoinTxArgs(ArgsManager &argsman)
7878
//
7979
static int AppInitRawTx(int argc, char* argv[])
8080
{
81-
//
82-
// Parameters
83-
//
8481
SetupBitcoinTxArgs(gArgs);
8582
std::string error;
8683
if (!gArgs.ParseParameters(argc, argv, error)) {
8784
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error);
8885
return EXIT_FAILURE;
8986
}
9087

91-
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
88+
// Check for chain settings (Params() calls are only valid after this clause)
9289
try {
9390
SelectParams(gArgs.GetChainName());
9491
} catch (const std::exception& e) {

src/bitcoin-wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static bool WalletAppInit(int argc, char* argv[])
6262
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", ""));
6363
return false;
6464
}
65-
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
65+
// Check for chain settings (Params() calls are only valid after this clause)
6666
SelectParams(gArgs.GetChainName());
6767

6868
return true;

src/bitcoind.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ static void WaitForShutdown(NodeContext& node)
3737
Interrupt(node);
3838
}
3939

40-
//////////////////////////////////////////////////////////////////////////////
41-
//
42-
// Start
43-
//
4440
static bool AppInit(int argc, char* argv[])
4541
{
4642
NodeContext node;
@@ -81,7 +77,7 @@ static bool AppInit(int argc, char* argv[])
8177
if (!args.ReadConfigFiles(error, true)) {
8278
return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error)));
8379
}
84-
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
80+
// Check for chain settings (Params() calls are only valid after this clause)
8581
try {
8682
SelectParams(args.GetChainName());
8783
} catch (const std::exception& e) {

src/qt/bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ int GuiMain(int argc, char* argv[])
533533
// - QSettings() will use the new application name after this, resulting in network-specific settings
534534
// - Needs to be done before createOptionsModel
535535

536-
// Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause)
536+
// Check for chain settings (Params() calls are only valid after this clause)
537537
try {
538538
SelectParams(gArgs.GetChainName());
539539
} catch(std::exception &e) {

src/signet.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static uint256 ComputeModifiedMerkleRoot(const CMutableTransaction& cb, const CB
6565
return ComputeMerkleRoot(std::move(leaves));
6666
}
6767

68-
SignetTxs SignetTxs::Create(const CBlock& block, const CScript& challenge)
68+
Optional<SignetTxs> SignetTxs::Create(const CBlock& block, const CScript& challenge)
6969
{
7070
CMutableTransaction tx_to_spend;
7171
tx_to_spend.nVersion = 0;
@@ -83,12 +83,12 @@ SignetTxs SignetTxs::Create(const CBlock& block, const CScript& challenge)
8383
// responses from block coinbase tx
8484

8585
// find and delete signet signature
86-
if (block.vtx.empty()) return invalid(); // no coinbase tx in block; invalid
86+
if (block.vtx.empty()) return nullopt; // no coinbase tx in block; invalid
8787
CMutableTransaction modified_cb(*block.vtx.at(0));
8888

8989
const int cidx = GetWitnessCommitmentIndex(block);
9090
if (cidx == NO_WITNESS_COMMITMENT) {
91-
return invalid(); // require a witness commitment
91+
return nullopt; // require a witness commitment
9292
}
9393

9494
CScript& witness_commitment = modified_cb.vout.at(cidx).scriptPubKey;
@@ -101,9 +101,9 @@ SignetTxs SignetTxs::Create(const CBlock& block, const CScript& challenge)
101101
VectorReader v(SER_NETWORK, INIT_PROTO_VERSION, signet_solution, 0);
102102
v >> tx_spending.vin[0].scriptSig;
103103
v >> tx_spending.vin[0].scriptWitness.stack;
104-
if (!v.empty()) return invalid(); // extraneous data encountered
104+
if (!v.empty()) return nullopt; // extraneous data encountered
105105
} catch (const std::exception&) {
106-
return invalid(); // parsing error
106+
return nullopt; // parsing error
107107
}
108108
}
109109
uint256 signet_merkle = ComputeModifiedMerkleRoot(modified_cb, block);
@@ -117,7 +117,7 @@ SignetTxs SignetTxs::Create(const CBlock& block, const CScript& challenge)
117117
tx_to_spend.vin[0].scriptSig << block_data;
118118
tx_spending.vin[0].prevout = COutPoint(tx_to_spend.GetHash(), 0);
119119

120-
return {tx_to_spend, tx_spending};
120+
return SignetTxs{tx_to_spend, tx_spending};
121121
}
122122

123123
// Signet block solution checker
@@ -129,19 +129,19 @@ bool CheckSignetBlockSolution(const CBlock& block, const Consensus::Params& cons
129129
}
130130

131131
const CScript challenge(consensusParams.signet_challenge.begin(), consensusParams.signet_challenge.end());
132-
const SignetTxs signet_txs(block, challenge);
132+
const Optional<SignetTxs> signet_txs = SignetTxs::Create(block, challenge);
133133

134-
if (!signet_txs.m_valid) {
134+
if (!signet_txs) {
135135
LogPrint(BCLog::VALIDATION, "CheckSignetBlockSolution: Errors in block (block solution parse failure)\n");
136136
return false;
137137
}
138138

139-
const CScript& scriptSig = signet_txs.m_to_sign.vin[0].scriptSig;
140-
const CScriptWitness& witness = signet_txs.m_to_sign.vin[0].scriptWitness;
139+
const CScript& scriptSig = signet_txs->m_to_sign.vin[0].scriptSig;
140+
const CScriptWitness& witness = signet_txs->m_to_sign.vin[0].scriptWitness;
141141

142-
TransactionSignatureChecker sigcheck(&signet_txs.m_to_sign, /*nIn=*/ 0, /*amount=*/ signet_txs.m_to_spend.vout[0].nValue);
142+
TransactionSignatureChecker sigcheck(&signet_txs->m_to_sign, /*nIn=*/ 0, /*amount=*/ signet_txs->m_to_spend.vout[0].nValue);
143143

144-
if (!VerifyScript(scriptSig, signet_txs.m_to_spend.vout[0].scriptPubKey, &witness, BLOCK_SCRIPT_VERIFY_FLAGS, sigcheck)) {
144+
if (!VerifyScript(scriptSig, signet_txs->m_to_spend.vout[0].scriptPubKey, &witness, BLOCK_SCRIPT_VERIFY_FLAGS, sigcheck)) {
145145
LogPrint(BCLog::VALIDATION, "CheckSignetBlockSolution: Errors in block (block solution invalid)\n");
146146
return false;
147147
}

src/signet.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <primitives/block.h>
1010
#include <primitives/transaction.h>
1111

12+
#include <optional.h>
13+
1214
/**
1315
* Extract signature and check whether a block has a valid solution
1416
*/
@@ -22,21 +24,14 @@ bool CheckSignetBlockSolution(const CBlock& block, const Consensus::Params& cons
2224
* 2. It skips the nonce.
2325
*/
2426
class SignetTxs {
25-
private:
26-
struct invalid {};
27-
SignetTxs(invalid i) : m_to_spend(), m_to_sign(), m_valid(false) { }
28-
2927
template<class T1, class T2>
30-
SignetTxs(const T1& to_spend, const T2& to_sign) : m_to_spend{to_spend}, m_to_sign{to_sign}, m_valid(true) { }
31-
32-
static SignetTxs Create(const CBlock& block, const CScript& challenge);
28+
SignetTxs(const T1& to_spend, const T2& to_sign) : m_to_spend{to_spend}, m_to_sign{to_sign} { }
3329

3430
public:
35-
SignetTxs(const CBlock& block, const CScript& challenge) : SignetTxs(Create(block, challenge)) { }
31+
static Optional<SignetTxs> Create(const CBlock& block, const CScript& challenge);
3632

3733
const CTransaction m_to_spend;
3834
const CTransaction m_to_sign;
39-
const bool m_valid;
4035
};
4136

4237
#endif // BITCOIN_SIGNET_H

src/test/fuzz/signet.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include <primitives/block.h>
88
#include <signet.h>
99
#include <streams.h>
10-
#include <test/fuzz/fuzz.h>
1110
#include <test/fuzz/FuzzedDataProvider.h>
11+
#include <test/fuzz/fuzz.h>
1212
#include <test/fuzz/util.h>
1313

1414
#include <cstdint>
@@ -28,7 +28,5 @@ void test_one_input(const std::vector<uint8_t>& buffer)
2828
return;
2929
}
3030
(void)CheckSignetBlockSolution(*block, Params().GetConsensus());
31-
if (GetWitnessCommitmentIndex(*block) != NO_WITNESS_COMMITMENT) {
32-
(void)SignetTxs(*block, ConsumeScript(fuzzed_data_provider));
33-
}
31+
(void)SignetTxs::Create(*block, ConsumeScript(fuzzed_data_provider));
3432
}

0 commit comments

Comments
 (0)