-
Couldn't load subscription status.
- Fork 138
Delete channel alias scids when quotes expire #1710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 0-8-0-staging
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -688,6 +688,10 @@ type OrderHandlerCfg struct { | |
| // intercept and accept/reject HTLCs. | ||
| HtlcInterceptor HtlcInterceptor | ||
|
|
||
| // AliasManager is the SCID alias manager. This component is used to add | ||
| // and remove SCID aliases. | ||
| AliasManager ScidAliasManager | ||
|
|
||
| // AcceptHtlcEvents is a channel that receives accepted HTLCs. | ||
| AcceptHtlcEvents chan<- *AcceptHtlcEvent | ||
|
|
||
|
|
@@ -918,7 +922,7 @@ func (h *OrderHandler) subscribeHtlcs(ctx context.Context) error { | |
| func (h *OrderHandler) Start() error { | ||
| var startErr error | ||
| h.startOnce.Do(func() { | ||
| // Start the main event loop in a separate goroutine. | ||
| // Start the HTLC interceptor in a separate go routine. | ||
| h.Wg.Add(1) | ||
| go func() { | ||
| defer h.Wg.Done() | ||
|
|
@@ -932,6 +936,12 @@ func (h *OrderHandler) Start() error { | |
| "interception: %v", startErr) | ||
| return | ||
| } | ||
| }() | ||
|
|
||
| // Start the main event loop in a separate go routine. | ||
| h.Wg.Add(1) | ||
| go func() { | ||
| defer h.Wg.Done() | ||
|
|
||
| h.mainEventLoop() | ||
| }() | ||
|
|
@@ -968,8 +978,8 @@ func (h *OrderHandler) RegisterAssetSalePolicy(buyAccept rfqmsg.BuyAccept) { | |
| h.policies.Store(policy.AcceptedQuoteId.Scid(), policy) | ||
| } | ||
|
|
||
| // RegisterAssetPurchasePolicy generates and registers an asset buy policy with the | ||
| // order handler. This function takes an incoming sell accept message as an | ||
| // RegisterAssetPurchasePolicy generates and registers an asset buy policy with | ||
| // the order handler. This function takes an incoming sell accept message as an | ||
| // argument. | ||
| func (h *OrderHandler) RegisterAssetPurchasePolicy( | ||
| sellAccept rfqmsg.SellAccept) { | ||
|
|
@@ -1112,9 +1122,41 @@ func (h *OrderHandler) cleanupStalePolicies() { | |
|
|
||
| h.policies.ForEach( | ||
| func(scid SerialisedScid, policy Policy) error { | ||
| if policy.HasExpired() { | ||
| staleCounter++ | ||
| h.policies.Delete(scid) | ||
| if !policy.HasExpired() { | ||
| return nil | ||
| } | ||
|
|
||
| staleCounter++ | ||
|
|
||
| // Delete the local entry of this policy. | ||
| h.policies.Delete(scid) | ||
|
Comment on lines
+1131
to
+1132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not a big deal in this case but: slightly better if we delete from the local cache last; otherwise, we might lose our reference to the resource? the cleanup routine could appear to be working from tapd's POV (few log messages without re-attempt), but in reality the cleanup could be failing. |
||
|
|
||
| ctx, cancel := h.WithCtxQuitCustomTimeout( | ||
| h.DefaultTimeout, | ||
| ) | ||
| defer cancel() | ||
|
|
||
| aliasScid := lnwire.NewShortChanIDFromInt( | ||
| uint64(scid), | ||
| ) | ||
|
|
||
| // Find the base SCID for the alias. | ||
| baseScid, err := h.cfg.AliasManager.FindBaseAlias( | ||
| ctx, aliasScid, | ||
| ) | ||
| if err != nil { | ||
| log.Warnf("Error finding base SCID for alias "+ | ||
| "%d: %v", scid, err) | ||
| return nil | ||
| } | ||
|
|
||
| // Delete the alias scid mapping on LND. | ||
| err = h.cfg.AliasManager.DeleteLocalAlias( | ||
| ctx, aliasScid, baseScid, | ||
| ) | ||
| if err != nil { | ||
| log.Warnf("Error deleting SCID alias %d: %v", | ||
| scid, err) | ||
| } | ||
|
|
||
| return nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could use
h.ContextGuard.Goroutinehere (and above if you like)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL go1.25.0 apparently also adds a WaitGroup.Go method for handling the Add(1)/Done pattern.