Skip to content

Conversation

hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Aug 31, 2023

This PR allows the auto loop-in dispatcher to continue with the execution of the next swap once a previous swap's invoice is settled.

Set parameters

loop --network regtest setparams --autoloop=true --autobudget 10000000 --maxamt 1000000 --feepercent 20 --autoinflight 10

Set rule

loop --network regtest setrule --type in --outgoing_threshold 99 node_key_to_loop_in_to

Result:
A new swap is dispatched although the previous swap is still in a pending state

LOOP_IN SUCCESS 0.003 BTC - P2TR: bcrt1p7awp9kaujtdr5h2pzlcpzyuypjsnh35trv5ma49mznfkl6yntntsh739lh (cost: server 130, onchain 7700, offchain 0)
LOOP_IN INVOICE_SETTLED 0.003 BTC - P2TR: bcrt1para8f4fy3r9qtrvvpmrf0z3uzwh776zv7577fsx24k8mvtxfagrqhp6w87 (cost: server -299870, onchain 7700, offchain 0)
LOOP_IN HTLC_PUBLISHED 0.003 BTC - P2TR: bcrt1pzapdkea2gamkf5f7p52lwhx0p55ry57g59qnyugxda6rn7m6295q6zpd9g

Accounting considerations:

To deal with pending swap fees the auto loop-in engine temporarily assigns pending swaps the maximum allowed fees so to not overshoot the set budget. Once the swap finalizes the actual fees(likely lower) will be set on the swap and the auto-loop dispatcher will reevaluate the creation of a new swap if it was previously blocked by an elapsed budget.
As an example, we could create many swaps in settled state that temporarily chew up our budget - but once the swaps finalize and capital frees new swaps might be dispatched.

@hieblmi hieblmi force-pushed the loopin-settlement-fix branch from 40a2466 to 8e971d9 Compare August 31, 2023 14:34
Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm ⭐

@hieblmi hieblmi changed the title loopin: consider settled invoices success auto loopin: consider settled invoices success Aug 31, 2023
Copy link
Member

@bhandras bhandras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

// Include any pending swaps in our ongoing set of swaps.
case in.State().State.Type() == loopdb.StateTypePending:
case in.State().State.Type() == loopdb.StateTypePending &&
in.State().State != loopdb.StateInvoiceSettled:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: perhaps consider adding a comment here explaining why we do this.

@hieblmi hieblmi changed the title auto loopin: consider settled invoices success auto loopin: consider settled invoices swap succeeded Sep 1, 2023
@hieblmi hieblmi force-pushed the loopin-settlement-fix branch from 8e971d9 to fd6a9cf Compare September 1, 2023 11:08
@hieblmi hieblmi mentioned this pull request Sep 4, 2023
@hieblmi hieblmi merged commit 5739fa5 into lightninglabs:master Sep 5, 2023
@hieblmi hieblmi deleted the loopin-settlement-fix branch September 15, 2025 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants