Skip to content

Commit 5bf0409

Browse files
Merge #6300: backport: Merge bitcoin#23642, 22794, 23316, 24365, gui#517, 24219, 23253, 24449, 22543
3931608 Merge bitcoin#22543: test: Use MiniWallet in mempool_limit.py (merge-script) f147373 Merge bitcoin#24449: fuzz: FuzzedFileProvider::write should not return negative value (MarcoFalke) 2a2a269 Merge bitcoin#23253: bitcoin-tx: Reject non-integral and out of range int strings (W. J. van der Laan) 11eeae2 Merge bitcoin#24219: Fix implicit-integer-sign-change in bloom (MarcoFalke) f16265d Merge bitcoin-core/gui#517: refactor, qt: Use std::chrono for parameters of QTimer methods (Hennadii Stepanov) b212ca0 Merge bitcoin#24365: wallet: Don't generate keys for wallets with private keys disabled during upgradewallet (laanwj) 66e77f7 Merge bitcoin#23316: test: make the node param explicit in init_wallet() (MarcoFalke) 995cae4 Merge bitcoin#22794: test: Verify if wallet is compiled in rpc_invalid_address_message.py test (MarcoFalke) 61a0140 Merge bitcoin#23642: refactor: Call type-solver earlier in decodescript (MarcoFalke) Pull request description: Bitcoin Backports ACKs for top commit: UdjinM6: utACK 3931608 PastaPastaPasta: utACK 3931608 Tree-SHA512: 38f384776002e8014b2510aeaf1f4655fea0531011eb326eb2ab546d9e7193ad9e5c4b570d9831f88bb696e06ded04259a21ddb750d7ffedfedebdbb9a951379
2 parents a9cfd39 + 3931608 commit 5bf0409

23 files changed

+197
-103
lines changed

src/bitcoin-tx.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@ static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal)
220220
tx.nLockTime = (unsigned int) newLocktime;
221221
}
222222

223+
template <typename T>
224+
static T TrimAndParse(const std::string& int_str, const std::string& err)
225+
{
226+
const auto parsed{ToIntegral<T>(TrimString(int_str))};
227+
if (!parsed.has_value()) {
228+
throw std::runtime_error(err + " '" + int_str + "'");
229+
}
230+
return parsed.value();
231+
}
232+
223233
static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInput)
224234
{
225235
std::vector<std::string> vStrInputParts = SplitString(strInput, ':');
@@ -245,8 +255,9 @@ static void MutateTxAddInput(CMutableTransaction& tx, const std::string& strInpu
245255

246256
// extract the optional sequence number
247257
uint32_t nSequenceIn = CTxIn::SEQUENCE_FINAL;
248-
if (vStrInputParts.size() > 2)
249-
nSequenceIn = std::stoul(vStrInputParts[2]);
258+
if (vStrInputParts.size() > 2) {
259+
nSequenceIn = TrimAndParse<uint32_t>(vStrInputParts.at(2), "invalid TX sequence id");
260+
}
250261

251262
// append to transaction input list
252263
CTxIn txin(txid, vout, CScript(), nSequenceIn);
@@ -324,10 +335,10 @@ static void MutateTxAddOutMultiSig(CMutableTransaction& tx, const std::string& s
324335
CAmount value = ExtractAndValidateValue(vStrInputParts[0]);
325336

326337
// Extract REQUIRED
327-
uint32_t required = stoul(vStrInputParts[1]);
338+
const uint32_t required{TrimAndParse<uint32_t>(vStrInputParts.at(1), "invalid multisig required number")};
328339

329340
// Extract NUMKEYS
330-
uint32_t numkeys = stoul(vStrInputParts[2]);
341+
const uint32_t numkeys{TrimAndParse<uint32_t>(vStrInputParts.at(2), "invalid multisig total number")};
331342

332343
// Validate there are the correct number of pubkeys
333344
if (vStrInputParts.size() < numkeys + 3)

src/common/bloom.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ void CRollingBloomFilter::insert(Span<const unsigned char> vKey)
314314
/* FastMod works with the upper bits of h, so it is safe to ignore that the lower bits of h are already used for bit. */
315315
uint32_t pos = FastRange32(h, data.size());
316316
/* The lowest bit of pos is ignored, and set to zero for the first bit, and to one for the second. */
317-
data[pos & ~1] = (data[pos & ~1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration & 1)) << bit;
318-
data[pos | 1] = (data[pos | 1] & ~(((uint64_t)1) << bit)) | ((uint64_t)(nGeneration >> 1)) << bit;
317+
data[pos & ~1U] = (data[pos & ~1U] & ~(uint64_t{1} << bit)) | (uint64_t(nGeneration & 1)) << bit;
318+
data[pos | 1] = (data[pos | 1] & ~(uint64_t{1} << bit)) | (uint64_t(nGeneration >> 1)) << bit;
319319
}
320320
}
321321

@@ -326,7 +326,7 @@ bool CRollingBloomFilter::contains(Span<const unsigned char> vKey) const
326326
int bit = h & 0x3F;
327327
uint32_t pos = FastRange32(h, data.size());
328328
/* If the relevant bit is not set in either data[pos & ~1] or data[pos | 1], the filter does not contain vKey */
329-
if (!(((data[pos & ~1] | data[pos | 1]) >> bit) & 1)) {
329+
if (!(((data[pos & ~1U] | data[pos | 1]) >> bit) & 1)) {
330330
return false;
331331
}
332332
}

src/qt/bitcoin.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#endif // ENABLE_WALLET
4545

4646
#include <boost/signals2/connection.hpp>
47+
#include <chrono>
4748
#include <memory>
4849

4950
#include <QApplication>
@@ -397,10 +398,10 @@ void BitcoinApplication::initializeResult(bool success, interfaces::BlockAndHead
397398
connect(paymentServer, &PaymentServer::message, [this](const QString& title, const QString& message, unsigned int style) {
398399
window->message(title, message, style);
399400
});
400-
QTimer::singleShot(100, paymentServer, &PaymentServer::uiReady);
401+
QTimer::singleShot(100ms, paymentServer, &PaymentServer::uiReady);
401402
}
402403
#endif
403-
pollShutdownTimer->start(200);
404+
pollShutdownTimer->start(SHUTDOWN_POLLING_DELAY);
404405
} else {
405406
Q_EMIT splashFinished(); // Make sure splash screen doesn't stick around during shutdown
406407
quit(); // Exit first main loop invocation

src/qt/clientmodel.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <netbase.h>
2222
#include <util/system.h>
2323
#include <util/threadnames.h>
24+
#include <util/time.h>
2425
#include <validation.h>
2526

2627
#include <stdint.h>
@@ -323,7 +324,7 @@ static void BlockTipChanged(ClientModel* clientmodel, SynchronizationState sync_
323324
const bool throttle = (sync_state != SynchronizationState::POST_INIT && !fHeader) || sync_state == SynchronizationState::INIT_REINDEX;
324325
const int64_t now = throttle ? GetTimeMillis() : 0;
325326
int64_t& nLastUpdateNotification = fHeader ? nLastHeaderTipUpdateNotification : nLastBlockTipUpdateNotification;
326-
if (throttle && now < nLastUpdateNotification + MODEL_UPDATE_DELAY) {
327+
if (throttle && now < nLastUpdateNotification + count_milliseconds(MODEL_UPDATE_DELAY)) {
327328
return;
328329
}
329330

src/qt/guiconstants.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
#ifndef BITCOIN_QT_GUICONSTANTS_H
77
#define BITCOIN_QT_GUICONSTANTS_H
88

9+
#include <chrono>
910
#include <cstdint>
1011

11-
/* Milliseconds between model updates */
12-
static const int MODEL_UPDATE_DELAY = 250;
12+
using namespace std::chrono_literals;
13+
14+
/* A delay between model updates */
15+
static constexpr auto MODEL_UPDATE_DELAY{250ms};
16+
17+
/* A delay between shutdown pollings */
18+
static constexpr auto SHUTDOWN_POLLING_DELAY{200ms};
1319

1420
/* AskPassphraseDialog -- Maximum passphrase length */
1521
static const int MAX_PASSPHRASE_SIZE = 1024;

src/qt/optionsdialog.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <util/underlying.h>
2525

2626
#include <QButtonGroup>
27+
#include <chrono>
28+
2729
#include <QDataWidgetMapper>
2830
#include <QDir>
2931
#include <QIntValidator>
@@ -457,7 +459,7 @@ void OptionsDialog::showRestartWarning(bool fPersistent)
457459
ui->statusLabel->setText(tr("This change would require a client restart."));
458460
// clear non-persistent status label after 10 seconds
459461
// Todo: should perhaps be a class attribute, if we extend the use of statusLabel
460-
QTimer::singleShot(10000, this, &OptionsDialog::clearStatusLabel);
462+
QTimer::singleShot(10s, this, &OptionsDialog::clearStatusLabel);
461463
}
462464
}
463465

src/qt/sendcoinsdialog.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
#include <node/interface_ui.h>
2525
#include <policy/fees.h>
2626
#include <txmempool.h>
27+
#include <validation.h>
2728
#include <wallet/coincontrol.h>
2829
#include <wallet/fees.h>
2930
#include <wallet/wallet.h>
30-
#include <validation.h>
31+
#include <chrono>
3132

3233
#include <array>
3334
#include <fstream>
@@ -1080,7 +1081,7 @@ SendConfirmationDialog::SendConfirmationDialog(const QString& title, const QStri
10801081
int SendConfirmationDialog::exec()
10811082
{
10821083
updateYesButton();
1083-
countDownTimer.start(1000);
1084+
countDownTimer.start(1s);
10841085
return QMessageBox::exec();
10851086
}
10861087

src/qt/test/addressbooktests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <wallet/wallet.h>
2020
#include <walletinitinterface.h>
2121

22+
#include <chrono>
23+
2224
#include <QApplication>
2325
#include <QTimer>
2426
#include <QMessageBox>
@@ -39,7 +41,7 @@ void EditAddressAndSubmit(
3941
dialog->findChild<QLineEdit*>("labelEdit")->setText(label);
4042
dialog->findChild<QValidatedLineEdit*>("addressEdit")->setText(address);
4143

42-
ConfirmMessage(&warning_text, 5);
44+
ConfirmMessage(&warning_text, 5ms);
4345
dialog->accept();
4446
QCOMPARE(warning_text, expected_msg);
4547
}

src/qt/test/util.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <chrono>
6+
57
#include <QApplication>
68
#include <QMessageBox>
79
#include <QPushButton>
810
#include <QString>
911
#include <QTimer>
1012
#include <QWidget>
1113

12-
void ConfirmMessage(QString* text, int msec)
14+
void ConfirmMessage(QString* text, std::chrono::milliseconds msec)
1315
{
1416
QTimer::singleShot(msec, [text]() {
1517
for (QWidget* widget : QApplication::topLevelWidgets()) {

src/qt/test/util.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
#ifndef BITCOIN_QT_TEST_UTIL_H
66
#define BITCOIN_QT_TEST_UTIL_H
77

8-
#include <QString>
8+
#include <chrono>
9+
10+
QT_BEGIN_NAMESPACE
11+
class QString;
12+
QT_END_NAMESPACE
913

1014
/**
1115
* Press "Ok" button in message box dialog.
1216
*
1317
* @param text - Optionally store dialog text.
1418
* @param msec - Number of milliseconds to pause before triggering the callback.
1519
*/
16-
void ConfirmMessage(QString* text = nullptr, int msec = 0);
20+
void ConfirmMessage(QString* text, std::chrono::milliseconds msec);
1721

1822
#endif // BITCOIN_QT_TEST_UTIL_H

src/qt/test/wallettests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <qt/recentrequeststablemodel.h>
2626
#include <qt/receiverequestdialog.h>
2727

28+
#include <chrono>
2829
#include <memory>
2930

3031
#include <QAbstractButton>

src/qt/transactionview.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <optional>
2424

2525
#include <QCalendarWidget>
26+
#include <chrono>
2627
#include <QComboBox>
2728
#include <QDateTimeEdit>
2829
#include <QDesktopServices>
@@ -114,8 +115,8 @@ TransactionView::TransactionView(QWidget* parent) :
114115
amountWidget->setObjectName("amountWidget");
115116
hlayout->addWidget(amountWidget);
116117

117-
// Delay before filtering transactions in ms
118-
static const int input_filter_delay = 200;
118+
// Delay before filtering transactions
119+
static constexpr auto input_filter_delay{200ms};
119120

120121
QTimer* amount_typing_delay = new QTimer(this);
121122
amount_typing_delay->setSingleShot(true);

src/qt/walletcontroller.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <wallet/wallet.h>
2222

2323
#include <algorithm>
24+
#include <chrono>
2425

2526
#include <QApplication>
2627
#include <QMessageBox>
@@ -271,12 +272,12 @@ void CreateWalletActivity::createWallet()
271272
flags |= WALLET_FLAG_DESCRIPTORS;
272273
}
273274

274-
QTimer::singleShot(500, worker(), [this, name, flags] {
275+
QTimer::singleShot(500ms, worker(), [this, name, flags] {
275276
std::unique_ptr<interfaces::Wallet> wallet = node().walletLoader().createWallet(name, m_passphrase, flags, m_error_message, m_warning_message);
276277

277278
if (wallet) m_wallet_model = m_wallet_controller->getOrCreateWallet(std::move(wallet));
278279

279-
QTimer::singleShot(500, this, &CreateWalletActivity::finish);
280+
QTimer::singleShot(500ms, this, &CreateWalletActivity::finish);
280281
});
281282
}
282283

src/rpc/rawtransaction.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -874,29 +874,30 @@ static RPCHelpMan decoderawtransaction()
874874

875875
static RPCHelpMan decodescript()
876876
{
877-
return RPCHelpMan{"decodescript",
878-
"\nDecode a hex-encoded script.\n",
879-
{
880-
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded script"},
881-
},
882-
RPCResult{
883-
RPCResult::Type::OBJ, "", "",
877+
return RPCHelpMan{
878+
"decodescript",
879+
"\nDecode a hex-encoded script.\n",
880+
{
881+
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "the hex-encoded script"},
882+
},
883+
RPCResult{
884+
RPCResult::Type::OBJ, "", "",
885+
{
886+
{RPCResult::Type::STR, "asm", "Script public key"},
887+
{RPCResult::Type::STR, "type", "The output type (e.g. " + GetAllOutputTypes() + ")"},
888+
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
889+
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
890+
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
884891
{
885-
{RPCResult::Type::STR, "asm", "Script public key"},
886-
{RPCResult::Type::STR, "type", "The output type (e.g. "+GetAllOutputTypes()+")"},
887-
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},
888-
{RPCResult::Type::NUM, "reqSigs", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Number of required signatures"},
889-
{RPCResult::Type::ARR, "addresses", /* optional */ true, "(DEPRECATED, returned only if config option -deprecatedrpc=addresses is passed) Array of Dash addresses",
890-
{
891-
{RPCResult::Type::STR, "address", "Dash address"},
892-
}},
893-
{RPCResult::Type::STR, "p2sh", "address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH)"},
894-
}
895-
},
896-
RPCExamples{
897-
HelpExampleCli("decodescript", "\"hexstring\"")
898-
+ HelpExampleRpc("decodescript", "\"hexstring\"")
899-
},
892+
{RPCResult::Type::STR, "address", "Dash address"},
893+
}},
894+
{RPCResult::Type::STR, "p2sh", "address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH)"},
895+
},
896+
},
897+
RPCExamples{
898+
HelpExampleCli("decodescript", "\"hexstring\"")
899+
+ HelpExampleRpc("decodescript", "\"hexstring\"")
900+
},
900901
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
901902
{
902903
RPCTypeCheck(request.params, {UniValue::VSTR});
@@ -911,11 +912,10 @@ static RPCHelpMan decodescript()
911912
}
912913
ScriptPubKeyToUniv(script, r, /* fIncludeHex */ false);
913914

914-
UniValue type;
915-
916-
type = find_value(r, "type");
915+
std::vector<std::vector<unsigned char>> solutions_data;
916+
const TxoutType which_type{Solver(script, solutions_data)};
917917

918-
if (type.isStr() && type.get_str() != "scripthash") {
918+
if (which_type != TxoutType::SCRIPTHASH) {
919919
// P2SH cannot be wrapped in a P2SH. If this script is already a P2SH,
920920
// don't return the address for a P2SH of the P2SH.
921921
r.pushKV("p2sh", EncodeDestination(ScriptHash(script)));

src/test/fuzz/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ ssize_t FuzzedFileProvider::write(void* cookie, const char* buf, size_t size)
461461
SetFuzzedErrNo(fuzzed_file->m_fuzzed_data_provider);
462462
const ssize_t n = fuzzed_file->m_fuzzed_data_provider.ConsumeIntegralInRange<ssize_t>(0, size);
463463
if (AdditionOverflow(fuzzed_file->m_offset, (int64_t)n)) {
464-
return fuzzed_file->m_fuzzed_data_provider.ConsumeBool() ? 0 : -1;
464+
return 0;
465465
}
466466
fuzzed_file->m_offset += n;
467467
return n;

0 commit comments

Comments
 (0)