Skip to content

Commit 37e026a

Browse files
b23d94b partial bitcoin#23706: getblockfrompeer followups (Kittywhiskers Van Gogh) 7e5cc5e merge bitcoin#23702: Add missing optional to getblockfrompeer (Kittywhiskers Van Gogh) c294457 merge bitcoin#20295: getblockfrompeer (Kittywhiskers Van Gogh) 63ac87f merge bitcoin#22722: update estimatesmartfee rpc to return max of estimateSmartFee, mempoolMinFee and minRelayTxFee. (Kittywhiskers Van Gogh) 07e4c2c merge bitcoin#21934: Include versionbits signalling details during LOCKED_IN (Kittywhiskers Van Gogh) 960e768 merge bitcoin#19651: importdescriptors update existing (Kittywhiskers Van Gogh) 1f31823 merge bitcoin#21910: remove redundant fOnlySafe argument (Kittywhiskers Van Gogh) 69c5aa8 merge bitcoin#21359: include_unsafe option for fundrawtransaction (Kittywhiskers Van Gogh) 169dce7 merge bitcoin#20286: deprecate addresses and reqSigs from rpc outputs (Kittywhiskers Van Gogh) 7cddf70 merge bitcoin#20867: Support up to 20 keys for multisig under Segwit context (Kittywhiskers Van Gogh) 7c59923 merge bitcoin#18344: Fix nit in getblockchaininfo (Kittywhiskers Van Gogh) ec0803a refactor: align `TxToUniv` argument list with upstream (Kittywhiskers Van Gogh) Pull request description: ## Additional Information * Closes dashpay#6000 * `TxToUniv`'s argument list needed to be rearranged to match upstream as closely as possible (i.e. placing Dash-specific arguments at the end of the list to allow for code to be backported unmodified, relying on default arguments instead of having to modify each invocation to insert the default argument in between). This was due to a new `TxToUniv` variant being introduced in [bitcoin#20286](bitcoin#20286) * The maximum number of public keys in a multisig remains the same. The upper limit for bare multisigs is and always has been `MAX_PUBKEYS_PER_MULTISIG` ([source](https://github.com/dashpay/dash/blob/19512988c6e6e8641245bd9c5fab21dd737561f0/src/script/interpreter.cpp#L1143-L1144)), which has always been 20 ([source](https://github.com/dashpay/dash/blob/19512988c6e6e8641245bd9c5fab21dd737561f0/src/script/script.h#L28-L29)). The limit of up to 16 comes from P2SH overhead ([source](https://github.com/dashpay/dash/blob/19512988c6e6e8641245bd9c5fab21dd737561f0/src/script/descriptor.cpp#L877-L880)) and that hasn't changed. In effect, what [bitcoin#20867](bitcoin#20867) does to Dash Core is change the error from "too many public keys" (as we'll be testing against the bare multisig limit) to "excessive redeemScript size" ([source](https://github.com/dashpay/dash/blob/19512988c6e6e8641245bd9c5fab21dd737561f0/src/rpc/util.cpp#L223-L225)) (which is the _true_ limitation). * Backporting [bitcoin#21934](bitcoin#21934) required a minor change in the condition needed to emit `activation_height` as `has_signal` in the preceding block will evaluate true for both `STARTED` and `LOCKED_IN` while earlier it would only for `STARTED`. * In [bitcoin#22722](bitcoin#22722), a `self.stop_node` had to be added to account for the absurd fee warning that a new test condition introduces. * [bitcoin#23706](bitcoin#23706) is partial due to commits in it that rely on RPC type enforcement, which is currently not implemented in Dash Core. * `feature_dip3_deterministicmns.py` depends on the reporting of `addresses` to validate multisigs containing expected payees. There is no replacement RPC call to report the pubkeys that compose a multisig address. In the interm, the `-deprecatedrpc=addresses` flag has been enabled to allow the test to run otherwise unmodified. ## Breaking Changes * The following RPCs: `gettxout`, `getrawtransaction`, `decoderawtransaction`, `decodescript`, `gettransaction`, and REST endpoints: `/rest/tx`, `/rest/getutxos`, `/rest/block` deprecated the following fields (which are no longer returned in the responses by default): `addresses`, `reqSigs`. The `-deprecatedrpc=addresses` flag must be passed for these fields to be included in the RPC response. Note that these fields are attributes of the `scriptPubKey` object returned in the RPC response. However, in the response of `decodescript` these fields are top-level attributes, and included again as attributes of the `scriptPubKey` object. * When creating a hex-encoded Dash transaction using the `dash-tx` utility with the `-json` option set, the following fields: `addresses`, `reqSigs` are no longer returned in the tx output of the response. * The error message for attempts at making multisigs with >16 pubkeys will change to an "excessive redeemScript size" instead of the previous "too many public keys". ## Checklist: - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)** - [x] I have added or updated relevant unit/integration/functional/e2e tests - [x] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_ ACKs for top commit: UdjinM6: utACK b23d94b PastaPastaPasta: utACK b23d94b Tree-SHA512: 659d9ba3a0a9f8594b307a7056ab172309d5a0d9efec605bc4b345f7e0fb1032ad303af9e8f51dbd6549e82d0b738ad41eae8a5b3aebf59081f39df0d4b5ec7c
2 parents f542e8e + b23d94b commit 37e026a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1003
-365
lines changed

doc/REST-interface.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,8 @@ $ curl localhost:19998/rest/getutxos/checkmempool/b2cdfd7b89def827ff8af7cd9bff76
9898
"scriptPubKey" : {
9999
"asm" : "OP_DUP OP_HASH160 1c7cebb529b86a04c683dfa87be49de35bcf589e OP_EQUALVERIFY OP_CHECKSIG",
100100
"hex" : "76a9141c7cebb529b86a04c683dfa87be49de35bcf589e88ac",
101-
"reqSigs" : 1,
102101
"type" : "pubkeyhash",
103-
"addresses" : [
104-
"mi7as51dvLJsizWnTMurtRmrP8hG2m1XvD"
105-
]
102+
"address" : "mi7as51dvLJsizWnTMurtRmrP8hG2m1XvD"
106103
}
107104
}
108105
]

doc/release-notes-20286.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Updated RPCs
2+
------------
3+
4+
- The following RPCs: `gettxout`, `getrawtransaction`, `decoderawtransaction`,
5+
`decodescript`, `gettransaction`, and REST endpoints: `/rest/tx`,
6+
`/rest/getutxos`, `/rest/block` deprecated the following fields (which are no
7+
longer returned in the responses by default): `addresses`, `reqSigs`.
8+
The `-deprecatedrpc=addresses` flag must be passed for these fields to be
9+
included in the RPC response. Note that these fields are attributes of
10+
the `scriptPubKey` object returned in the RPC response. However, in the response
11+
of `decodescript` these fields are top-level attributes, and included again as attributes
12+
of the `scriptPubKey` object.
13+
14+
- When creating a hex-encoded Dash transaction using the `dash-tx` utility
15+
with the `-json` option set, the following fields: `addresses`, `reqSigs` are no longer
16+
returned in the tx output of the response.

doc/release-notes-21359.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Wallet
2+
------
3+
4+
- The `fundrawtransaction`, `send` and `walletcreatefundedpsbt` RPCs now support an `include_unsafe` option
5+
that when `true` allows using unsafe inputs to fund the transaction.
6+
Note that the resulting transaction may become invalid if one of the unsafe inputs disappears.
7+
If that happens, the transaction must be funded with different inputs and republished.

src/Makefile.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ BITCOIN_CORE_H = \
287287
rpc/blockchain.h \
288288
rpc/client.h \
289289
rpc/mining.h \
290-
rpc/net.h \
291290
rpc/protocol.h \
292291
rpc/rawtransaction_util.h \
293292
rpc/register.h \
294293
rpc/request.h \
295294
rpc/server.h \
295+
rpc/server_util.h \
296296
rpc/util.h \
297297
saltedhasher.h \
298298
scheduler.h \
@@ -510,6 +510,7 @@ libbitcoin_server_a_SOURCES = \
510510
rpc/quorums.cpp \
511511
rpc/rawtransaction.cpp \
512512
rpc/server.cpp \
513+
rpc/server_util.cpp \
513514
script/sigcache.cpp \
514515
shutdown.cpp \
515516
spork.cpp \

src/bitcoin-tx.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ static void MutateTx(CMutableTransaction& tx, const std::string& command,
676676
static void OutputTxJSON(const CTransaction& tx)
677677
{
678678
UniValue entry(UniValue::VOBJ);
679-
TxToUniv(tx, uint256(), entry);
679+
TxToUniv(tx, uint256(), /* include_addresses */ false, entry);
680680

681681
std::string jsonOutput = entry.write(4);
682682
tfm::format(std::cout, "%s\n", jsonOutput);

src/coinjoin/client.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ bool CCoinJoinClientSession::CreateCollateralTransaction(CMutableTransaction& tx
15381538
CCoinControl coin_control;
15391539
coin_control.nCoinType = CoinType::ONLY_COINJOIN_COLLATERAL;
15401540

1541-
m_wallet.AvailableCoins(vCoins, true, &coin_control);
1541+
m_wallet.AvailableCoins(vCoins, &coin_control);
15421542

15431543
if (vCoins.empty()) {
15441544
strReason = strprintf("%s requires a collateral transaction and could not locate an acceptable input!", gCoinJoinName);

src/core_io.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ UniValue ValueFromAmount(const CAmount amount);
4545
std::string FormatScript(const CScript& script);
4646
std::string EncodeHexTx(const CTransaction& tx);
4747
std::string SighashToStr(unsigned char sighash_type);
48-
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
48+
void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex, bool include_addresses);
4949
void ScriptToUniv(const CScript& script, UniValue& out, bool include_address);
50-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, const CSpentIndexTxInfo* ptxSpentInfo = nullptr, const CTxUndo* txundo = nullptr);
50+
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex = true, const CTxUndo* txundo = nullptr, const CSpentIndexTxInfo* ptxSpentInfo = nullptr);
5151

5252
#endif // BITCOIN_CORE_IO_H

src/core_write.cpp

+16-8
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,13 @@ void ScriptToUniv(const CScript& script, UniValue& out, bool include_address)
166166
}
167167
}
168168

169+
// TODO: from v21 ("addresses" and "reqSigs" deprecated) this method should be refactored to remove the `include_addresses` option
170+
// this method can also be combined with `ScriptToUniv` as they will overlap
169171
void ScriptPubKeyToUniv(const CScript& scriptPubKey,
170-
UniValue& out, bool fIncludeHex)
172+
UniValue& out, bool fIncludeHex, bool include_addresses)
171173
{
172174
TxoutType type;
175+
CTxDestination address;
173176
std::vector<CTxDestination> addresses;
174177
int nRequired;
175178

@@ -182,17 +185,22 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey,
182185
return;
183186
}
184187

185-
out.pushKV("reqSigs", nRequired);
188+
if (ExtractDestination(scriptPubKey, address)) {
189+
out.pushKV("address", EncodeDestination(address));
190+
}
186191
out.pushKV("type", GetTxnOutputType(type));
187192

188-
UniValue a(UniValue::VARR);
189-
for (const CTxDestination& addr : addresses) {
190-
a.push_back(EncodeDestination(addr));
193+
if (include_addresses) {
194+
UniValue a(UniValue::VARR);
195+
for (const CTxDestination& addr : addresses) {
196+
a.push_back(EncodeDestination(addr));
197+
}
198+
out.pushKV("addresses", a);
199+
out.pushKV("reqSigs", nRequired);
191200
}
192-
out.pushKV("addresses", a);
193201
}
194202

195-
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex, const CSpentIndexTxInfo* ptxSpentInfo, const CTxUndo* txundo)
203+
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, bool include_addresses, UniValue& entry, bool include_hex, const CTxUndo* txundo, const CSpentIndexTxInfo* ptxSpentInfo)
196204
{
197205
uint256 txid = tx.GetHash();
198206
entry.pushKV("txid", txid.GetHex());
@@ -260,7 +268,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
260268
out.pushKV("n", (int64_t)i);
261269

262270
UniValue o(UniValue::VOBJ);
263-
ScriptPubKeyToUniv(txout.scriptPubKey, o, true);
271+
ScriptPubKeyToUniv(txout.scriptPubKey, o, true, include_addresses);
264272
out.pushKV("scriptPubKey", o);
265273

266274
// Add spent information if spentindex is enabled

src/net_processing.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ class PeerManagerImpl final : public PeerManager
398398

399399
/** Implement PeerManager */
400400
void CheckForStaleTipAndEvictPeers() override;
401+
std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) override;
401402
bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
402403
bool IgnoresIncomingTxs() override { return m_ignore_incoming_txs; }
403404
void SendPings() override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);;
@@ -1862,6 +1863,39 @@ bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex)
18621863
(GetBlockProofEquivalentTime(*pindexBestHeader, *pindex, *pindexBestHeader, m_chainparams.GetConsensus()) < STALE_RELAY_AGE_LIMIT);
18631864
}
18641865

1866+
std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBlockIndex& block_index)
1867+
{
1868+
if (fImporting) return "Importing...";
1869+
if (fReindex) return "Reindexing...";
1870+
1871+
LOCK(cs_main);
1872+
// Ensure this peer exists and hasn't been disconnected
1873+
CNodeState* state = State(peer_id);
1874+
if (state == nullptr) return "Peer does not exist";
1875+
1876+
// Mark block as in-flight unless it already is (for this peer).
1877+
// If a block was already in-flight for a different peer, its BLOCKTXN
1878+
// response will be dropped.
1879+
const uint256& hash{block_index.GetBlockHash()};
1880+
if (!MarkBlockAsInFlight(peer_id, hash, &block_index)) return "Already requested from this peer";
1881+
1882+
// Construct message to request the block
1883+
std::vector<CInv> invs{CInv(MSG_BLOCK, hash)};
1884+
1885+
// Send block request message to the peer
1886+
bool success = m_connman.ForNode(peer_id, [this, &invs](CNode* node) {
1887+
const CNetMsgMaker msgMaker(node->GetCommonVersion());
1888+
this->m_connman.PushMessage(node, msgMaker.Make(NetMsgType::GETDATA, invs));
1889+
return true;
1890+
});
1891+
1892+
if (!success) return "Peer not fully connected";
1893+
1894+
LogPrint(BCLog::NET, "Requesting block %s from peer=%d\n",
1895+
hash.ToString(), peer_id);
1896+
return std::nullopt;
1897+
}
1898+
18651899
std::unique_ptr<PeerManager> PeerManager::make(const CChainParams& chainparams, CConnman& connman, AddrMan& addrman, BanMan* banman,
18661900
CScheduler &scheduler, ChainstateManager& chainman, CTxMemPool& pool,
18671901
CMasternodeMetaMan& mn_metaman, CMasternodeSync& mn_sync,

src/net_processing.h

+9
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ class PeerManager : public CValidationInterface, public NetEventsInterface
6666
const std::unique_ptr<LLMQContext>& llmq_ctx, bool ignore_incoming_txs);
6767
virtual ~PeerManager() { }
6868

69+
/**
70+
* Attempt to manually fetch block from a given peer. We must already have the header.
71+
*
72+
* @param[in] peer_id The peer id
73+
* @param[in] block_index The blockindex
74+
* @returns std::nullopt if a request was successfully made, otherwise an error message
75+
*/
76+
virtual std::optional<std::string> FetchBlock(NodeId peer_id, const CBlockIndex& block_index) = 0;
77+
6978
/** Get statistics from node state */
7079
virtual bool GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) const = 0;
7180

src/rest.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <rpc/blockchain.h>
2020
#include <rpc/protocol.h>
2121
#include <rpc/server.h>
22+
#include <rpc/server_util.h>
2223
#include <streams.h>
2324
#include <sync.h>
2425
#include <txmempool.h>

0 commit comments

Comments
 (0)