Page MenuHomePhabricator

D7874.diff
No OneTemporary

D7874.diff

diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2805,15 +2805,16 @@
}
static bool IsCurrentForAntiFeeSniping(interfaces::Chain &chain,
- interfaces::Chain::Lock &locked_chain) {
+ const BlockHash &block_hash) {
if (chain.isInitialBlockDownload()) {
return false;
}
// in seconds
constexpr int64_t MAX_ANTI_FEE_SNIPING_TIP_AGE = 8 * 60 * 60;
- if (locked_chain.getBlockTime(*locked_chain.getHeight()) <
- (GetTime() - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
+ int64_t block_time;
+ CHECK_NONFATAL(chain.findBlock(block_hash, FoundBlock().time(block_time)));
+ if (block_time < (GetTime() - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
return false;
}
return true;
@@ -2823,10 +2824,9 @@
* 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
*/
-static uint32_t
-GetLocktimeForNewTransaction(interfaces::Chain &chain,
- interfaces::Chain::Lock &locked_chain) {
- uint32_t const height = locked_chain.getHeight().value_or(-1);
+static uint32_t GetLocktimeForNewTransaction(interfaces::Chain &chain,
+ const BlockHash &block_hash,
+ int block_height) {
uint32_t locktime;
// Discourage fee sniping.
//
@@ -2848,8 +2848,8 @@
// 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
// nLockTime that preclude a fix later.
- if (IsCurrentForAntiFeeSniping(chain, locked_chain)) {
- locktime = height;
+ if (IsCurrentForAntiFeeSniping(chain, block_hash)) {
+ locktime = block_height;
// Secondly occasionally randomly pick a nLockTime even further back, so
// that transactions that are delayed after signing for whatever reason,
@@ -2865,7 +2865,6 @@
// constant.
locktime = 0;
}
- assert(locktime <= height);
assert(locktime < LOCKTIME_THRESHOLD);
return locktime;
}
@@ -2922,13 +2921,12 @@
CMutableTransaction txNew;
- txNew.nLockTime = GetLocktimeForNewTransaction(chain(), locked_chainIn);
-
{
std::set<CInputCoin> setCoins;
auto locked_chain = chain().lock();
LOCK(cs_wallet);
-
+ txNew.nLockTime = GetLocktimeForNewTransaction(
+ chain(), GetLastBlockHash(), GetLastBlockHeight());
std::vector<COutput> vAvailableCoins;
AvailableCoins(*locked_chain, vAvailableCoins, true, &coin_control);
// Parameters for coin selection, init with dummy

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 11:03 (12 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5182978
Default Alt Text
D7874.diff (2 KB)

Event Timeline