Skip to content

Commit b5d5020

Browse files
committed
tmp7
1 parent 8d8f5f3 commit b5d5020

File tree

7 files changed

+72
-18
lines changed

7 files changed

+72
-18
lines changed

electrum/address_synchronizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ def get_spender(self, outpoint: str) -> Optional[str]:
10451045
"""
10461046
prev_txid, index = outpoint.split(':')
10471047
spender_txid = self.db.get_spent_outpoint(prev_txid, int(index))
1048-
# discard local spenders
1048+
# discard local spenders #
10491049
tx_mined_status = self.get_tx_height(spender_txid)
10501050
if tx_mined_status.height in [TX_HEIGHT_LOCAL, TX_HEIGHT_FUTURE]:
10511051
spender_txid = None

electrum/fee_policy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from decimal import Decimal
33
from numbers import Real
44
from enum import IntEnum
5+
import random
56

67
from .i18n import _
78
from .util import NoDynamicFeeEstimates, quantize_feerate, format_fee_satoshis
@@ -23,6 +24,7 @@
2324
FEERATE_MAX_DYNAMIC = 1500000
2425
FEERATE_WARNING_HIGH_FEE = 600000
2526
FEERATE_FALLBACK_STATIC_FEE = 150000
27+
FEERATE_REGTEST_STATIC_FEE = 1000
2628
FEERATE_DEFAULT_RELAY = 1000
2729
FEERATE_MAX_RELAY = 50000
2830

@@ -74,6 +76,7 @@ def slider_index_of_method(cls, method):
7476
i = -1
7577
return i
7678

79+
is_flaky = False
7780

7881
class FeePolicy(Logger):
7982
# object associated to a fee slider
@@ -217,8 +220,10 @@ def fee_per_kb(self, network: 'Network') -> Optional[int]:
217220
"""Returns sat/kvB fee to pay for a txn.
218221
Note: might return None.
219222
"""
223+
if is_flaky and random.random() < 0.5:
224+
return None
220225
if self.use_dynamic_estimates and constants.net is constants.BitcoinRegtest:
221-
return FEERATE_FALLBACK_STATIC_FEE
226+
return FEERATE_REGTEST_STATIC_FEE
222227

223228
if self.method == FeeMethod.FEERATE:
224229
fee_rate = self.value

electrum/lnchannel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def get_ctx_sweep_info(self, ctx: Transaction) -> Tuple[bool, Dict[str, SweepInf
313313
sweep_info = their_sweep_info
314314
who_closed = REMOTE
315315
else:
316-
sweep_info = {}
316+
sweep_info = {} #
317317
who_closed = 0
318318
if self._who_closed != who_closed: # mostly here to limit log spam
319319
self._who_closed = who_closed
@@ -443,7 +443,7 @@ def update_closed_state(self, *, funding_txid: str, funding_height: TxMinedInfo,
443443
util.trigger_callback('channel', self.lnworker.wallet, self)
444444

445445
if self.get_state() == ChannelState.CLOSED and not keep_watching:
446-
self.set_state(ChannelState.REDEEMED)
446+
self.set_state(ChannelState.REDEEMED) #
447447
if self.lnworker and self.is_backup():
448448
# auto-remove redeemed backups
449449
self.lnworker.remove_channel_backup(self.channel_id)

electrum/lnwatcher.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ async def check_onchain_situation(self, address: str, funding_outpoint: str) ->
9999
if not self.adb.is_mine(address):
100100
return
101101
# inspect_tx_candidate might have added new addresses, in which case we return early
102+
# TODO why don't we wait until adb.is_up_to_date ?!
102103
funding_txid = funding_outpoint.split(':')[0]
103104
funding_height = self.adb.get_tx_height(funding_txid)
104105
closing_txid = self.adb.get_spender(funding_outpoint)
@@ -159,9 +160,9 @@ async def sweep_commitment_transaction(self, funding_outpoint: str, closing_tx:
159160
return False
160161
# detect who closed and get information about how to claim outputs
161162
is_local_ctx, sweep_info_dict = chan.get_ctx_sweep_info(closing_tx)
162-
keep_watching = False if sweep_info_dict else not self.adb.is_deeply_mined(closing_tx.txid())
163+
keep_watching = False if sweep_info_dict else not self.adb.is_deeply_mined(closing_tx.txid()) #
163164
# create and broadcast transactions
164-
for prevout, sweep_info in sweep_info_dict.items():
165+
for prevout, sweep_info in sweep_info_dict.items(): #
165166
prev_txid, prev_index = prevout.split(':')
166167
name = sweep_info.name + ' ' + chan.get_id_for_log()
167168
self.lnworker.wallet.set_default_label(prevout, name)
@@ -170,7 +171,7 @@ async def sweep_commitment_transaction(self, funding_outpoint: str, closing_tx:
170171
self.logger.info(f'prevout does not exist for {name}: {prevout}')
171172
continue
172173
was_added = self.maybe_redeem(sweep_info)
173-
spender_txid = self.adb.get_spender(prevout)
174+
spender_txid = self.adb.get_spender(prevout) # note: LOCAL spenders don't count
174175
spender_tx = self.adb.get_transaction(spender_txid) if spender_txid else None
175176
if spender_tx:
176177
# the spender might be the remote, revoked or not
@@ -188,7 +189,7 @@ async def sweep_commitment_transaction(self, funding_outpoint: str, closing_tx:
188189
self.maybe_extract_preimage(chan, spender_tx, prevout)
189190
self.maybe_add_accounting_address(spender_txid, sweep_info)
190191
else:
191-
keep_watching |= was_added
192+
keep_watching |= was_added #
192193
self.maybe_add_pending_forceclose(
193194
chan=chan, spender_txid=spender_txid, is_local_ctx=is_local_ctx, sweep_info=sweep_info, was_added=was_added)
194195
return keep_watching

electrum/lnworker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
)
4141
from .fee_policy import (
4242
FeePolicy, FEERATE_FALLBACK_STATIC_FEE, FEE_LN_ETA_TARGET, FEE_LN_LOW_ETA_TARGET,
43-
FEERATE_PER_KW_MIN_RELAY_LIGHTNING, FEE_LN_MINIMUM_ETA_TARGET
43+
FEERATE_PER_KW_MIN_RELAY_LIGHTNING, FEE_LN_MINIMUM_ETA_TARGET, FEERATE_REGTEST_STATIC_FEE
4444
)
4545
from .invoices import Invoice, PR_UNPAID, PR_PAID, PR_INFLIGHT, PR_FAILED, LN_EXPIRY_NEVER, BaseInvoice
4646
from .bitcoin import COIN, opcodes, make_op_return, address_to_scripthash, DummyAddress
@@ -3080,9 +3080,10 @@ def current_target_feerate_per_kw(self, *, has_anchors: bool) -> Optional[int]:
30803080
# grows quickly
30813081
feerate_per_kvbyte = max(feerate_per_kvbyte, 5000)
30823082
else:
3083-
if constants.net is not constants.BitcoinRegtest:
3083+
if constants.net is constants.BitcoinRegtest:
3084+
feerate_per_kvbyte = FEERATE_REGTEST_STATIC_FEE
3085+
else:
30843086
return None
3085-
feerate_per_kvbyte = FEERATE_FALLBACK_STATIC_FEE
30863087
return max(FEERATE_PER_KW_MIN_RELAY_LIGHTNING, feerate_per_kvbyte // 4)
30873088

30883089
def current_low_feerate_per_kw_srk_channel(self) -> Optional[int]:

electrum/txbatcher.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import copy
6363
from typing import Dict, Sequence, Optional, TYPE_CHECKING, Mapping, Set, List, Tuple
6464

65+
import electrum
6566
from . import util
6667
from .bitcoin import dust_threshold
6768
from .logging import Logger
@@ -271,7 +272,10 @@ def is_dust(self, sweep_info: SweepInfo) -> bool:
271272
witness_size = len(sweep_info.txin.make_witness(71*b'\x00'))
272273
tx_size_vbytes = 84 + witness_size//4 # assumes no batching, sweep to p2wpkh
273274
self.logger.info(f'{sweep_info.name} size = {tx_size_vbytes}')
274-
fee = self.fee_policy.estimate_fee(tx_size_vbytes, network=self.wallet.network, allow_fallback_to_static_rates=True)
275+
electrum.fee_policy.is_flaky = True
276+
fee = self.fee_policy.estimate_fee(tx_size_vbytes, network=self.wallet.network, allow_fallback_to_static_rates=True) # TODO why allow fallback?
277+
self.logger.info(f"heyheyhey. is_dust. {value=}. {fee=}. {dust_threshold()=}")
278+
electrum.fee_policy.is_flaky = False
275279
return value - fee <= dust_threshold()
276280

277281
@locked

tests/regtest/regtest.sh

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
export HOME=~
33
set -eu
44

5-
TEST_ANCHOR_CHANNELS=True
5+
TEST_ANCHOR_CHANNELS=False
66

77
# alice -> bob -> carol
88

@@ -323,12 +323,12 @@ if [[ $1 == "swapserver_server_skip_onchain_funding" ]]; then
323323
new_blocks 3
324324
wait_until_channel_open alice
325325
echo "alice initiates swap"
326-
dryrun=$($alice reverse_swap 0.02 dryrun)
326+
dryrun=$($alice reverse_swap 0.0002 dryrun)
327327
onchain_amount=$(echo $dryrun| jq -r ".onchain_amount")
328328
# Alice starts a reverse-swap, but will time out waiting for Bob's swap-funding-tx to appear in mempool.
329329
$alice setconfig timeout 10
330330
set +e
331-
swap=$($alice reverse_swap 0.02 $onchain_amount)
331+
swap=$($alice reverse_swap 0.0002 $onchain_amount)
332332
set -e
333333
$alice unsetconfig timeout
334334
# After a while, Alice gets impatient and gets Bob to close the channel.
@@ -339,11 +339,54 @@ if [[ $1 == "swapserver_server_skip_onchain_funding" ]]; then
339339
wait_until_channel_closed alice
340340
ctx_id=$($alice list_channels | jq -r ".[0].closing_txid")
341341
# need more blocks to reach CLTV of HTLC-output in ctx
342-
new_blocks 130
342+
343+
$alice stop
344+
new_blocks 20
345+
$alice daemon -d
346+
$alice load_wallet
347+
sleep 5
348+
349+
$alice stop
350+
new_blocks 20
351+
$alice daemon -d
352+
$alice load_wallet
353+
sleep 5
354+
355+
$alice stop
356+
new_blocks 20
357+
$alice daemon -d
358+
$alice load_wallet
359+
sleep 5
360+
361+
$alice stop
362+
new_blocks 20
363+
$alice daemon -d
364+
$alice load_wallet
365+
sleep 5
366+
367+
$alice stop
368+
new_blocks 20
369+
$alice daemon -d
370+
$alice load_wallet
371+
sleep 5
372+
373+
$alice stop
374+
new_blocks 20
375+
$alice daemon -d
376+
$alice load_wallet
377+
sleep 5
378+
379+
$alice stop
380+
new_blocks 20
381+
$alice daemon -d
382+
$alice load_wallet
383+
sleep 5
384+
385+
#new_blocks 130
343386
if [ $TEST_ANCHOR_CHANNELS = True ] ; then
344-
htlc_output_index=3 # FIXME index depends on Alice not using MPP
387+
htlc_output_index=2 # FIXME index depends on Alice not using MPP. # FIXME also assumes there was a non-dust fee-prepayment
345388
else
346-
htlc_output_index=1
389+
htlc_output_index=0
347390
fi
348391
wait_until_spent $ctx_id $htlc_output_index
349392
new_blocks 1

0 commit comments

Comments
 (0)