Skip to content

Commit 9d12a69

Browse files
committed
commands: add test_inject_fee_etas
- the fabled return of the "inject_fees" command :D - also make fee_estimates.has_data() smarter, to ignore extraneous targets
1 parent 928e242 commit 9d12a69

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

electrum/commands.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
from .plugin import run_hook, DeviceMgr, Plugins
7272
from .version import ELECTRUM_VERSION
7373
from .simple_config import SimpleConfig
74-
from .fee_policy import FeePolicy
74+
from .fee_policy import FeePolicy, FEE_ETA_TARGETS, FEERATE_DEFAULT_RELAY
7575
from . import GuiImportError
7676
from . import crypto
7777
from . import constants
@@ -1577,6 +1577,27 @@ async def getfeerate(self):
15771577
'tooltip': tooltip,
15781578
}
15791579

1580+
@command('n')
1581+
async def test_inject_fee_etas(self, fee_est):
1582+
"""
1583+
Inject fee estimates into the network object, as if they were coming from connected servers.
1584+
Useful on regtest.
1585+
1586+
arg:str:fee_est:dict of ETA-based fee estimates, encoded as str
1587+
"""
1588+
if not isinstance(fee_est, dict):
1589+
fee_est = ast.literal_eval(fee_est)
1590+
assert isinstance(fee_est, dict), f"unexpected type for fee_est. got {repr(fee_est)}"
1591+
# populate missing high-block-number estimates using default relay fee.
1592+
# e.g. {"25": 2222} -> {"25": 2222, "144": 1000, "1008": 1000}
1593+
furthest_estimate = max(fee_est.keys()) if fee_est else 0
1594+
further_fee_est = {
1595+
eta_target: FEERATE_DEFAULT_RELAY for eta_target in FEE_ETA_TARGETS
1596+
if eta_target > furthest_estimate
1597+
}
1598+
fee_est.update(further_fee_est)
1599+
self.network.update_fee_estimates(fee_est=fee_est)
1600+
15801601
@command('w')
15811602
async def removelocaltx(self, txid, wallet: Abstract_Wallet = None):
15821603
"""Remove a 'local' transaction from the wallet, and its dependent

electrum/fee_policy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,9 @@ def has_data(self) -> bool:
375375
just try to do the estimate and handle a potential None result. That way,
376376
estimation works for targets we have, even if some targets are missing.
377377
"""
378-
# we do not request estimate for next block fee, hence -1
379-
return len(self.data) == len(FEE_ETA_TARGETS) - 1
378+
targets = set(FEE_ETA_TARGETS)
379+
targets.discard(1) # rm "next block" target
380+
return all(target in self.data for target in targets)
380381

381382
def set_data(self, nblock_target: int, fee_per_kb: int):
382383
assert isinstance(nblock_target, int), f"expected int, got {nblock_target!r}"

0 commit comments

Comments
 (0)