Skip to content

Commit 2cad51b

Browse files
Merge dashpay#6016: backport: Merge bitcoin#22214, 22120, 21745
3b5dc9e Merge bitcoin#21745: refactor: Add missing includes in pubkey.cpp/pubkey.h (W. J. van der Laan) 1ee01c8 Merge bitcoin#22120: test: p2p_invalid_block: Check that a block rejected due to too-new tim… (MarcoFalke) bf72bea Merge bitcoin#22214: refactor: Rearrange fillPSBT arguments (fanquake) Pull request description: bitcoin backport Top commit has no ACKs. Tree-SHA512: 5b4ab7e898c8e0c3f465acc084f3c2136c8c8523d5cc813f042df8591967acff17a380a4173b7c6da63f6dca76773d8ad9811d68d290f3ddd198eaa6481bbacb
2 parents 1fc62c8 + 3b5dc9e commit 2cad51b

File tree

7 files changed

+33
-9
lines changed

7 files changed

+33
-9
lines changed

src/interfaces/wallet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ class Wallet
206206
virtual TransactionError fillPSBT(int sighash_type,
207207
bool sign,
208208
bool bip32derivs,
209+
size_t* n_signed,
209210
PartiallySignedTransaction& psbtx,
210-
bool& complete,
211-
size_t* n_signed) = 0;
211+
bool& complete) = 0;
212212

213213
//! Get balances.
214214
virtual WalletBalances getBalances() = 0;

src/pubkey.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55

66
#include <pubkey.h>
77

8+
#include <hash.h>
89
#include <secp256k1.h>
10+
#include <secp256k1_extrakeys.h>
911
#include <secp256k1_ellswift.h>
1012
#include <secp256k1_recovery.h>
13+
#include <span.h>
14+
#include <uint256.h>
1115

16+
#include <algorithm>
17+
#include <cassert>
1218
namespace {
1319

1420
struct Secp256k1SelfTester

src/pubkey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <uint256.h>
1313

1414
#include <array>
15-
#include <stdexcept>
15+
#include <cstring>
1616
#include <vector>
1717

1818
const unsigned int BIP32_EXTKEY_SIZE = 74;

src/qt/psbtoperationsdialog.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void PSBTOperationsDialog::openWithPSBT(PartiallySignedTransaction psbtx)
5050
bool complete;
5151
size_t n_could_sign;
5252
FinalizePSBT(psbtx); // Make sure all existing signatures are fully combined before checking for completeness.
53-
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, true /* bip32derivs */, m_transaction_data, complete, &n_could_sign);
53+
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, true /* bip32derivs */, &n_could_sign, m_transaction_data, complete);
5454
if (err != TransactionError::OK) {
5555
showStatus(tr("Failed to load transaction: %1")
5656
.arg(QString::fromStdString(TransactionErrorString(err).translated)), StatusLevel::ERR);
@@ -67,7 +67,7 @@ void PSBTOperationsDialog::signTransaction()
6767
{
6868
bool complete;
6969
size_t n_signed;
70-
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, true /* sign */, true /* bip32derivs */, m_transaction_data, complete, &n_signed);
70+
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, true /* sign */, true /* bip32derivs */, &n_signed, m_transaction_data, complete);
7171

7272
if (err != TransactionError::OK) {
7373
showStatus(tr("Failed to sign transaction: %1")
@@ -226,7 +226,7 @@ void PSBTOperationsDialog::showStatus(const QString &msg, StatusLevel level) {
226226
size_t PSBTOperationsDialog::couldSignInputs(const PartiallySignedTransaction &psbtx) {
227227
size_t n_signed;
228228
bool complete;
229-
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, false /* bip32derivs */, m_transaction_data, complete, &n_signed);
229+
TransactionError err = m_wallet_model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, false /* bip32derivs */, &n_signed, m_transaction_data, complete);
230230

231231
if (err != TransactionError::OK) {
232232
return 0;

src/qt/sendcoinsdialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ void SendCoinsDialog::sendButtonClicked([[maybe_unused]] bool checked)
487487
CMutableTransaction mtx = CMutableTransaction{*(m_current_transaction->getWtx())};
488488
PartiallySignedTransaction psbtx(mtx);
489489
bool complete = false;
490-
const TransactionError err = model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, true /* bip32derivs */, psbtx, complete, nullptr);
490+
const TransactionError err = model->wallet().fillPSBT(SIGHASH_ALL, false /* sign */, true /* bip32derivs */, nullptr, psbtx, complete);
491491
assert(!complete);
492492
assert(err == TransactionError::OK);
493493
// Serialize the PSBT

src/wallet/interfaces.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ class WalletImpl : public Wallet
367367
TransactionError fillPSBT(int sighash_type,
368368
bool sign,
369369
bool bip32derivs,
370+
size_t* n_signed,
370371
PartiallySignedTransaction& psbtx,
371-
bool& complete,
372-
size_t* n_signed) override
372+
bool& complete) override
373373
{
374374
return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs, n_signed);
375375
}

test/functional/p2p_invalid_block.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99
2) Invalid block with duplicated transaction should be re-requested.
1010
3) Invalid block with bad coinbase value should be rejected and not
1111
re-requested.
12+
4) Invalid block due to future timestamp is later accepted when that timestamp
13+
becomes valid.
1214
"""
1315
import copy
16+
import time
1417

1518
from test_framework.blocktools import create_block, create_coinbase, create_tx_with_script
1619
from test_framework.messages import COIN
1720
from test_framework.p2p import P2PDataStore
1821
from test_framework.test_framework import BitcoinTestFramework
1922
from test_framework.util import assert_equal
2023

24+
MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60
25+
2126

2227
class InvalidBlockRequestTest(BitcoinTestFramework):
2328
def set_test_params(self):
@@ -134,5 +139,18 @@ def run_test(self):
134139
self.log.info("Test inflation by duplicating input")
135140
peer.send_blocks_and_test([block4], node, success=False, reject_reason='bad-txns-inputs-duplicate')
136141

142+
self.log.info("Test accepting identical block after rejecting it due to a future timestamp.")
143+
t = int(time.time())
144+
node.setmocktime(t)
145+
# Set block time +1 second past max future validity
146+
block = create_block(tip, create_coinbase(height), t + MAX_FUTURE_BLOCK_TIME + 1)
147+
block.hashMerkleRoot = block.calc_merkle_root()
148+
block.solve()
149+
# Need force_send because the block will get rejected without a getdata otherwise
150+
peer.send_blocks_and_test([block], node, force_send=True, success=False, reject_reason='time-too-new')
151+
node.setmocktime(t + 1)
152+
peer.send_blocks_and_test([block], node, success=True)
153+
154+
137155
if __name__ == '__main__':
138156
InvalidBlockRequestTest().main()

0 commit comments

Comments
 (0)