Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d526933
Merge #16026: Ensure that uncompressed public keys in a multisig alwa…
meshcollider Jun 21, 2019
3f491fa
fix: follow up backport bitcoin#16426
knst Feb 10, 2023
a6d4946
Merge #16786: test: add unit test for wallet watch-only methods invol…
Oct 10, 2019
57f92fc
fix: patches from bitcoin#17260 for new code in #16786: Split some CW…
knst Jan 24, 2023
08f3194
refactor: align header wallet.h with bitcoin's by moving some functiona
knst Feb 14, 2023
1bdd5f7
refactor: moved hdChainCurrent to scriptpubkeyman.
knst Feb 10, 2023
c89fd12
fix: follow-up bitcoin#17260 for dash specific code
knst Feb 16, 2023
16d2126
fix: follow up bitcoin#16301 - uncomment missing WalletBatch
knst Feb 17, 2023
0615c9f
Merge #14588: Refactor PSBT signing logic to enforce invariant and fi…
sipa Nov 10, 2018
ed88ba7
Merge #17261: Make ScriptPubKeyMan an actual interface and the wallet…
achow101 Oct 7, 2019
8f2b00e
Merge #18026: psbt_wallet_tests: use unique_ptr for GetSigningProvider
fanquake Jan 30, 2020
b89e80b
Merge #18067: wallet: Improve LegacyScriptPubKeyMan::CanProvide scrip…
meshcollider Feb 19, 2020
39ead66
Merge #18241: wallet/refactor: refer to CWallet immutably when possible
fanquake Mar 6, 2020
f812de4
Merge #18115: wallet: Pass in transactions and messages for signing i…
meshcollider Mar 9, 2020
ae22478
fix: do not use GetSolvingProvider for coinjoin signing
UdjinM6 Feb 26, 2023
25bdc26
Merge #19982: test: Fix inconsistent lock order in wallet_tests/Creat…
fanquake Dec 11, 2020
4ee15d2
Merge #19845: net: CNetAddr: add support to (un)serialize as ADDRv2
knst Feb 23, 2023
e9dc55d
Merge #20033: refactor: minor whitespace fixups, s/const/constexpr/ a…
Nov 16, 2020
7c38075
fix: avoid calling AddWallet before initializing ScriptPubKeyMans
UdjinM6 Feb 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ BITCOIN_CORE_H = \
node/transaction.h \
node/utxo_snapshot.h \
noui.h \
outputtype.h \
policy/feerate.h \
policy/fees.h \
policy/policy.h \
Expand Down Expand Up @@ -334,7 +335,6 @@ BITCOIN_CORE_H = \
wallet/fees.h \
wallet/ismine.h \
wallet/load.h \
wallet/psbtwallet.h \
wallet/rpcwallet.h \
wallet/salvage.h \
wallet/scriptpubkeyman.h \
Expand Down Expand Up @@ -498,7 +498,6 @@ libbitcoin_wallet_a_SOURCES = \
wallet/db.cpp \
wallet/fees.cpp \
wallet/load.cpp \
wallet/psbtwallet.cpp \
wallet/rpcdump.cpp \
wallet/rpcwallet.cpp \
wallet/scriptpubkeyman.cpp \
Expand Down Expand Up @@ -673,6 +672,7 @@ libbitcoin_common_a_SOURCES = \
netaddress.cpp \
netbase.cpp \
net_permissions.cpp \
outputtype.cpp \
policy/feerate.cpp \
policy/policy.cpp \
protocol.cpp \
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ BITCOIN_TESTS += \
wallet/test/wallet_crypto_tests.cpp \
wallet/test/coinselector_tests.cpp \
wallet/test/init_tests.cpp \
wallet/test/ismine_tests.cpp
wallet/test/ismine_tests.cpp \
wallet/test/scriptpubkeyman_tests.cpp

if USE_BDB
BITCOIN_TESTS += wallet/test/db_tests.cpp
Expand Down
6 changes: 4 additions & 2 deletions src/bench/coin_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ static void CoinSelection(benchmark::Bench& bench)
{
NodeContext node;
auto chain = interfaces::MakeChain(node);
const CWallet wallet(chain.get(), "", CreateDummyWalletDatabase());
CWallet wallet(chain.get(), "", CreateDummyWalletDatabase());
wallet.SetupLegacyScriptPubKeyMan();
std::vector<std::unique_ptr<CWalletTx>> wtxs;
LOCK(wallet.cs_wallet);

Expand Down Expand Up @@ -63,7 +64,7 @@ static void CoinSelection(benchmark::Bench& bench)
typedef std::set<CInputCoin> CoinSet;
static NodeContext testNode;
static auto testChain = interfaces::MakeChain(testNode);
static const CWallet testWallet(testChain.get(), "", CreateDummyWalletDatabase());
static CWallet testWallet(testChain.get(), "", CreateDummyWalletDatabase());
std::vector<std::unique_ptr<CWalletTx>> wtxn;

// Copied from src/wallet/test/coinselector_tests.cpp
Expand Down Expand Up @@ -92,6 +93,7 @@ static CAmount make_hard_case(int utxos, std::vector<OutputGroup>& utxo_pool)
static void BnBExhaustion(benchmark::Bench& bench)
{
// Setup
testWallet.SetupLegacyScriptPubKeyMan();
std::vector<OutputGroup> utxo_pool;
CoinSet selection;
CAmount value_ret = 0;
Expand Down
1 change: 1 addition & 0 deletions src/bench/wallet_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain(node);
CWallet wallet{chain.get(), "", CreateMockWalletDatabase()};
{
wallet.SetupLegacyScriptPubKeyMan();
bool first_run;
if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) assert(false);
}
Expand Down
47 changes: 31 additions & 16 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <masternode/sync.h>
#include <net_processing.h>
#include <netmessagemaker.h>
#include <script/sign.h>
#include <shutdown.h>
#include <util/irange.h>
#include <util/moneystr.h>
Expand Down Expand Up @@ -575,7 +574,7 @@ bool CCoinJoinClientSession::SignFinalTransaction(const CTxMemPool& mempool, con

// STEP 2: make sure our own inputs/outputs are present, otherwise refuse to sign

std::vector<CTxIn> sigs;
std::map<COutPoint, Coin> coins;

for (const auto &entry: vecEntries) {
// Check that the final transaction has all our outputs
Expand Down Expand Up @@ -618,32 +617,48 @@ bool CCoinJoinClientSession::SignFinalTransaction(const CTxMemPool& mempool, con
return false;
}

LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- Signing my input %i\n", __func__, nMyInputIndex);
// TODO we're using amount=0 here but we should use the correct amount. This works because Dash ignores the amount while signing/verifying (only used in Bitcoin/Segwit)
if (!SignSignature(*mixingWallet.GetSigningProvider(prevPubKey), prevPubKey, finalMutableTransaction, nMyInputIndex, 0, int(SIGHASH_ALL | SIGHASH_ANYONECANPAY))) { // changes scriptSig
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- Unable to sign my own transaction!\n", __func__);
// not sure what to do here, it will time out...?
}
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- found my input %i\n", __func__, nMyInputIndex);
// add a pair with an empty value
coins[finalMutableTransaction.vin.at(nMyInputIndex).prevout];
}
}

sigs.push_back(finalMutableTransaction.vin[nMyInputIndex]);
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- nMyInputIndex: %d, sigs.size(): %d, scriptSig=%s\n",
__func__, nMyInputIndex, (int) sigs.size(),ScriptToAsmStr(finalMutableTransaction.vin[nMyInputIndex].scriptSig));
// fill values for found outpoints
mixingWallet.chain().findCoins(coins);
std::map<int, std::string> signing_errors;
mixingWallet.SignTransaction(finalMutableTransaction, coins, SIGHASH_ALL | SIGHASH_ANYONECANPAY, signing_errors);

for (const auto& [input_index, error_string] : signing_errors) {
// NOTE: this is a partial signing so it's expected for SignTransaction to return
// "Input not found or already spent" errors for inputs that aren't ours
if (error_string != "Input not found or already spent") {
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- signing input %d failed: %s!\n", __func__, input_index, error_string);
UnlockCoins();
keyHolderStorage.ReturnAll();
SetNull();
return false;
}
}

if (sigs.empty()) {
std::vector<CTxIn> signed_inputs;
for (const auto& txin : finalMutableTransaction.vin) {
if (coins.find(txin.prevout) != coins.end()) {
signed_inputs.push_back(txin);
}
}

if (signed_inputs.empty()) {
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- can't sign anything!\n", __func__);
UnlockCoins();
keyHolderStorage.ReturnAll();
SetNull();

return false;
}

// push all of our signatures to the Masternode
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- pushing sigs to the masternode, finalMutableTransaction=%s", __func__, finalMutableTransaction.ToString()); /* Continued */
LogPrint(BCLog::COINJOIN, "CCoinJoinClientSession::%s -- pushing signed inputs to the masternode, finalMutableTransaction=%s", __func__, finalMutableTransaction.ToString()); /* Continued */
CNetMsgMaker msgMaker(peer.GetSendVersion());
connman.PushMessage(&peer, msgMaker.Make(NetMsgType::DSSIGNFINALTX, sigs));
connman.PushMessage(&peer, msgMaker.Make(NetMsgType::DSSIGNFINALTX, signed_inputs));
SetState(POOL_STATE_SIGNING);
nTimeLastSuccessfulStep = GetTime();

Expand Down Expand Up @@ -1541,7 +1556,7 @@ bool CCoinJoinClientSession::CreateCollateralTransaction(CMutableTransaction& tx
txCollateral.vout.emplace_back(0, CScript() << OP_RETURN);
}

if (!SignSignature(*mixingWallet.GetSigningProvider(txout.scriptPubKey), txout.scriptPubKey, txCollateral, 0, txout.nValue, SIGHASH_ALL)) {
if (!mixingWallet.SignTransaction(txCollateral)) {
strReason = "Unable to sign collateral transaction!";
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/coinjoin/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ CTransactionBuilderOutput::CTransactionBuilderOutput(CTransactionBuilder* pTxBui
{
assert(pTxBuilder);
CTxDestination txdest;
LOCK(pwalletIn->cs_wallet);
dest.GetReservedDestination(txdest, false);
script = ::GetScriptForDestination(txdest);
}
Expand Down
2 changes: 1 addition & 1 deletion src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void BaseIndex::ChainStateFlushed(const CBlockLocator& locator)
Commit();
}

bool BaseIndex::BlockUntilSyncedToCurrentChain()
bool BaseIndex::BlockUntilSyncedToCurrentChain() const
{
AssertLockNotHeld(cs_main);

Expand Down
2 changes: 1 addition & 1 deletion src/index/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class BaseIndex : public CValidationInterface
/// sync once and only needs to process blocks in the ValidationInterface
/// queue. If the index is catching up from far behind, this method does
/// not block and immediately returns false.
bool BlockUntilSyncedToCurrentChain();
bool BlockUntilSyncedToCurrentChain() const;

void Interrupt();

Expand Down
6 changes: 3 additions & 3 deletions src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class ChainImpl : public Chain
explicit ChainImpl(NodeContext& node) : m_node(node) {}
std::optional<int> getHeight() override
{
LOCK(cs_main);
LOCK(::cs_main);
int height = ::ChainActive().Height();
if (height >= 0) {
return height;
Expand All @@ -148,7 +148,7 @@ class ChainImpl : public Chain
}
std::optional<int> getBlockHeight(const uint256& hash) override
{
LOCK(cs_main);
LOCK(::cs_main);
CBlockIndex* block = LookupBlockIndex(hash);
if (block && ::ChainActive().Contains(block)) {
return block->nHeight;
Expand All @@ -157,7 +157,7 @@ class ChainImpl : public Chain
}
uint256 getBlockHash(int height) override
{
LOCK(cs_main);
LOCK(::cs_main);
CBlockIndex* block = ::ChainActive()[height];
assert(block != nullptr);
return block->GetBlockHash();
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Handler;
//! internal workings of the bitcoin node, and not being very convenient to use.
//! Chain methods should be cleaned up and simplified over time. Examples:
//!
//! * The initMessage() and showProgress() methods which the wallet uses to send
//! * The initMessages() and showProgress() methods which the wallet uses to send
//! notifications to the GUI should go away when GUI and wallet can directly
//! communicate with each other without going through the node
//! (https://github.com/bitcoin/bitcoin/pull/15288#discussion_r253321096).
Expand Down
20 changes: 7 additions & 13 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <wallet/fees.h>
#include <wallet/ismine.h>
#include <wallet/load.h>
#include <wallet/psbtwallet.h>
#include <wallet/rpcwallet.h>
#include <wallet/wallet.h>

Expand Down Expand Up @@ -192,19 +191,15 @@ class WalletImpl : public Wallet
}
bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override
{
const SigningProvider* provider = m_wallet->GetSigningProvider(script);
std::unique_ptr<SigningProvider> provider = m_wallet->GetSolvingProvider(script);
if (provider) {
return provider->GetPubKey(address, pub_key);
}
return false;
}
bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) override
SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) override
{
const SigningProvider* provider = m_wallet->GetSigningProvider(script);
if (provider) {
return provider->GetKey(address, key);
}
return false;
return m_wallet->SignMessage(message, pkhash, str_sig);
}
bool isSpendable(const CScript& script) override { return m_wallet->IsMine(script) & ISMINE_SPENDABLE; }
bool isSpendable(const CTxDestination& dest) override { return m_wallet->IsMine(dest) & ISMINE_SPENDABLE; }
Expand Down Expand Up @@ -254,7 +249,6 @@ class WalletImpl : public Wallet
}
return result;
}
//void learnRelatedScripts(const CPubKey& key, OutputType type) override { if (spk_man) m_wallet->GetLegacyScriptPubKeyMan()->LearnRelatedScripts(key, type); }
bool addDestData(const CTxDestination& dest, const std::string& key, const std::string& value) override
{
LOCK(m_wallet->cs_wallet);
Expand Down Expand Up @@ -317,7 +311,7 @@ class WalletImpl : public Wallet
WalletValueMap value_map,
WalletOrderForm order_form) override
{
LOCK2(m_wallet->cs_wallet, cs_main);
LOCK(m_wallet->cs_wallet);
ReserveDestination m_dest(m_wallet.get());
m_wallet->CommitTransaction(std::move(tx), std::move(value_map), std::move(order_form));
}
Expand Down Expand Up @@ -405,9 +399,9 @@ class WalletImpl : public Wallet
bool& complete,
int sighash_type = 1 /* SIGHASH_ALL */,
bool sign = true,
bool bip32derivs = false) override
bool bip32derivs = false) const override
{
return FillPSBT(m_wallet.get(), psbtx, complete, sighash_type, sign, bip32derivs);
return m_wallet->FillPSBT(psbtx, complete, sighash_type, sign, bip32derivs);
}
WalletBalances getBalances() override
{
Expand Down Expand Up @@ -537,7 +531,7 @@ class WalletImpl : public Wallet
}
unsigned int getConfirmTarget() override { return m_wallet->m_confirm_target; }
bool hdEnabled() override { return m_wallet->IsHDEnabled(); }
bool canGetAddresses() override { return m_wallet->CanGetAddresses(); }
bool canGetAddresses() const override { return m_wallet->CanGetAddresses(); }
bool IsWalletFlagSet(uint64_t flag) override { return m_wallet->IsWalletFlagSet(flag); }
CoinJoin::Client& coinJoin() override { return m_coinjoin; }
CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }
Expand Down
10 changes: 5 additions & 5 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <script/standard.h> // For CTxDestination
#include <support/allocators/secure.h> // For SecureString
#include <ui_interface.h> // For ChangeType
#include <util/system.h>
#include <util/message.h>

#include <functional>
#include <map>
Expand Down Expand Up @@ -117,8 +117,8 @@ class Wallet
//! Get public key.
virtual bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) = 0;

//! Get private key.
virtual bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) = 0;
//! Sign message
virtual SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) = 0;

//! Return whether wallet has private key.
virtual bool isSpendable(const CScript& script) = 0;
Expand Down Expand Up @@ -223,7 +223,7 @@ class Wallet
bool& complete,
int sighash_type = 1 /* SIGHASH_ALL */,
bool sign = true,
bool bip32derivs = false) = 0;
bool bip32derivs = false) const = 0;

//! Get balances.
virtual WalletBalances getBalances() = 0;
Expand Down Expand Up @@ -288,7 +288,7 @@ class Wallet
virtual bool hdEnabled() = 0;

// Return whether the wallet is blank.
virtual bool canGetAddresses() = 0;
virtual bool canGetAddresses() const = 0;

// check if a certain wallet flag is set.
virtual bool IsWalletFlagSet(uint64_t flag) = 0;
Expand Down
19 changes: 19 additions & 0 deletions src/outputtype.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <outputtype.h>

#include <script/signingprovider.h>
#include <script/standard.h>

#include <assert.h>

CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore, const CScript& script)
{
// Add script to keystore
keystore.AddCScript(script);
// Note that scripts over 520 bytes are not yet supported.
return ScriptHash(script);
}
19 changes: 19 additions & 0 deletions src/outputtype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2019 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef BITCOIN_OUTPUTTYPE_H
#define BITCOIN_OUTPUTTYPE_H

#include <script/signingprovider.h>
#include <script/standard.h>

/**
* Get a destination of the requested type (if possible) to the specified script.
* This function will automatically add the script (and any other
* necessary scripts) to the keystore.
*/
CTxDestination AddAndGetDestinationForScript(FillableSigningProvider& keystore, const CScript& script);

#endif // BITCOIN_OUTPUTTYPE_H
1 change: 0 additions & 1 deletion src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <ui_interface.h>
#include <wallet/coincontrol.h>
#include <wallet/fees.h>
#include <wallet/psbtwallet.h>
#include <wallet/wallet.h>

#include <QFontMetrics>
Expand Down
Loading