mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-30 17:01:34 +00:00
lightning: do not handle more than one fee update at a time
This commit is contained in:
parent
1352b0ce9f
commit
5422de90a2
2 changed files with 28 additions and 33 deletions
|
@ -1103,7 +1103,8 @@ class Peer(PrintError):
|
||||||
|
|
||||||
def on_update_fee(self, payload):
|
def on_update_fee(self, payload):
|
||||||
channel_id = payload["channel_id"]
|
channel_id = payload["channel_id"]
|
||||||
self.channels[channel_id].receive_update_fee(int.from_bytes(payload["feerate_per_kw"], "big"))
|
feerate =int.from_bytes(payload["feerate_per_kw"], "big")
|
||||||
|
self.channels[channel_id].update_fee(feerate, False)
|
||||||
|
|
||||||
async def bitcoin_fee_update(self, chan: Channel):
|
async def bitcoin_fee_update(self, chan: Channel):
|
||||||
"""
|
"""
|
||||||
|
@ -1122,7 +1123,7 @@ class Peer(PrintError):
|
||||||
self.print_error("FEES HAVE RISEN")
|
self.print_error("FEES HAVE RISEN")
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
chan.update_fee(feerate_per_kw)
|
chan.update_fee(feerate_per_kw, True)
|
||||||
await self.update_channel(chan, "update_fee", channel_id=chan.channel_id, feerate_per_kw=feerate_per_kw)
|
await self.update_channel(chan, "update_fee", channel_id=chan.channel_id, feerate_per_kw=feerate_per_kw)
|
||||||
|
|
||||||
def current_feerate_per_kw(self):
|
def current_feerate_per_kw(self):
|
||||||
|
|
|
@ -187,7 +187,7 @@ class Channel(PrintError):
|
||||||
|
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
self.fee_mgr = []
|
self.pending_fee = None
|
||||||
|
|
||||||
self.local_commitment = self.pending_local_commitment
|
self.local_commitment = self.pending_local_commitment
|
||||||
self.remote_commitment = self.pending_remote_commitment
|
self.remote_commitment = self.pending_remote_commitment
|
||||||
|
@ -377,11 +377,11 @@ class Channel(PrintError):
|
||||||
current_commitment_signature=sig,
|
current_commitment_signature=sig,
|
||||||
current_htlc_signatures=htlc_sigs_string)
|
current_htlc_signatures=htlc_sigs_string)
|
||||||
|
|
||||||
for pending_fee in self.fee_mgr:
|
if self.pending_fee:
|
||||||
if not self.constraints.is_initiator:
|
if not self.constraints.is_initiator:
|
||||||
pending_fee[FUNDEE_SIGNED] = True
|
self.pending_fee[FUNDEE_SIGNED] = True
|
||||||
if self.constraints.is_initiator and pending_fee[FUNDEE_ACKED]:
|
if self.constraints.is_initiator and self.pending_fee[FUNDEE_ACKED]:
|
||||||
pending_fee[FUNDER_SIGNED] = True
|
self.pending_fee[FUNDER_SIGNED] = True
|
||||||
|
|
||||||
self.process_new_offchain_ctx(pending_local_commitment, ours=True)
|
self.process_new_offchain_ctx(pending_local_commitment, ours=True)
|
||||||
|
|
||||||
|
@ -403,14 +403,14 @@ class Channel(PrintError):
|
||||||
|
|
||||||
new_feerate = self.constraints.feerate
|
new_feerate = self.constraints.feerate
|
||||||
|
|
||||||
for pending_fee in self.fee_mgr[:]:
|
if self.pending_fee:
|
||||||
if not self.constraints.is_initiator and pending_fee[FUNDEE_SIGNED]:
|
if not self.constraints.is_initiator and self.pending_fee[FUNDEE_SIGNED]:
|
||||||
new_feerate = pending_fee.rate
|
new_feerate = self.pending_fee.rate
|
||||||
self.fee_mgr.remove(pending_fee)
|
self.pending_fee = None
|
||||||
print("FEERATE CHANGE COMPLETE (non-initiator)")
|
print("FEERATE CHANGE COMPLETE (non-initiator)")
|
||||||
if self.constraints.is_initiator and pending_fee[FUNDER_SIGNED]:
|
if self.constraints.is_initiator and self.pending_fee[FUNDER_SIGNED]:
|
||||||
new_feerate = pending_fee.rate
|
new_feerate = self.pending_fee.rate
|
||||||
self.fee_mgr.remove(pending_fee)
|
self.pending_fee = None
|
||||||
print("FEERATE CHANGE COMPLETE (initiator)")
|
print("FEERATE CHANGE COMPLETE (initiator)")
|
||||||
|
|
||||||
self.config[LOCAL]=self.config[LOCAL]._replace(
|
self.config[LOCAL]=self.config[LOCAL]._replace(
|
||||||
|
@ -477,11 +477,11 @@ class Channel(PrintError):
|
||||||
self.log = old_logs
|
self.log = old_logs
|
||||||
raise Exception('revoked secret not for current point')
|
raise Exception('revoked secret not for current point')
|
||||||
|
|
||||||
for pending_fee in self.fee_mgr:
|
if self.pending_fee:
|
||||||
if not self.constraints.is_initiator:
|
if not self.constraints.is_initiator:
|
||||||
pending_fee[FUNDEE_SIGNED] = True
|
self.pending_fee[FUNDEE_SIGNED] = True
|
||||||
if self.constraints.is_initiator and pending_fee[FUNDEE_ACKED]:
|
if self.constraints.is_initiator and pending_fee[FUNDEE_ACKED]:
|
||||||
pending_fee[FUNDER_SIGNED] = True
|
self.pending_fee[FUNDER_SIGNED] = True
|
||||||
|
|
||||||
# FIXME not sure this is correct... but it seems to work
|
# FIXME not sure this is correct... but it seems to work
|
||||||
# if there are update_add_htlc msgs between commitment_signed and rev_ack,
|
# if there are update_add_htlc msgs between commitment_signed and rev_ack,
|
||||||
|
@ -527,9 +527,9 @@ class Channel(PrintError):
|
||||||
amount_msat = self.config[LOCAL].amount_msat + (received_this_batch - sent_this_batch)
|
amount_msat = self.config[LOCAL].amount_msat + (received_this_batch - sent_this_batch)
|
||||||
)
|
)
|
||||||
|
|
||||||
for pending_fee in self.fee_mgr:
|
if self.pending_fee:
|
||||||
if self.constraints.is_initiator:
|
if self.constraints.is_initiator:
|
||||||
pending_fee[FUNDEE_ACKED] = True
|
self.pending_fee[FUNDEE_ACKED] = True
|
||||||
|
|
||||||
self.local_commitment = self.pending_local_commitment
|
self.local_commitment = self.pending_local_commitment
|
||||||
self.remote_commitment = self.pending_remote_commitment
|
self.remote_commitment = self.pending_remote_commitment
|
||||||
|
@ -608,11 +608,10 @@ class Channel(PrintError):
|
||||||
|
|
||||||
def pending_feerate(self, subject):
|
def pending_feerate(self, subject):
|
||||||
candidate = self.constraints.feerate
|
candidate = self.constraints.feerate
|
||||||
for pending_fee in self.fee_mgr:
|
if self.pending_fee:
|
||||||
x = pending_fee.pending_feerate(subject)
|
x = self.pending_fee.pending_feerate(subject)
|
||||||
if x is not None:
|
if x is not None:
|
||||||
candidate = x
|
candidate = x
|
||||||
|
|
||||||
return candidate
|
return candidate
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -682,17 +681,12 @@ class Channel(PrintError):
|
||||||
def pending_local_fee(self):
|
def pending_local_fee(self):
|
||||||
return self.constraints.capacity - sum(x[2] for x in self.pending_local_commitment.outputs())
|
return self.constraints.capacity - sum(x[2] for x in self.pending_local_commitment.outputs())
|
||||||
|
|
||||||
def update_fee(self, feerate):
|
def update_fee(self, feerate, initiator):
|
||||||
if not self.constraints.is_initiator:
|
if self.constraints.is_initiator != initiator:
|
||||||
raise Exception("only initiator can update_fee, this counterparty is not initiator")
|
raise Exception("Cannot update_fee: wrong initiator", initiator)
|
||||||
pending_fee = FeeUpdate(self, rate=feerate)
|
if self.pending_fee:
|
||||||
self.fee_mgr.append(pending_fee)
|
raise Exception("a fee update is already in progress")
|
||||||
|
self.pending_fee = FeeUpdate(self, rate=feerate)
|
||||||
def receive_update_fee(self, feerate):
|
|
||||||
if self.constraints.is_initiator:
|
|
||||||
raise Exception("only the non-initiator can receive_update_fee, this counterparty is initiator")
|
|
||||||
pending_fee = FeeUpdate(self, rate=feerate)
|
|
||||||
self.fee_mgr.append(pending_fee)
|
|
||||||
|
|
||||||
def remove_uncommitted_htlcs_from_log(self, subject):
|
def remove_uncommitted_htlcs_from_log(self, subject):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue