diff options
author | fanquake <fanquake@gmail.com> | 2024-01-05 10:37:42 +0000 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2024-01-05 10:42:10 +0000 |
commit | 143ace65db3943845125068d48feeb1168dfcb88 (patch) | |
tree | 695ce418811dc596f1c4d1e03e01d19433f51b06 /src | |
parent | d44554567f2726e572027a146516d87e4dcea2f5 (diff) | |
parent | fa46cc22bc696e6845915ae91d6b68e36bf4c242 (diff) |
Merge bitcoin/bitcoin#28890: rpc: Remove deprecated -rpcserialversion
fa46cc22bc696e6845915ae91d6b68e36bf4c242 Remove deprecated -rpcserialversion (MarcoFalke)
Pull request description:
The flag is problematic for many reasons:
* It is deprecated
* It is a global flag, requiring a restart to change, as opposed to a flag that can be set on each RPC invocation
* It may be hidden in config files by accident, hard to debug, causing LND crashes and bugs, see https://github.com/bitcoin/bitcoin/issues/28730#issuecomment-1780940868
* It makes performance improvements harder to implement: https://github.com/bitcoin/bitcoin/pull/17529#issuecomment-556082818
Fix all issues by removing it.
If there is a use-case, likely a per-RPC flag can be added, if needed.
ACKs for top commit:
ajtowns:
crACK fa46cc22bc696e6845915ae91d6b68e36bf4c242
TheCharlatan:
lgtm ACK fa46cc22bc696e6845915ae91d6b68e36bf4c242
Tree-SHA512: 96ba1c60356ce93954fe5c2a59045771c6d1516ad0d9dc436ef1800a1f1b0153f0d5fb78ca99d53ad54ba25fbce36962bdf1d4325aceedfc8154a61347a6a915
Diffstat (limited to 'src')
-rw-r--r-- | src/core_io.h | 4 | ||||
-rw-r--r-- | src/core_write.cpp | 12 | ||||
-rw-r--r-- | src/init.cpp | 11 | ||||
-rw-r--r-- | src/interfaces/chain.h | 3 | ||||
-rw-r--r-- | src/node/interfaces.cpp | 1 | ||||
-rw-r--r-- | src/rest.cpp | 8 | ||||
-rw-r--r-- | src/rpc/blockchain.cpp | 7 | ||||
-rw-r--r-- | src/rpc/mining.cpp | 2 | ||||
-rw-r--r-- | src/rpc/rawtransaction.cpp | 4 | ||||
-rw-r--r-- | src/rpc/server.cpp | 5 | ||||
-rw-r--r-- | src/rpc/server.h | 12 | ||||
-rw-r--r-- | src/wallet/rpc/transactions.cpp | 3 | ||||
-rw-r--r-- | src/zmq/zmqpublishnotifier.cpp | 4 |
13 files changed, 19 insertions, 57 deletions
diff --git a/src/core_io.h b/src/core_io.h index a104f240c1..4405f5c8f8 100644 --- a/src/core_io.h +++ b/src/core_io.h @@ -51,9 +51,9 @@ bool ParseHashStr(const std::string& strHex, uint256& result); // core_write.cpp UniValue ValueFromAmount(const CAmount amount); std::string FormatScript(const CScript& script); -std::string EncodeHexTx(const CTransaction& tx, const bool without_witness = false); +std::string EncodeHexTx(const CTransaction& tx); std::string SighashToStr(unsigned char sighash_type); void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex = true, bool include_address = false, const SigningProvider* provider = nullptr); -void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex = true, bool without_witness = false, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS); +void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex = true, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_DETAILS); #endif // BITCOIN_CORE_IO_H diff --git a/src/core_write.cpp b/src/core_write.cpp index a2be17d1aa..63f2c36b5a 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -140,14 +140,10 @@ std::string ScriptToAsmStr(const CScript& script, const bool fAttemptSighashDeco return str; } -std::string EncodeHexTx(const CTransaction& tx, const bool without_witness) +std::string EncodeHexTx(const CTransaction& tx) { DataStream ssTx; - if (without_witness) { - ssTx << TX_NO_WITNESS(tx); - } else { - ssTx << TX_WITH_WITNESS(tx); - } + ssTx << TX_WITH_WITNESS(tx); return HexStr(ssTx); } @@ -172,7 +168,7 @@ void ScriptToUniv(const CScript& script, UniValue& out, bool include_hex, bool i out.pushKV("type", GetTxnOutputType(type)); } -void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex, bool without_witness, const CTxUndo* txundo, TxVerbosity verbosity) +void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry, bool include_hex, const CTxUndo* txundo, TxVerbosity verbosity) { CHECK_NONFATAL(verbosity >= TxVerbosity::SHOW_DETAILS); @@ -268,6 +264,6 @@ void TxToUniv(const CTransaction& tx, const uint256& block_hash, UniValue& entry } if (include_hex) { - entry.pushKV("hex", EncodeHexTx(tx, without_witness)); // The hex-encoded transaction. Used the name "hex" to be consistent with the verbose output of "getrawtransaction". + entry.pushKV("hex", EncodeHexTx(tx)); // The hex-encoded transaction. Used the name "hex" to be consistent with the verbose output of "getrawtransaction". } } diff --git a/src/init.cpp b/src/init.cpp index 793eab2eab..39ee9fe60d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -655,7 +655,6 @@ void SetupServerArgs(ArgsManager& argsman) argsman.AddArg("-rpccookiefile=<loc>", "Location of the auth cookie. Relative paths will be prefixed by a net-specific datadir location. (default: data dir)", ArgsManager::ALLOW_ANY, OptionsCategory::RPC); argsman.AddArg("-rpcpassword=<pw>", "Password for JSON-RPC connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC); argsman.AddArg("-rpcport=<port>", strprintf("Listen for JSON-RPC connections on <port> (default: %u, testnet: %u, signet: %u, regtest: %u)", defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort(), signetBaseParams->RPCPort(), regtestBaseParams->RPCPort()), ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::RPC); - argsman.AddArg("-rpcserialversion", strprintf("Sets the serialization of raw transaction or block hex returned in non-verbose mode, non-segwit(0) (DEPRECATED) or segwit(1) (default: %d)", DEFAULT_RPC_SERIALIZE_VERSION), ArgsManager::ALLOW_ANY, OptionsCategory::RPC); argsman.AddArg("-rpcservertimeout=<n>", strprintf("Timeout during HTTP requests (default: %d)", DEFAULT_HTTP_SERVER_TIMEOUT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::RPC); argsman.AddArg("-rpcthreads=<n>", strprintf("Set the number of threads to service RPC calls (default: %d)", DEFAULT_HTTP_THREADS), ArgsManager::ALLOW_ANY, OptionsCategory::RPC); argsman.AddArg("-rpcuser=<user>", "Username for JSON-RPC connections", ArgsManager::ALLOW_ANY | ArgsManager::SENSITIVE, OptionsCategory::RPC); @@ -1025,16 +1024,6 @@ bool AppInitParameterInteraction(const ArgsManager& args) if (args.GetBoolArg("-peerbloomfilters", DEFAULT_PEERBLOOMFILTERS)) nLocalServices = ServiceFlags(nLocalServices | NODE_BLOOM); - if (args.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) < 0) - return InitError(Untranslated("rpcserialversion must be non-negative.")); - - if (args.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) > 1) - return InitError(Untranslated("Unknown rpcserialversion requested.")); - - if (args.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) == 0 && !IsDeprecatedRPCEnabled("serialversion")) { - return InitError(Untranslated("-rpcserialversion=0 is deprecated and will be removed in the future. Specify -deprecatedrpc=serialversion to allow anyway.")); - } - // Also report errors from parsing before daemonization { kernel::Notifications notifications{}; diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index 328399c4ad..9da5cb9637 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -335,9 +335,6 @@ public: //! Run function after given number of seconds. Cancel any previous calls with same name. virtual void rpcRunLater(const std::string& name, std::function<void()> fn, int64_t seconds) = 0; - //! Current RPC serialization flags. - virtual bool rpcSerializationWithoutWitness() = 0; - //! Get settings value. virtual common::SettingsValue getSetting(const std::string& arg) = 0; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 6963e928fe..5a8b7fc105 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -777,7 +777,6 @@ public: { RPCRunLater(name, std::move(fn), seconds); } - bool rpcSerializationWithoutWitness() override { return RPCSerializationWithoutWitness(); } common::SettingsValue getSetting(const std::string& name) override { return args().GetSetting(name); diff --git a/src/rest.cpp b/src/rest.cpp index e47b52fb53..fbbf6cfa84 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -316,7 +316,7 @@ static bool rest_block(const std::any& context, switch (rf) { case RESTResponseFormat::BINARY: { DataStream ssBlock; - ssBlock << RPCTxSerParams(block); + ssBlock << TX_WITH_WITNESS(block); std::string binaryBlock = ssBlock.str(); req->WriteHeader("Content-Type", "application/octet-stream"); req->WriteReply(HTTP_OK, binaryBlock); @@ -325,7 +325,7 @@ static bool rest_block(const std::any& context, case RESTResponseFormat::HEX: { DataStream ssBlock; - ssBlock << RPCTxSerParams(block); + ssBlock << TX_WITH_WITNESS(block); std::string strHex = HexStr(ssBlock) + "\n"; req->WriteHeader("Content-Type", "text/plain"); req->WriteReply(HTTP_OK, strHex); @@ -722,7 +722,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string switch (rf) { case RESTResponseFormat::BINARY: { DataStream ssTx; - ssTx << RPCTxSerParams(tx); + ssTx << TX_WITH_WITNESS(tx); std::string binaryTx = ssTx.str(); req->WriteHeader("Content-Type", "application/octet-stream"); @@ -732,7 +732,7 @@ static bool rest_tx(const std::any& context, HTTPRequest* req, const std::string case RESTResponseFormat::HEX: { DataStream ssTx; - ssTx << RPCTxSerParams(tx); + ssTx << TX_WITH_WITNESS(tx); std::string strHex = HexStr(ssTx) + "\n"; req->WriteHeader("Content-Type", "text/plain"); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index afd80d8788..1618987e82 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -187,7 +187,7 @@ UniValue blockToJSON(BlockManager& blockman, const CBlock& block, const CBlockIn // coinbase transaction (i.e. i == 0) doesn't have undo data const CTxUndo* txundo = (have_undo && i > 0) ? &blockUndo.vtxundo.at(i - 1) : nullptr; UniValue objTx(UniValue::VOBJ); - TxToUniv(*tx, /*block_hash=*/uint256(), /*entry=*/objTx, /*include_hex=*/true, /*without_witness=*/RPCSerializationWithoutWitness(), txundo, verbosity); + TxToUniv(*tx, /*block_hash=*/uint256(), /*entry=*/objTx, /*include_hex=*/true, txundo, verbosity); txs.push_back(objTx); } break; @@ -736,10 +736,9 @@ static RPCHelpMan getblock() const CBlock block{GetBlockChecked(chainman.m_blockman, *pblockindex)}; - if (verbosity <= 0) - { + if (verbosity <= 0) { DataStream ssBlock; - ssBlock << RPCTxSerParams(block); + ssBlock << TX_WITH_WITNESS(block); std::string strHex = HexStr(ssBlock); return strHex; } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index fdb694b5f1..31551dfe98 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -399,7 +399,7 @@ static RPCHelpMan generateblock() obj.pushKV("hash", block_out->GetHash().GetHex()); if (!process_new_block) { DataStream block_ser; - block_ser << RPCTxSerParams(*block_out); + block_ser << TX_WITH_WITNESS(*block_out); obj.pushKV("hex", HexStr(block_ser)); } return obj; diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index b1e6d677f8..634be2f7fb 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -62,7 +62,7 @@ static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& // Blockchain contextual information (confirmations and blocktime) is not // available to code in bitcoin-common, so we query them here and push the // data into the returned UniValue. - TxToUniv(tx, /*block_hash=*/uint256(), entry, /*include_hex=*/true, RPCSerializationWithoutWitness(), txundo, verbosity); + TxToUniv(tx, /*block_hash=*/uint256(), entry, /*include_hex=*/true, txundo, verbosity); if (!hashBlock.IsNull()) { LOCK(cs_main); @@ -383,7 +383,7 @@ static RPCHelpMan getrawtransaction() } if (verbosity <= 0) { - return EncodeHexTx(*tx, /*without_witness=*/RPCSerializationWithoutWitness()); + return EncodeHexTx(*tx); } UniValue result(UniValue::VOBJ); diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 4883341522..e1ac510cba 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -597,9 +597,4 @@ void RPCRunLater(const std::string& name, std::function<void()> func, int64_t nS deadlineTimers.emplace(name, std::unique_ptr<RPCTimerBase>(timerInterface->NewTimer(func, nSeconds*1000))); } -bool RPCSerializationWithoutWitness() -{ - return (gArgs.GetIntArg("-rpcserialversion", DEFAULT_RPC_SERIALIZE_VERSION) == 0); -} - CRPCTable tableRPC; diff --git a/src/rpc/server.h b/src/rpc/server.h index 9a49d82570..b8348e4aa6 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -16,8 +16,6 @@ #include <univalue.h> -static const unsigned int DEFAULT_RPC_SERIALIZE_VERSION = 1; - class CRPCCommand; namespace RPCServer @@ -183,14 +181,4 @@ void InterruptRPC(); void StopRPC(); std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq); -// Drop witness when serializing for RPC? -bool RPCSerializationWithoutWitness(); - -template<typename T> -auto RPCTxSerParams(T&& t) -{ - if (RPCSerializationWithoutWitness()) return TX_NO_WITNESS(t); - return TX_WITH_WITNESS(t); -} - #endif // BITCOIN_RPC_SERVER_H diff --git a/src/wallet/rpc/transactions.cpp b/src/wallet/rpc/transactions.cpp index cd7ed461f0..0e30d3e0fe 100644 --- a/src/wallet/rpc/transactions.cpp +++ b/src/wallet/rpc/transactions.cpp @@ -783,8 +783,7 @@ RPCHelpMan gettransaction() ListTransactions(*pwallet, wtx, 0, false, details, filter, /*filter_label=*/std::nullopt); entry.pushKV("details", details); - std::string strHex = EncodeHexTx(*wtx.tx, pwallet->chain().rpcSerializationWithoutWitness()); - entry.pushKV("hex", strHex); + entry.pushKV("hex", EncodeHexTx(*wtx.tx)); if (verbose) { UniValue decoded(UniValue::VOBJ); diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp index 54d125e47b..0f20706364 100644 --- a/src/zmq/zmqpublishnotifier.cpp +++ b/src/zmq/zmqpublishnotifier.cpp @@ -250,7 +250,7 @@ bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex) return false; } - ss << RPCTxSerParams(block); + ss << TX_WITH_WITNESS(block); return SendZmqMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size()); } @@ -260,7 +260,7 @@ bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &tr uint256 hash = transaction.GetHash(); LogPrint(BCLog::ZMQ, "Publish rawtx %s to %s\n", hash.GetHex(), this->address); DataStream ss; - ss << RPCTxSerParams(transaction); + ss << TX_WITH_WITNESS(transaction); return SendZmqMessage(MSG_RAWTX, &(*ss.begin()), ss.size()); } |