diff options
author | MarcoFalke <falke.marco@gmail.com> | 2020-09-23 09:00:36 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2020-09-23 09:02:00 +0200 |
commit | 82198938255783d2593f42a652efc9921550d86d (patch) | |
tree | 23c5790e00f1a5f8c9c00af323d60aaabae20eb5 /src | |
parent | b1291b2e8fc39b366765d905200f022823e3d50b (diff) | |
parent | facaf9e61f4b9ea91fab554d495ebea1043d08fb (diff) | |
download | bitcoin-82198938255783d2593f42a652efc9921550d86d.tar.xz |
Merge #19993: refactor: Signet fixups
facaf9e61f4b9ea91fab554d495ebea1043d08fb doc: Document signet BIP (MarcoFalke)
faf0a26711eed9264113463e56b988cf9fe549fd doc: Update comments for new chain settings (-signet and -chain=signet) (MarcoFalke)
fae0548686cb3d095086d3f0fef38dcfcd31d8ca fuzz: Remove needless guard (MarcoFalke)
77771a03df6c5d940b340d15eb88f2ac9a29c13a refactor: Remove SignetTxs::m_valid and use optional instead (MarcoFalke)
fa2ad5dae17b237641b8ece0e68ffcdd79d543bf 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 facaf9e61f4b9ea91fab554d495ebea1043d08fb -- code review only
dr-orlovsky:
Reviewed & ACK https://github.com/bitcoin/bitcoin/pull/19993/commits/facaf9e61f4b9ea91fab554d495ebea1043d08fb
kallewoof:
Code review ACK facaf9e61f4b9ea91fab554d495ebea1043d08fb
Tree-SHA512: 8085027c488d84bb4bddccba78bd2d4c5af0d8e2644ee72265f1f30fa8c83f61a961d9da2c796f2940e69682291cbee7b1028b6a6ce123ad9134c0ebbf4723b0
Diffstat (limited to 'src')
-rw-r--r-- | src/bitcoin-cli.cpp | 10 | ||||
-rw-r--r-- | src/bitcoin-tx.cpp | 5 | ||||
-rw-r--r-- | src/bitcoin-wallet.cpp | 2 | ||||
-rw-r--r-- | src/bitcoind.cpp | 6 | ||||
-rw-r--r-- | src/qt/bitcoin.cpp | 2 | ||||
-rw-r--r-- | src/signet.cpp | 24 | ||||
-rw-r--r-- | src/signet.h | 13 | ||||
-rw-r--r-- | src/test/fuzz/signet.cpp | 6 |
8 files changed, 23 insertions, 45 deletions
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 198cd5eb52..e94d4dff49 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -87,11 +87,6 @@ static void libevent_log_cb(int severity, const char *msg) } } -////////////////////////////////////////////////////////////////////////////// -// -// Start -// - // // Exception thrown on connection error. This error is used to determine // when to wait if -rpcwait is given. @@ -112,9 +107,6 @@ public: // static int AppInitRPC(int argc, char* argv[]) { - // - // Parameters - // SetupCliArgs(gArgs); std::string error; if (!gArgs.ParseParameters(argc, argv, error)) { @@ -147,7 +139,7 @@ static int AppInitRPC(int argc, char* argv[]) tfm::format(std::cerr, "Error reading configuration file: %s\n", error); return EXIT_FAILURE; } - // Check for -chain, -testnet or -regtest parameter (BaseParams() calls are only valid after this clause) + // Check for chain settings (BaseParams() calls are only valid after this clause) try { SelectBaseParams(gArgs.GetChainName()); } catch (const std::exception& e) { diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index a9119d5144..085f1ecfda 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -78,9 +78,6 @@ static void SetupBitcoinTxArgs(ArgsManager &argsman) // static int AppInitRawTx(int argc, char* argv[]) { - // - // Parameters - // SetupBitcoinTxArgs(gArgs); std::string error; if (!gArgs.ParseParameters(argc, argv, error)) { @@ -88,7 +85,7 @@ static int AppInitRawTx(int argc, char* argv[]) return EXIT_FAILURE; } - // Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause) + // Check for chain settings (Params() calls are only valid after this clause) try { SelectParams(gArgs.GetChainName()); } catch (const std::exception& e) { diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index 06b0c86476..8fdf1bae0f 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -62,7 +62,7 @@ static bool WalletAppInit(int argc, char* argv[]) tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "")); return false; } - // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause) + // Check for chain settings (Params() calls are only valid after this clause) SelectParams(gArgs.GetChainName()); return true; diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 02074f820a..455a82e390 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -37,10 +37,6 @@ static void WaitForShutdown(NodeContext& node) Interrupt(node); } -////////////////////////////////////////////////////////////////////////////// -// -// Start -// static bool AppInit(int argc, char* argv[]) { NodeContext node; @@ -81,7 +77,7 @@ static bool AppInit(int argc, char* argv[]) if (!args.ReadConfigFiles(error, true)) { return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error))); } - // Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause) + // Check for chain settings (Params() calls are only valid after this clause) try { SelectParams(args.GetChainName()); } catch (const std::exception& e) { diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 7a3fb420cc..3055cd7da6 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -533,7 +533,7 @@ int GuiMain(int argc, char* argv[]) // - QSettings() will use the new application name after this, resulting in network-specific settings // - Needs to be done before createOptionsModel - // Check for -chain, -testnet or -regtest parameter (Params() calls are only valid after this clause) + // Check for chain settings (Params() calls are only valid after this clause) try { SelectParams(gArgs.GetChainName()); } catch(std::exception &e) { diff --git a/src/signet.cpp b/src/signet.cpp index a29f89b58e..e68f031aa4 100644 --- a/src/signet.cpp +++ b/src/signet.cpp @@ -65,7 +65,7 @@ static uint256 ComputeModifiedMerkleRoot(const CMutableTransaction& cb, const CB return ComputeMerkleRoot(std::move(leaves)); } -SignetTxs SignetTxs::Create(const CBlock& block, const CScript& challenge) +Optional<SignetTxs> SignetTxs::Create(const CBlock& block, const CScript& challenge) { CMutableTransaction tx_to_spend; tx_to_spend.nVersion = 0; @@ -83,12 +83,12 @@ SignetTxs SignetTxs::Create(const CBlock& block, const CScript& challenge) // responses from block coinbase tx // find and delete signet signature - if (block.vtx.empty()) return invalid(); // no coinbase tx in block; invalid + if (block.vtx.empty()) return nullopt; // no coinbase tx in block; invalid CMutableTransaction modified_cb(*block.vtx.at(0)); const int cidx = GetWitnessCommitmentIndex(block); if (cidx == NO_WITNESS_COMMITMENT) { - return invalid(); // require a witness commitment + return nullopt; // require a witness commitment } CScript& witness_commitment = modified_cb.vout.at(cidx).scriptPubKey; @@ -101,9 +101,9 @@ SignetTxs SignetTxs::Create(const CBlock& block, const CScript& challenge) VectorReader v(SER_NETWORK, INIT_PROTO_VERSION, signet_solution, 0); v >> tx_spending.vin[0].scriptSig; v >> tx_spending.vin[0].scriptWitness.stack; - if (!v.empty()) return invalid(); // extraneous data encountered + if (!v.empty()) return nullopt; // extraneous data encountered } catch (const std::exception&) { - return invalid(); // parsing error + return nullopt; // parsing error } } uint256 signet_merkle = ComputeModifiedMerkleRoot(modified_cb, block); @@ -117,7 +117,7 @@ SignetTxs SignetTxs::Create(const CBlock& block, const CScript& challenge) tx_to_spend.vin[0].scriptSig << block_data; tx_spending.vin[0].prevout = COutPoint(tx_to_spend.GetHash(), 0); - return {tx_to_spend, tx_spending}; + return SignetTxs{tx_to_spend, tx_spending}; } // Signet block solution checker @@ -129,19 +129,19 @@ bool CheckSignetBlockSolution(const CBlock& block, const Consensus::Params& cons } const CScript challenge(consensusParams.signet_challenge.begin(), consensusParams.signet_challenge.end()); - const SignetTxs signet_txs(block, challenge); + const Optional<SignetTxs> signet_txs = SignetTxs::Create(block, challenge); - if (!signet_txs.m_valid) { + if (!signet_txs) { LogPrint(BCLog::VALIDATION, "CheckSignetBlockSolution: Errors in block (block solution parse failure)\n"); return false; } - const CScript& scriptSig = signet_txs.m_to_sign.vin[0].scriptSig; - const CScriptWitness& witness = signet_txs.m_to_sign.vin[0].scriptWitness; + const CScript& scriptSig = signet_txs->m_to_sign.vin[0].scriptSig; + const CScriptWitness& witness = signet_txs->m_to_sign.vin[0].scriptWitness; - TransactionSignatureChecker sigcheck(&signet_txs.m_to_sign, /*nIn=*/ 0, /*amount=*/ signet_txs.m_to_spend.vout[0].nValue); + TransactionSignatureChecker sigcheck(&signet_txs->m_to_sign, /*nIn=*/ 0, /*amount=*/ signet_txs->m_to_spend.vout[0].nValue); - if (!VerifyScript(scriptSig, signet_txs.m_to_spend.vout[0].scriptPubKey, &witness, BLOCK_SCRIPT_VERIFY_FLAGS, sigcheck)) { + if (!VerifyScript(scriptSig, signet_txs->m_to_spend.vout[0].scriptPubKey, &witness, BLOCK_SCRIPT_VERIFY_FLAGS, sigcheck)) { LogPrint(BCLog::VALIDATION, "CheckSignetBlockSolution: Errors in block (block solution invalid)\n"); return false; } diff --git a/src/signet.h b/src/signet.h index 5694716fb6..23563a83c4 100644 --- a/src/signet.h +++ b/src/signet.h @@ -9,6 +9,8 @@ #include <primitives/block.h> #include <primitives/transaction.h> +#include <optional.h> + /** * Extract signature and check whether a block has a valid solution */ @@ -22,21 +24,14 @@ bool CheckSignetBlockSolution(const CBlock& block, const Consensus::Params& cons * 2. It skips the nonce. */ class SignetTxs { -private: - struct invalid {}; - SignetTxs(invalid i) : m_to_spend(), m_to_sign(), m_valid(false) { } - template<class T1, class T2> - SignetTxs(const T1& to_spend, const T2& to_sign) : m_to_spend{to_spend}, m_to_sign{to_sign}, m_valid(true) { } - - static SignetTxs Create(const CBlock& block, const CScript& challenge); + SignetTxs(const T1& to_spend, const T2& to_sign) : m_to_spend{to_spend}, m_to_sign{to_sign} { } public: - SignetTxs(const CBlock& block, const CScript& challenge) : SignetTxs(Create(block, challenge)) { } + static Optional<SignetTxs> Create(const CBlock& block, const CScript& challenge); const CTransaction m_to_spend; const CTransaction m_to_sign; - const bool m_valid; }; #endif // BITCOIN_SIGNET_H diff --git a/src/test/fuzz/signet.cpp b/src/test/fuzz/signet.cpp index 4736ae27f5..786f1a83fe 100644 --- a/src/test/fuzz/signet.cpp +++ b/src/test/fuzz/signet.cpp @@ -7,8 +7,8 @@ #include <primitives/block.h> #include <signet.h> #include <streams.h> -#include <test/fuzz/fuzz.h> #include <test/fuzz/FuzzedDataProvider.h> +#include <test/fuzz/fuzz.h> #include <test/fuzz/util.h> #include <cstdint> @@ -28,7 +28,5 @@ void test_one_input(const std::vector<uint8_t>& buffer) return; } (void)CheckSignetBlockSolution(*block, Params().GetConsensus()); - if (GetWitnessCommitmentIndex(*block) != NO_WITNESS_COMMITMENT) { - (void)SignetTxs(*block, ConsumeScript(fuzzed_data_provider)); - } + (void)SignetTxs::Create(*block, ConsumeScript(fuzzed_data_provider)); } |