Disable mpp until LND race condition is resolved (#323)

This commit is contained in:
HODLmeTight 2024-03-02 16:37:21 +01:00 committed by GitHub
parent 82ff6ca134
commit 0a270195cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -36,8 +36,25 @@ def inbound_cans_len(inbound_cans):
except Exception as e:
print(f"{datetime.now().strftime('%c')} : [Rebalancer] : Error getting inbound cands: {str(e)}")
@sync_to_async
def check_and_set_allow_multishards():
allow_multishards = True # Default value is True
disable_mpp_setting = LocalSettings.objects.filter(key='LND-DisableMPP').first()
if disable_mpp_setting:
if int(disable_mpp_setting.value) > 0:
allow_multishards = False
else:
# If the setting does not exist, create it with a default value of '0'
LocalSettings.objects.create(key='LND-DisableMPP', value='0')
return allow_multishards
async def run_rebalancer(rebalance, worker):
try:
# Check if LocalSetting LND-EnableMPP exists and set allow_mpp accordingly
allow_multishards = await check_and_set_allow_multishards() # Default value is True.
max_parts = None if allow_multishards else 1 # Adjust max_parts based on the allow_multishards value
#Reduce potential rebalance value in percent out to avoid going below AR-OUT-Target
auto_rebalance_channels = Channels.objects.filter(is_active=True, is_open=True, private=False).annotate(percent_outbound=((Sum('local_balance')+Sum('pending_outbound')-rebalance.value)*100)/Sum('capacity')).annotate(inbound_can=(((Sum('remote_balance')+Sum('pending_inbound'))*100)/Sum('capacity'))/Sum('ar_in_target'))
outbound_cans = await get_out_cans(rebalance, auto_rebalance_channels)
@ -59,7 +76,7 @@ async def run_rebalancer(rebalance, worker):
timeout = rebalance.duration * 60
invoice_response = stub.AddInvoice(ln.Invoice(value=rebalance.value, expiry=timeout))
print(f"{datetime.now().strftime('%c')} : [Rebalancer] : {worker} starting rebalance for {rebalance.target_alias} {rebalance.last_hop_pubkey} for {rebalance.value} sats and duration {rebalance.duration}, using {len(chan_ids)} outbound channels")
async for payment_response in routerstub.SendPaymentV2(lnr.SendPaymentRequest(payment_request=str(invoice_response.payment_request), fee_limit_msat=int(rebalance.fee_limit*1000), outgoing_chan_ids=chan_ids, last_hop_pubkey=bytes.fromhex(rebalance.last_hop_pubkey), timeout_seconds=(timeout-5), allow_self_payment=True), timeout=(timeout+60)):
async for payment_response in routerstub.SendPaymentV2(lnr.SendPaymentRequest(payment_request=str(invoice_response.payment_request), fee_limit_msat=int(rebalance.fee_limit*1000), outgoing_chan_ids=chan_ids, last_hop_pubkey=bytes.fromhex(rebalance.last_hop_pubkey), timeout_seconds=(timeout-5), allow_self_payment=True, max_parts=max_parts), timeout=(timeout+60)):
if payment_response.status == 1 and rebalance.status == 0:
#IN-FLIGHT
rebalance.payment_hash = payment_response.payment_hash