mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-02 10:15:20 +00:00
config: make sure fee_per_kb() returns Optional[int]
electrs sends fee histogram with float feerates
This commit is contained in:
parent
ef84716e8b
commit
547b231b80
1 changed files with 9 additions and 4 deletions
|
@ -5,7 +5,7 @@ import os
|
||||||
import stat
|
import stat
|
||||||
import ssl
|
import ssl
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import Union, Optional
|
from typing import Union, Optional, Dict
|
||||||
from numbers import Real
|
from numbers import Real
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
@ -65,7 +65,7 @@ class SimpleConfig(Logger):
|
||||||
# a thread-safe way.
|
# a thread-safe way.
|
||||||
self.lock = threading.RLock()
|
self.lock = threading.RLock()
|
||||||
|
|
||||||
self.mempool_fees = {}
|
self.mempool_fees = {} # type: Dict[Union[float, int], int]
|
||||||
self.fee_estimates = {}
|
self.fee_estimates = {}
|
||||||
self.fee_estimates_last_updated = {}
|
self.fee_estimates_last_updated = {}
|
||||||
self.last_time_fee_estimates_requested = 0 # zero ensures immediate fees
|
self.last_time_fee_estimates_requested = 0 # zero ensures immediate fees
|
||||||
|
@ -341,6 +341,8 @@ class SimpleConfig(Logger):
|
||||||
fee = int(fee)
|
fee = int(fee)
|
||||||
else:
|
else:
|
||||||
fee = self.fee_estimates.get(num_blocks)
|
fee = self.fee_estimates.get(num_blocks)
|
||||||
|
if fee is not None:
|
||||||
|
fee = int(fee)
|
||||||
return fee
|
return fee
|
||||||
|
|
||||||
def fee_to_depth(self, target_fee: Real) -> int:
|
def fee_to_depth(self, target_fee: Real) -> int:
|
||||||
|
@ -374,9 +376,10 @@ class SimpleConfig(Logger):
|
||||||
return 0
|
return 0
|
||||||
# add one sat/byte as currently that is
|
# add one sat/byte as currently that is
|
||||||
# the max precision of the histogram
|
# the max precision of the histogram
|
||||||
|
# (well, in case of ElectrumX at least. not for electrs)
|
||||||
fee += 1
|
fee += 1
|
||||||
# convert to sat/kbyte
|
# convert to sat/kbyte
|
||||||
return fee * 1000
|
return int(fee * 1000)
|
||||||
|
|
||||||
def depth_target(self, slider_pos):
|
def depth_target(self, slider_pos):
|
||||||
slider_pos = max(slider_pos, 0)
|
slider_pos = max(slider_pos, 0)
|
||||||
|
@ -514,7 +517,7 @@ class SimpleConfig(Logger):
|
||||||
fee_rate = FEERATE_STATIC_VALUES[slider_pos]
|
fee_rate = FEERATE_STATIC_VALUES[slider_pos]
|
||||||
return fee_rate
|
return fee_rate
|
||||||
|
|
||||||
def fee_per_kb(self, dyn: bool=None, mempool: bool=None, fee_level: float=None) -> Union[int, None]:
|
def fee_per_kb(self, dyn: bool=None, mempool: bool=None, fee_level: float=None) -> Optional[int]:
|
||||||
"""Returns sat/kvB fee to pay for a txn.
|
"""Returns sat/kvB fee to pay for a txn.
|
||||||
Note: might return None.
|
Note: might return None.
|
||||||
|
|
||||||
|
@ -538,6 +541,8 @@ class SimpleConfig(Logger):
|
||||||
fee_rate = self.eta_to_fee(self.get_fee_level())
|
fee_rate = self.eta_to_fee(self.get_fee_level())
|
||||||
else:
|
else:
|
||||||
fee_rate = self.get('fee_per_kb', FEERATE_FALLBACK_STATIC_FEE)
|
fee_rate = self.get('fee_per_kb', FEERATE_FALLBACK_STATIC_FEE)
|
||||||
|
if fee_rate is not None:
|
||||||
|
fee_rate = int(fee_rate)
|
||||||
return fee_rate
|
return fee_rate
|
||||||
|
|
||||||
def fee_per_byte(self):
|
def fee_per_byte(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue