@@ -2620,13 +2620,15 @@ bool CWallet::FundTransaction(CMutableTransaction& tx, CAmount& nFeeRet, int& nC
2620
2620
return true ;
2621
2621
}
2622
2622
2623
- static bool IsCurrentForAntiFeeSniping (interfaces::Chain& chain, interfaces::Chain::Lock& locked_chain )
2623
+ static bool IsCurrentForAntiFeeSniping (interfaces::Chain& chain, const uint256& block_hash )
2624
2624
{
2625
2625
if (chain.isInitialBlockDownload ()) {
2626
2626
return false ;
2627
2627
}
2628
2628
constexpr int64_t MAX_ANTI_FEE_SNIPING_TIP_AGE = 8 * 60 * 60 ; // in seconds
2629
- if (locked_chain.getBlockTime (*locked_chain.getHeight ()) < (GetTime () - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
2629
+ int64_t block_time;
2630
+ CHECK_NONFATAL (chain.findBlock (block_hash, FoundBlock ().time (block_time)));
2631
+ if (block_time < (GetTime () - MAX_ANTI_FEE_SNIPING_TIP_AGE)) {
2630
2632
return false ;
2631
2633
}
2632
2634
return true ;
@@ -2636,9 +2638,8 @@ static bool IsCurrentForAntiFeeSniping(interfaces::Chain& chain, interfaces::Cha
2636
2638
* Return a height-based locktime for new transactions (uses the height of the
2637
2639
* current chain tip unless we are not synced with the current chain
2638
2640
*/
2639
- static uint32_t GetLocktimeForNewTransaction (interfaces::Chain& chain, interfaces::Chain::Lock& locked_chain )
2641
+ static uint32_t GetLocktimeForNewTransaction (interfaces::Chain& chain, const uint256& block_hash, int block_height )
2640
2642
{
2641
- uint32_t const height = locked_chain.getHeight ().get_value_or (-1 );
2642
2643
uint32_t locktime;
2643
2644
// Discourage fee sniping.
2644
2645
//
@@ -2660,8 +2661,8 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, interface
2660
2661
// enough, that fee sniping isn't a problem yet, but by implementing a fix
2661
2662
// now we ensure code won't be written that makes assumptions about
2662
2663
// nLockTime that preclude a fix later.
2663
- if (IsCurrentForAntiFeeSniping (chain, locked_chain )) {
2664
- locktime = height ;
2664
+ if (IsCurrentForAntiFeeSniping (chain, block_hash )) {
2665
+ locktime = block_height ;
2665
2666
2666
2667
// Secondly occasionally randomly pick a nLockTime even further back, so
2667
2668
// that transactions that are delayed after signing for whatever reason,
@@ -2675,7 +2676,6 @@ static uint32_t GetLocktimeForNewTransaction(interfaces::Chain& chain, interface
2675
2676
// unique "nLockTime fingerprint", set nLockTime to a constant.
2676
2677
locktime = 0 ;
2677
2678
}
2678
- assert (locktime <= height);
2679
2679
assert (locktime < LOCKTIME_THRESHOLD);
2680
2680
return locktime;
2681
2681
}
@@ -2735,16 +2735,14 @@ bool CWallet::CreateTransaction(interfaces::Chain::Lock& locked_chain, const std
2735
2735
}
2736
2736
2737
2737
CMutableTransaction txNew;
2738
-
2739
- txNew.nLockTime = GetLocktimeForNewTransaction (chain (), locked_chain);
2740
-
2741
2738
FeeCalculation feeCalc;
2742
2739
CAmount nFeeNeeded;
2743
2740
int nBytes;
2744
2741
{
2745
2742
std::set<CInputCoin> setCoins;
2746
2743
auto locked_chain = chain ().lock ();
2747
2744
LOCK (cs_wallet);
2745
+ txNew.nLockTime = GetLocktimeForNewTransaction (chain (), GetLastBlockHash (), GetLastBlockHeight ());
2748
2746
{
2749
2747
std::vector<COutput> vAvailableCoins;
2750
2748
AvailableCoins (*locked_chain, vAvailableCoins, true , &coin_control, 1 , MAX_MONEY, MAX_MONEY, 0 );
0 commit comments