mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-28 07:51:27 +00:00
ln onchain fees: use 2 block ETAs with 150 s/b fallback
This commit is contained in:
parent
985d15dc8e
commit
36ce46ed70
4 changed files with 12 additions and 10 deletions
|
@ -284,7 +284,6 @@ def aiosafe(f):
|
||||||
class Peer(PrintError):
|
class Peer(PrintError):
|
||||||
|
|
||||||
def __init__(self, lnworker, host, port, pubkey, request_initial_sync=False):
|
def __init__(self, lnworker, host, port, pubkey, request_initial_sync=False):
|
||||||
self.REV_GENESIS = bytes.fromhex(bitcoin.rev_hex(constants.net.GENESIS))
|
|
||||||
self.exception = None # set by aiosafe
|
self.exception = None # set by aiosafe
|
||||||
self.host = host
|
self.host = host
|
||||||
self.port = port
|
self.port = port
|
||||||
|
@ -499,7 +498,7 @@ class Peer(PrintError):
|
||||||
keyfamilyrevocationroot = 5
|
keyfamilyrevocationroot = 5
|
||||||
keyfamilynodekey = 6 # TODO currently unused
|
keyfamilynodekey = 6 # TODO currently unused
|
||||||
# amounts
|
# amounts
|
||||||
local_feerate = 20000
|
local_feerate = self.current_feerate_per_kw()
|
||||||
# key derivation
|
# key derivation
|
||||||
keypair_generator = lambda family, i: Keypair(*wallet.keystore.get_keypair([family, i], password))
|
keypair_generator = lambda family, i: Keypair(*wallet.keystore.get_keypair([family, i], password))
|
||||||
local_config=ChannelConfig(
|
local_config=ChannelConfig(
|
||||||
|
@ -522,7 +521,7 @@ class Peer(PrintError):
|
||||||
msg = gen_msg(
|
msg = gen_msg(
|
||||||
"open_channel",
|
"open_channel",
|
||||||
temporary_channel_id=temp_channel_id,
|
temporary_channel_id=temp_channel_id,
|
||||||
chain_hash=self.REV_GENESIS,
|
chain_hash=constants.net.rev_genesis_bytes(),
|
||||||
funding_satoshis=funding_sat,
|
funding_satoshis=funding_sat,
|
||||||
push_msat=push_msat,
|
push_msat=push_msat,
|
||||||
dust_limit_satoshis=local_config.dust_limit_sat,
|
dust_limit_satoshis=local_config.dust_limit_sat,
|
||||||
|
@ -734,7 +733,7 @@ class Peer(PrintError):
|
||||||
bitcoin_signature_2=bitcoin_sigs[1],
|
bitcoin_signature_2=bitcoin_sigs[1],
|
||||||
len=0,
|
len=0,
|
||||||
#features not set (defaults to zeros)
|
#features not set (defaults to zeros)
|
||||||
chain_hash=self.REV_GENESIS,
|
chain_hash=constants.net.rev_genesis_bytes(),
|
||||||
short_channel_id=chan.short_channel_id,
|
short_channel_id=chan.short_channel_id,
|
||||||
node_id_1=node_ids[0],
|
node_id_1=node_ids[0],
|
||||||
node_id_2=node_ids[1],
|
node_id_2=node_ids[1],
|
||||||
|
@ -791,7 +790,7 @@ class Peer(PrintError):
|
||||||
chan_ann = gen_msg("channel_announcement",
|
chan_ann = gen_msg("channel_announcement",
|
||||||
len=0,
|
len=0,
|
||||||
#features not set (defaults to zeros)
|
#features not set (defaults to zeros)
|
||||||
chain_hash=self.REV_GENESIS,
|
chain_hash=constants.net.rev_genesis_bytes(),
|
||||||
short_channel_id=chan.short_channel_id,
|
short_channel_id=chan.short_channel_id,
|
||||||
node_id_1=node_ids[0],
|
node_id_1=node_ids[0],
|
||||||
node_id_2=node_ids[1],
|
node_id_2=node_ids[1],
|
||||||
|
@ -1034,7 +1033,7 @@ class Peer(PrintError):
|
||||||
|
|
||||||
def on_bitcoin_fee_update(self, chan):
|
def on_bitcoin_fee_update(self, chan):
|
||||||
"""
|
"""
|
||||||
called when the fee histogram (based on current mempool) changed
|
called when our fee estimates change
|
||||||
"""
|
"""
|
||||||
if not chan.constraints.is_initiator:
|
if not chan.constraints.is_initiator:
|
||||||
# TODO force close if initiator does not update_fee enough
|
# TODO force close if initiator does not update_fee enough
|
||||||
|
@ -1056,5 +1055,8 @@ class Peer(PrintError):
|
||||||
self.lnworker.save_channel(chan)
|
self.lnworker.save_channel(chan)
|
||||||
|
|
||||||
def current_feerate_per_kw(self):
|
def current_feerate_per_kw(self):
|
||||||
feerate_per_kvbyte = self.network.config.depth_target_to_fee(10*1000000) # 10 MB
|
from .simple_config import FEE_LN_ETA_TARGET, FEERATE_FALLBACK_STATIC_FEE
|
||||||
|
feerate_per_kvbyte = self.network.config.eta_target_to_fee(FEE_LN_ETA_TARGET)
|
||||||
|
if feerate_per_kvbyte is None:
|
||||||
|
feerate_per_kvbyte = FEERATE_FALLBACK_STATIC_FEE
|
||||||
return max(253, feerate_per_kvbyte // 4)
|
return max(253, feerate_per_kvbyte // 4)
|
||||||
|
|
|
@ -572,7 +572,6 @@ class HTLCStateMachine(PrintError):
|
||||||
"constraints": self.constraints,
|
"constraints": self.constraints,
|
||||||
"funding_outpoint": self.funding_outpoint,
|
"funding_outpoint": self.funding_outpoint,
|
||||||
"node_id": self.node_id,
|
"node_id": self.node_id,
|
||||||
"channel_id": self.channel_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
|
|
|
@ -53,7 +53,7 @@ class LNWorker(PrintError):
|
||||||
self._last_tried_peer = {} # LNPeerAddr -> unix timestamp
|
self._last_tried_peer = {} # LNPeerAddr -> unix timestamp
|
||||||
self._add_peers_from_config()
|
self._add_peers_from_config()
|
||||||
# wait until we see confirmations
|
# wait until we see confirmations
|
||||||
self.network.register_callback(self.on_network_update, ['updated', 'verified', 'fee_histogram']) # thread safe
|
self.network.register_callback(self.on_network_update, ['updated', 'verified', 'fee']) # thread safe
|
||||||
self.on_network_update('updated') # shortcut (don't block) if funding tx locked and verified
|
self.on_network_update('updated') # shortcut (don't block) if funding tx locked and verified
|
||||||
self.network.futures.append(asyncio.run_coroutine_threadsafe(self.main_loop(), asyncio.get_event_loop()))
|
self.network.futures.append(asyncio.run_coroutine_threadsafe(self.main_loop(), asyncio.get_event_loop()))
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ class LNWorker(PrintError):
|
||||||
if peer is None:
|
if peer is None:
|
||||||
self.print_error("peer not found for {}".format(bh2u(chan.node_id)))
|
self.print_error("peer not found for {}".format(bh2u(chan.node_id)))
|
||||||
return
|
return
|
||||||
if event == 'fee_histogram':
|
if event == 'fee':
|
||||||
peer.on_bitcoin_fee_update(chan)
|
peer.on_bitcoin_fee_update(chan)
|
||||||
conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1]
|
conf = self.wallet.get_tx_height(chan.funding_outpoint.txid)[1]
|
||||||
peer.on_network_update(chan, conf)
|
peer.on_network_update(chan, conf)
|
||||||
|
|
|
@ -16,6 +16,7 @@ from .i18n import _
|
||||||
|
|
||||||
FEE_ETA_TARGETS = [25, 10, 5, 2]
|
FEE_ETA_TARGETS = [25, 10, 5, 2]
|
||||||
FEE_DEPTH_TARGETS = [10000000, 5000000, 2000000, 1000000, 500000, 200000, 100000]
|
FEE_DEPTH_TARGETS = [10000000, 5000000, 2000000, 1000000, 500000, 200000, 100000]
|
||||||
|
FEE_LN_ETA_TARGET = 2 # note: make sure the network is asking for estimates for this target
|
||||||
|
|
||||||
# satoshi per kbyte
|
# satoshi per kbyte
|
||||||
FEERATE_MAX_DYNAMIC = 1500000
|
FEERATE_MAX_DYNAMIC = 1500000
|
||||||
|
|
Loading…
Add table
Reference in a new issue