Remove remaining wallet accesses to node globals
This commit is contained in:
parent
b1b2b23892
commit
d358466de1
12 changed files with 63 additions and 49 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <protocol.h>
|
#include <protocol.h>
|
||||||
#include <rpc/protocol.h>
|
#include <rpc/protocol.h>
|
||||||
#include <rpc/server.h>
|
#include <rpc/server.h>
|
||||||
|
#include <shutdown.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <threadsafety.h>
|
#include <threadsafety.h>
|
||||||
#include <timedata.h>
|
#include <timedata.h>
|
||||||
|
@ -340,15 +341,23 @@ public:
|
||||||
{
|
{
|
||||||
return ::mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
|
return ::mempool.GetMinFee(gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000);
|
||||||
}
|
}
|
||||||
|
CFeeRate relayMinFee() override { return ::minRelayTxFee; }
|
||||||
|
CFeeRate relayIncrementalFee() override { return ::incrementalRelayFee; }
|
||||||
|
CFeeRate relayDustFee() override { return ::dustRelayFee; }
|
||||||
CAmount maxTxFee() override { return ::maxTxFee; }
|
CAmount maxTxFee() override { return ::maxTxFee; }
|
||||||
bool getPruneMode() override { return ::fPruneMode; }
|
bool getPruneMode() override { return ::fPruneMode; }
|
||||||
bool p2pEnabled() override { return g_connman != nullptr; }
|
bool p2pEnabled() override { return g_connman != nullptr; }
|
||||||
bool isInitialBlockDownload() override { return IsInitialBlockDownload(); }
|
bool isInitialBlockDownload() override { return IsInitialBlockDownload(); }
|
||||||
|
bool shutdownRequested() override { return ShutdownRequested(); }
|
||||||
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
|
int64_t getAdjustedTime() override { return GetAdjustedTime(); }
|
||||||
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
|
void initMessage(const std::string& message) override { ::uiInterface.InitMessage(message); }
|
||||||
void initWarning(const std::string& message) override { InitWarning(message); }
|
void initWarning(const std::string& message) override { InitWarning(message); }
|
||||||
void initError(const std::string& message) override { InitError(message); }
|
void initError(const std::string& message) override { InitError(message); }
|
||||||
void loadWallet(std::unique_ptr<Wallet> wallet) override { ::uiInterface.LoadWallet(wallet); }
|
void loadWallet(std::unique_ptr<Wallet> wallet) override { ::uiInterface.LoadWallet(wallet); }
|
||||||
|
void showProgress(const std::string& title, int progress, bool resume_possible) override
|
||||||
|
{
|
||||||
|
::uiInterface.ShowProgress(title, progress, resume_possible);
|
||||||
|
}
|
||||||
std::unique_ptr<Handler> handleNotifications(Notifications& notifications) override
|
std::unique_ptr<Handler> handleNotifications(Notifications& notifications) override
|
||||||
{
|
{
|
||||||
return MakeUnique<NotificationsHandlerImpl>(*this, notifications);
|
return MakeUnique<NotificationsHandlerImpl>(*this, notifications);
|
||||||
|
|
|
@ -202,6 +202,15 @@ public:
|
||||||
//! Mempool minimum fee.
|
//! Mempool minimum fee.
|
||||||
virtual CFeeRate mempoolMinFee() = 0;
|
virtual CFeeRate mempoolMinFee() = 0;
|
||||||
|
|
||||||
|
//! Relay current minimum fee (from -minrelaytxfee and -incrementalrelayfee settings).
|
||||||
|
virtual CFeeRate relayMinFee() = 0;
|
||||||
|
|
||||||
|
//! Relay incremental fee setting (-incrementalrelayfee), reflecting cost of relay.
|
||||||
|
virtual CFeeRate relayIncrementalFee() = 0;
|
||||||
|
|
||||||
|
//! Relay dust fee setting (-dustrelayfee), reflecting lowest rate it's economical to spend.
|
||||||
|
virtual CFeeRate relayDustFee() = 0;
|
||||||
|
|
||||||
//! Node max tx fee setting (-maxtxfee).
|
//! Node max tx fee setting (-maxtxfee).
|
||||||
//! This could be replaced by a per-wallet max fee, as proposed at
|
//! This could be replaced by a per-wallet max fee, as proposed at
|
||||||
//! https://github.com/bitcoin/bitcoin/issues/15355
|
//! https://github.com/bitcoin/bitcoin/issues/15355
|
||||||
|
@ -214,9 +223,12 @@ public:
|
||||||
//! Check if p2p enabled.
|
//! Check if p2p enabled.
|
||||||
virtual bool p2pEnabled() = 0;
|
virtual bool p2pEnabled() = 0;
|
||||||
|
|
||||||
// Check if in IBD.
|
//! Check if in IBD.
|
||||||
virtual bool isInitialBlockDownload() = 0;
|
virtual bool isInitialBlockDownload() = 0;
|
||||||
|
|
||||||
|
//! Check if shutdown requested.
|
||||||
|
virtual bool shutdownRequested() = 0;
|
||||||
|
|
||||||
//! Get adjusted time.
|
//! Get adjusted time.
|
||||||
virtual int64_t getAdjustedTime() = 0;
|
virtual int64_t getAdjustedTime() = 0;
|
||||||
|
|
||||||
|
@ -232,6 +244,9 @@ public:
|
||||||
//! Send wallet load notification to the GUI.
|
//! Send wallet load notification to the GUI.
|
||||||
virtual void loadWallet(std::unique_ptr<Wallet> wallet) = 0;
|
virtual void loadWallet(std::unique_ptr<Wallet> wallet) = 0;
|
||||||
|
|
||||||
|
//! Send progress indicator.
|
||||||
|
virtual void showProgress(const std::string& title, int progress, bool resume_possible) = 0;
|
||||||
|
|
||||||
//! Chain notifications.
|
//! Chain notifications.
|
||||||
class Notifications
|
class Notifications
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,8 +47,6 @@ public:
|
||||||
|
|
||||||
const CTransaction& get() override { return *m_tx; }
|
const CTransaction& get() override { return *m_tx; }
|
||||||
|
|
||||||
int64_t getVirtualSize() override { return GetVirtualTransactionSize(*m_tx); }
|
|
||||||
|
|
||||||
bool commit(WalletValueMap value_map,
|
bool commit(WalletValueMap value_map,
|
||||||
WalletOrderForm order_form,
|
WalletOrderForm order_form,
|
||||||
std::string& reject_reason) override
|
std::string& reject_reason) override
|
||||||
|
@ -99,12 +97,8 @@ WalletTx MakeWalletTx(interfaces::Chain::Lock& locked_chain, CWallet& wallet, co
|
||||||
//! Construct wallet tx status struct.
|
//! Construct wallet tx status struct.
|
||||||
WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
|
WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
|
||||||
{
|
{
|
||||||
LockAnnotation lock(::cs_main); // Temporary, for mapBlockIndex below. Removed in upcoming commit.
|
|
||||||
|
|
||||||
WalletTxStatus result;
|
WalletTxStatus result;
|
||||||
auto mi = ::mapBlockIndex.find(wtx.hashBlock);
|
result.block_height = locked_chain.getBlockHeight(wtx.hashBlock).get_value_or(std::numeric_limits<int>::max());
|
||||||
CBlockIndex* block = mi != ::mapBlockIndex.end() ? mi->second : nullptr;
|
|
||||||
result.block_height = (block ? block->nHeight : std::numeric_limits<int>::max());
|
|
||||||
result.blocks_to_maturity = wtx.GetBlocksToMaturity(locked_chain);
|
result.blocks_to_maturity = wtx.GetBlocksToMaturity(locked_chain);
|
||||||
result.depth_in_main_chain = wtx.GetDepthInMainChain(locked_chain);
|
result.depth_in_main_chain = wtx.GetDepthInMainChain(locked_chain);
|
||||||
result.time_received = wtx.nTimeReceived;
|
result.time_received = wtx.nTimeReceived;
|
||||||
|
|
|
@ -292,9 +292,6 @@ public:
|
||||||
//! Get transaction data.
|
//! Get transaction data.
|
||||||
virtual const CTransaction& get() = 0;
|
virtual const CTransaction& get() = 0;
|
||||||
|
|
||||||
//! Get virtual transaction size.
|
|
||||||
virtual int64_t getVirtualSize() = 0;
|
|
||||||
|
|
||||||
//! Send pending transaction and commit to wallet.
|
//! Send pending transaction and commit to wallet.
|
||||||
virtual bool commit(WalletValueMap value_map,
|
virtual bool commit(WalletValueMap value_map,
|
||||||
WalletOrderForm order_form,
|
WalletOrderForm order_form,
|
||||||
|
|
|
@ -29,7 +29,7 @@ std::unique_ptr<interfaces::PendingWalletTx>& WalletModelTransaction::getWtx()
|
||||||
|
|
||||||
unsigned int WalletModelTransaction::getTransactionSize()
|
unsigned int WalletModelTransaction::getTransactionSize()
|
||||||
{
|
{
|
||||||
return wtx ? wtx->getVirtualSize() : 0;
|
return wtx ? GetVirtualTransactionSize(wtx->get()) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CAmount WalletModelTransaction::getTransactionFee() const
|
CAmount WalletModelTransaction::getTransactionFee() const
|
||||||
|
|
|
@ -123,16 +123,17 @@ Result CreateTransaction(const CWallet* wallet, const uint256& txid, const CCoin
|
||||||
// The wallet uses a conservative WALLET_INCREMENTAL_RELAY_FEE value to
|
// The wallet uses a conservative WALLET_INCREMENTAL_RELAY_FEE value to
|
||||||
// future proof against changes to network wide policy for incremental relay
|
// future proof against changes to network wide policy for incremental relay
|
||||||
// fee that our node may not be aware of.
|
// fee that our node may not be aware of.
|
||||||
|
CFeeRate nodeIncrementalRelayFee = wallet->chain().relayIncrementalFee();
|
||||||
CFeeRate walletIncrementalRelayFee = CFeeRate(WALLET_INCREMENTAL_RELAY_FEE);
|
CFeeRate walletIncrementalRelayFee = CFeeRate(WALLET_INCREMENTAL_RELAY_FEE);
|
||||||
if (::incrementalRelayFee > walletIncrementalRelayFee) {
|
if (nodeIncrementalRelayFee > walletIncrementalRelayFee) {
|
||||||
walletIncrementalRelayFee = ::incrementalRelayFee;
|
walletIncrementalRelayFee = nodeIncrementalRelayFee;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (total_fee > 0) {
|
if (total_fee > 0) {
|
||||||
CAmount minTotalFee = nOldFeeRate.GetFee(maxNewTxSize) + ::incrementalRelayFee.GetFee(maxNewTxSize);
|
CAmount minTotalFee = nOldFeeRate.GetFee(maxNewTxSize) + nodeIncrementalRelayFee.GetFee(maxNewTxSize);
|
||||||
if (total_fee < minTotalFee) {
|
if (total_fee < minTotalFee) {
|
||||||
errors.push_back(strprintf("Insufficient totalFee, must be at least %s (oldFee %s + incrementalFee %s)",
|
errors.push_back(strprintf("Insufficient totalFee, must be at least %s (oldFee %s + incrementalFee %s)",
|
||||||
FormatMoney(minTotalFee), FormatMoney(nOldFeeRate.GetFee(maxNewTxSize)), FormatMoney(::incrementalRelayFee.GetFee(maxNewTxSize))));
|
FormatMoney(minTotalFee), FormatMoney(nOldFeeRate.GetFee(maxNewTxSize)), FormatMoney(nodeIncrementalRelayFee.GetFee(maxNewTxSize))));
|
||||||
return Result::INVALID_PARAMETER;
|
return Result::INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
CAmount requiredFee = GetRequiredFee(*wallet, maxNewTxSize);
|
CAmount requiredFee = GetRequiredFee(*wallet, maxNewTxSize);
|
||||||
|
@ -159,9 +160,10 @@ Result CreateTransaction(const CWallet* wallet, const uint256& txid, const CCoin
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that in all cases the new fee doesn't violate maxTxFee
|
// Check that in all cases the new fee doesn't violate maxTxFee
|
||||||
if (new_fee > maxTxFee) {
|
const CAmount max_tx_fee = wallet->chain().maxTxFee();
|
||||||
|
if (new_fee > max_tx_fee) {
|
||||||
errors.push_back(strprintf("Specified or calculated fee %s is too high (cannot be higher than maxTxFee %s)",
|
errors.push_back(strprintf("Specified or calculated fee %s is too high (cannot be higher than maxTxFee %s)",
|
||||||
FormatMoney(new_fee), FormatMoney(maxTxFee)));
|
FormatMoney(new_fee), FormatMoney(max_tx_fee)));
|
||||||
return Result::WALLET_ERROR;
|
return Result::WALLET_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,9 @@ CAmount GetMinimumFee(const CWallet& wallet, unsigned int nTxBytes, const CCoinC
|
||||||
{
|
{
|
||||||
CAmount fee_needed = GetMinimumFeeRate(wallet, coin_control, feeCalc).GetFee(nTxBytes);
|
CAmount fee_needed = GetMinimumFeeRate(wallet, coin_control, feeCalc).GetFee(nTxBytes);
|
||||||
// Always obey the maximum
|
// Always obey the maximum
|
||||||
if (fee_needed > maxTxFee) {
|
const CAmount max_tx_fee = wallet.chain().maxTxFee();
|
||||||
fee_needed = maxTxFee;
|
if (fee_needed > max_tx_fee) {
|
||||||
|
fee_needed = max_tx_fee;
|
||||||
if (feeCalc) feeCalc->reason = FeeReason::MAXTXFEE;
|
if (feeCalc) feeCalc->reason = FeeReason::MAXTXFEE;
|
||||||
}
|
}
|
||||||
return fee_needed;
|
return fee_needed;
|
||||||
|
@ -31,7 +32,7 @@ CAmount GetMinimumFee(const CWallet& wallet, unsigned int nTxBytes, const CCoinC
|
||||||
|
|
||||||
CFeeRate GetRequiredFeeRate(const CWallet& wallet)
|
CFeeRate GetRequiredFeeRate(const CWallet& wallet)
|
||||||
{
|
{
|
||||||
return std::max(wallet.m_min_fee, ::minRelayTxFee);
|
return std::max(wallet.m_min_fee, wallet.chain().relayMinFee());
|
||||||
}
|
}
|
||||||
|
|
||||||
CFeeRate GetMinimumFeeRate(const CWallet& wallet, const CCoinControl& coin_control, FeeCalculation* feeCalc)
|
CFeeRate GetMinimumFeeRate(const CWallet& wallet, const CCoinControl& coin_control, FeeCalculation* feeCalc)
|
||||||
|
@ -96,6 +97,6 @@ CFeeRate GetDiscardRate(const CWallet& wallet)
|
||||||
// Don't let discard_rate be greater than longest possible fee estimate if we get a valid fee estimate
|
// Don't let discard_rate be greater than longest possible fee estimate if we get a valid fee estimate
|
||||||
discard_rate = (discard_rate == CFeeRate(0)) ? wallet.m_discard_rate : std::min(discard_rate, wallet.m_discard_rate);
|
discard_rate = (discard_rate == CFeeRate(0)) ? wallet.m_discard_rate : std::min(discard_rate, wallet.m_discard_rate);
|
||||||
// Discard rate must be at least dustRelayFee
|
// Discard rate must be at least dustRelayFee
|
||||||
discard_rate = std::max(discard_rate, ::dustRelayFee);
|
discard_rate = std::max(discard_rate, wallet.chain().relayDustFee());
|
||||||
return discard_rate;
|
return discard_rate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ bool VerifyWallets(interfaces::Chain& chain, const std::vector<std::string>& wal
|
||||||
|
|
||||||
LogPrintf("Using wallet directory %s\n", GetWalletDir().string());
|
LogPrintf("Using wallet directory %s\n", GetWalletDir().string());
|
||||||
|
|
||||||
uiInterface.InitMessage(_("Verifying wallet(s)..."));
|
chain.initMessage(_("Verifying wallet(s)..."));
|
||||||
|
|
||||||
// Parameter interaction code should have thrown an error if -salvagewallet
|
// Parameter interaction code should have thrown an error if -salvagewallet
|
||||||
// was enabled with more than wallet file, so the wallet_files size check
|
// was enabled with more than wallet file, so the wallet_files size check
|
||||||
|
|
|
@ -595,11 +595,11 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||||
|
|
||||||
// Use uiInterface.ShowProgress instead of pwallet.ShowProgress because pwallet.ShowProgress has a cancel button tied to AbortRescan which
|
// Use uiInterface.ShowProgress instead of pwallet.ShowProgress because pwallet.ShowProgress has a cancel button tied to AbortRescan which
|
||||||
// we don't want for this progress bar showing the import progress. uiInterface.ShowProgress does not have a cancel button.
|
// we don't want for this progress bar showing the import progress. uiInterface.ShowProgress does not have a cancel button.
|
||||||
uiInterface.ShowProgress(strprintf("%s " + _("Importing..."), pwallet->GetDisplayName()), 0, false); // show progress dialog in GUI
|
pwallet->chain().showProgress(strprintf("%s " + _("Importing..."), pwallet->GetDisplayName()), 0, false); // show progress dialog in GUI
|
||||||
std::vector<std::tuple<CKey, int64_t, bool, std::string>> keys;
|
std::vector<std::tuple<CKey, int64_t, bool, std::string>> keys;
|
||||||
std::vector<std::pair<CScript, int64_t>> scripts;
|
std::vector<std::pair<CScript, int64_t>> scripts;
|
||||||
while (file.good()) {
|
while (file.good()) {
|
||||||
uiInterface.ShowProgress("", std::max(1, std::min(50, (int)(((double)file.tellg() / (double)nFilesize) * 100))), false);
|
pwallet->chain().showProgress("", std::max(1, std::min(50, (int)(((double)file.tellg() / (double)nFilesize) * 100))), false);
|
||||||
std::string line;
|
std::string line;
|
||||||
std::getline(file, line);
|
std::getline(file, line);
|
||||||
if (line.empty() || line[0] == '#')
|
if (line.empty() || line[0] == '#')
|
||||||
|
@ -637,13 +637,13 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||||
file.close();
|
file.close();
|
||||||
// We now know whether we are importing private keys, so we can error if private keys are disabled
|
// We now know whether we are importing private keys, so we can error if private keys are disabled
|
||||||
if (keys.size() > 0 && pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
if (keys.size() > 0 && pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
|
||||||
uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI
|
pwallet->chain().showProgress("", 100, false); // hide progress dialog in GUI
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "Importing wallets is disabled when private keys are disabled");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Importing wallets is disabled when private keys are disabled");
|
||||||
}
|
}
|
||||||
double total = (double)(keys.size() + scripts.size());
|
double total = (double)(keys.size() + scripts.size());
|
||||||
double progress = 0;
|
double progress = 0;
|
||||||
for (const auto& key_tuple : keys) {
|
for (const auto& key_tuple : keys) {
|
||||||
uiInterface.ShowProgress("", std::max(50, std::min(75, (int)((progress / total) * 100) + 50)), false);
|
pwallet->chain().showProgress("", std::max(50, std::min(75, (int)((progress / total) * 100) + 50)), false);
|
||||||
const CKey& key = std::get<0>(key_tuple);
|
const CKey& key = std::get<0>(key_tuple);
|
||||||
int64_t time = std::get<1>(key_tuple);
|
int64_t time = std::get<1>(key_tuple);
|
||||||
bool has_label = std::get<2>(key_tuple);
|
bool has_label = std::get<2>(key_tuple);
|
||||||
|
@ -668,7 +668,7 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||||
progress++;
|
progress++;
|
||||||
}
|
}
|
||||||
for (const auto& script_pair : scripts) {
|
for (const auto& script_pair : scripts) {
|
||||||
uiInterface.ShowProgress("", std::max(50, std::min(75, (int)((progress / total) * 100) + 50)), false);
|
pwallet->chain().showProgress("", std::max(50, std::min(75, (int)((progress / total) * 100) + 50)), false);
|
||||||
const CScript& script = script_pair.first;
|
const CScript& script = script_pair.first;
|
||||||
int64_t time = script_pair.second;
|
int64_t time = script_pair.second;
|
||||||
CScriptID id(script);
|
CScriptID id(script);
|
||||||
|
@ -687,10 +687,10 @@ UniValue importwallet(const JSONRPCRequest& request)
|
||||||
}
|
}
|
||||||
progress++;
|
progress++;
|
||||||
}
|
}
|
||||||
uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI
|
pwallet->chain().showProgress("", 100, false); // hide progress dialog in GUI
|
||||||
pwallet->UpdateTimeFirstKey(nTimeBegin);
|
pwallet->UpdateTimeFirstKey(nTimeBegin);
|
||||||
}
|
}
|
||||||
uiInterface.ShowProgress("", 100, false); // hide progress dialog in GUI
|
pwallet->chain().showProgress("", 100, false); // hide progress dialog in GUI
|
||||||
RescanWallet(*pwallet, reserver, nTimeBegin, false /* update */);
|
RescanWallet(*pwallet, reserver, nTimeBegin, false /* update */);
|
||||||
pwallet->MarkDirty();
|
pwallet->MarkDirty();
|
||||||
|
|
||||||
|
|
|
@ -2367,8 +2367,8 @@ static UniValue settxfee(const JSONRPCRequest& request)
|
||||||
CFeeRate tx_fee_rate(nAmount, 1000);
|
CFeeRate tx_fee_rate(nAmount, 1000);
|
||||||
if (tx_fee_rate == 0) {
|
if (tx_fee_rate == 0) {
|
||||||
// automatic selection
|
// automatic selection
|
||||||
} else if (tx_fee_rate < ::minRelayTxFee) {
|
} else if (tx_fee_rate < pwallet->chain().relayMinFee()) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than min relay tx fee (%s)", ::minRelayTxFee.ToString()));
|
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than min relay tx fee (%s)", pwallet->chain().relayMinFee().ToString()));
|
||||||
} else if (tx_fee_rate < pwallet->m_min_fee) {
|
} else if (tx_fee_rate < pwallet->m_min_fee) {
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than wallet min fee (%s)", pwallet->m_min_fee.ToString()));
|
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("txfee cannot be less than wallet min fee (%s)", pwallet->m_min_fee.ToString()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1791,7 +1791,7 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
|
||||||
progress_end = chain().guessVerificationProgress(stop_block.IsNull() ? tip_hash : stop_block);
|
progress_end = chain().guessVerificationProgress(stop_block.IsNull() ? tip_hash : stop_block);
|
||||||
}
|
}
|
||||||
double progress_current = progress_begin;
|
double progress_current = progress_begin;
|
||||||
while (block_height && !fAbortRescan && !ShutdownRequested()) {
|
while (block_height && !fAbortRescan && !chain().shutdownRequested()) {
|
||||||
if (*block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
|
if (*block_height % 100 == 0 && progress_end - progress_begin > 0.0) {
|
||||||
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), std::max(1, std::min(99, (int)((progress_current - progress_begin) / (progress_end - progress_begin) * 100))));
|
ShowProgress(strprintf("%s " + _("Rescanning..."), GetDisplayName()), std::max(1, std::min(99, (int)((progress_current - progress_begin) / (progress_end - progress_begin) * 100))));
|
||||||
}
|
}
|
||||||
|
@ -1853,7 +1853,7 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
|
||||||
if (block_height && fAbortRescan) {
|
if (block_height && fAbortRescan) {
|
||||||
WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", *block_height, progress_current);
|
WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", *block_height, progress_current);
|
||||||
result.status = ScanResult::USER_ABORT;
|
result.status = ScanResult::USER_ABORT;
|
||||||
} else if (block_height && ShutdownRequested()) {
|
} else if (block_height && chain().shutdownRequested()) {
|
||||||
WalletLogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", *block_height, progress_current);
|
WalletLogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", *block_height, progress_current);
|
||||||
result.status = ScanResult::USER_ABORT;
|
result.status = ScanResult::USER_ABORT;
|
||||||
}
|
}
|
||||||
|
@ -2310,7 +2310,6 @@ CAmount CWallet::GetAvailableBalance(const CCoinControl* coinControl) const
|
||||||
|
|
||||||
void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<COutput> &vCoins, bool fOnlySafe, const CCoinControl *coinControl, const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount, const int nMinDepth, const int nMaxDepth) const
|
void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<COutput> &vCoins, bool fOnlySafe, const CCoinControl *coinControl, const CAmount &nMinimumAmount, const CAmount &nMaximumAmount, const CAmount &nMinimumSumAmount, const uint64_t nMaximumCount, const int nMinDepth, const int nMaxDepth) const
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_main);
|
|
||||||
AssertLockHeld(cs_wallet);
|
AssertLockHeld(cs_wallet);
|
||||||
|
|
||||||
vCoins.clear();
|
vCoins.clear();
|
||||||
|
@ -2420,7 +2419,6 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
|
||||||
|
|
||||||
std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins(interfaces::Chain::Lock& locked_chain) const
|
std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins(interfaces::Chain::Lock& locked_chain) const
|
||||||
{
|
{
|
||||||
AssertLockHeld(cs_main);
|
|
||||||
AssertLockHeld(cs_wallet);
|
AssertLockHeld(cs_wallet);
|
||||||
|
|
||||||
std::map<CTxDestination, std::vector<COutput>> result;
|
std::map<CTxDestination, std::vector<COutput>> result;
|
||||||
|
@ -2692,13 +2690,13 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsCurrentForAntiFeeSniping(interfaces::Chain::Lock& locked_chain)
|
static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, interfaces::Chain::Lock& locked_chain)
|
||||||
{
|
{
|
||||||
if (IsInitialBlockDownload()) {
|
if (chain.isInitialBlockDownload()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
constexpr int64_t MAX_ANTI_FEE_SNIPING_TIP_AGE = 8 * 60 * 60; // in seconds
|
constexpr int64_t MAX_ANTI_FEE_SNIPING_TIP_AGE = 8 * 60 * 60; // in seconds
|
||||||
if (chainActive.Tip()->GetBlockTime() < (GetTime() - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
|
if (locked_chain.getBlockTime(*locked_chain.getHeight()) < (GetTime() - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -2708,7 +2706,7 @@ static bool IsCurrentForAntiFeeSniping(interfaces::Chain::Lock& locked_chain)
|
||||||
* Return a height-based locktime for new transactions (uses the height of the
|
* Return a height-based locktime for new transactions (uses the height of the
|
||||||
* current chain tip unless we are not synced with the current chain
|
* current chain tip unless we are not synced with the current chain
|
||||||
*/
|
*/
|
||||||
static uint32_t GetLocktimeForNewTransaction(interfaces::Chain::Lock& locked_chain)
|
static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, interfaces::Chain::Lock& locked_chain)
|
||||||
{
|
{
|
||||||
uint32_t const height = locked_chain.getHeight().get_value_or(-1);
|
uint32_t const height = locked_chain.getHeight().get_value_or(-1);
|
||||||
uint32_t locktime;
|
uint32_t locktime;
|
||||||
|
@ -2732,7 +2730,7 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain::Lock& locked_cha
|
||||||
// enough, that fee sniping isn't a problem yet, but by implementing a fix
|
// enough, that fee sniping isn't a problem yet, but by implementing a fix
|
||||||
// now we ensure code won't be written that makes assumptions about
|
// now we ensure code won't be written that makes assumptions about
|
||||||
// nLockTime that preclude a fix later.
|
// nLockTime that preclude a fix later.
|
||||||
if (IsCurrentForAntiFeeSniping(locked_chain)) {
|
if (IsCurrentForAntiFeeSniping(chain, locked_chain)) {
|
||||||
locktime = height;
|
locktime = height;
|
||||||
|
|
||||||
// Secondly occasionally randomly pick a nLockTime even further back, so
|
// Secondly occasionally randomly pick a nLockTime even further back, so
|
||||||
|
@ -2806,7 +2804,7 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
|
||||||
|
|
||||||
CMutableTransaction txNew;
|
CMutableTransaction txNew;
|
||||||
|
|
||||||
txNew.nLockTime = GetLocktimeForNewTransaction(locked_chain);
|
txNew.nLockTime = GetLocktimeForNewTransaction(chain(), locked_chain);
|
||||||
|
|
||||||
FeeCalculation feeCalc;
|
FeeCalculation feeCalc;
|
||||||
CAmount nFeeNeeded;
|
CAmount nFeeNeeded;
|
||||||
|
@ -2902,7 +2900,7 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
|
||||||
// Include the fee cost for outputs. Note this is only used for BnB right now
|
// Include the fee cost for outputs. Note this is only used for BnB right now
|
||||||
coin_selection_params.tx_noinputs_size += ::GetSerializeSize(txout, PROTOCOL_VERSION);
|
coin_selection_params.tx_noinputs_size += ::GetSerializeSize(txout, PROTOCOL_VERSION);
|
||||||
|
|
||||||
if (IsDust(txout, ::dustRelayFee))
|
if (IsDust(txout, chain().relayDustFee()))
|
||||||
{
|
{
|
||||||
if (recipient.fSubtractFeeFromAmount && nFeeRet > 0)
|
if (recipient.fSubtractFeeFromAmount && nFeeRet > 0)
|
||||||
{
|
{
|
||||||
|
@ -3003,7 +3001,7 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
|
||||||
|
|
||||||
// If we made it here and we aren't even able to meet the relay fee on the next pass, give up
|
// If we made it here and we aren't even able to meet the relay fee on the next pass, give up
|
||||||
// because we must be at the maximum allowed fee.
|
// because we must be at the maximum allowed fee.
|
||||||
if (nFeeNeeded < ::minRelayTxFee.GetFee(nBytes))
|
if (nFeeNeeded < chain().relayMinFee().GetFee(nBytes))
|
||||||
{
|
{
|
||||||
strFailReason = _("Transaction too large for fee policy");
|
strFailReason = _("Transaction too large for fee policy");
|
||||||
return false;
|
return false;
|
||||||
|
@ -4281,9 +4279,9 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
|
||||||
_("This is the transaction fee you will pay if you send a transaction."));
|
_("This is the transaction fee you will pay if you send a transaction."));
|
||||||
}
|
}
|
||||||
walletInstance->m_pay_tx_fee = CFeeRate(nFeePerK, 1000);
|
walletInstance->m_pay_tx_fee = CFeeRate(nFeePerK, 1000);
|
||||||
if (walletInstance->m_pay_tx_fee < ::minRelayTxFee) {
|
if (walletInstance->m_pay_tx_fee < chain.relayMinFee()) {
|
||||||
chain.initError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
|
chain.initError(strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
|
||||||
gArgs.GetArg("-paytxfee", ""), ::minRelayTxFee.ToString()));
|
gArgs.GetArg("-paytxfee", ""), chain.relayMinFee().ToString()));
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4446,8 +4444,6 @@ int CMerkleTx::GetDepthInMainChain(interfaces::Chain::Lock& locked_chain) const
|
||||||
if (hashUnset())
|
if (hashUnset())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
AssertLockHeld(cs_main);
|
|
||||||
|
|
||||||
return locked_chain.getBlockDepth(hashBlock) * (nIndex == -1 ? -1 : 1);
|
return locked_chain.getBlockDepth(hashBlock) * (nIndex == -1 ? -1 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -506,7 +506,7 @@ public:
|
||||||
CAmount GetCredit(interfaces::Chain::Lock& locked_chain, const isminefilter& filter) const;
|
CAmount GetCredit(interfaces::Chain::Lock& locked_chain, const isminefilter& filter) const;
|
||||||
CAmount GetImmatureCredit(interfaces::Chain::Lock& locked_chain, bool fUseCache=true) const;
|
CAmount GetImmatureCredit(interfaces::Chain::Lock& locked_chain, bool fUseCache=true) const;
|
||||||
// TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
|
// TODO: Remove "NO_THREAD_SAFETY_ANALYSIS" and replace it with the correct
|
||||||
// annotation "EXCLUSIVE_LOCKS_REQUIRED(cs_main, pwallet->cs_wallet)". The
|
// annotation "EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)". The
|
||||||
// annotation "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid
|
// annotation "NO_THREAD_SAFETY_ANALYSIS" was temporarily added to avoid
|
||||||
// having to resolve the issue of member access into incomplete type CWallet.
|
// having to resolve the issue of member access into incomplete type CWallet.
|
||||||
CAmount GetAvailableCredit(interfaces::Chain::Lock& locked_chain, bool fUseCache=true, const isminefilter& filter=ISMINE_SPENDABLE) const NO_THREAD_SAFETY_ANALYSIS;
|
CAmount GetAvailableCredit(interfaces::Chain::Lock& locked_chain, bool fUseCache=true, const isminefilter& filter=ISMINE_SPENDABLE) const NO_THREAD_SAFETY_ANALYSIS;
|
||||||
|
|
Loading…
Reference in a new issue