Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lndservices/router_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func (l *LndRouterClient) DeleteLocalAlias(ctx context.Context, alias,
return l.lnd.Router.XDeleteLocalChanAlias(ctx, alias, baseScid)
}

// FindBaseAlias finds the base channel ID for a given alias.
func (l *LndRouterClient) FindBaseAlias(ctx context.Context,
alias lnwire.ShortChannelID) (lnwire.ShortChannelID, error) {

return l.lnd.Router.XFindBaseLocalChanAlias(ctx, alias)
}

// SubscribeHtlcEvents subscribes to a stream of events related to
// HTLC updates.
func (l *LndRouterClient) SubscribeHtlcEvents(
Expand Down
5 changes: 5 additions & 0 deletions rfq/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ type ScidAliasManager interface {
// Manager's maps.
DeleteLocalAlias(ctx context.Context, alias,
baseScid lnwire.ShortChannelID) error

// FindBaseAlias finds the base channel ID for a given alias.
FindBaseAlias(ctx context.Context,
alias lnwire.ShortChannelID) (lnwire.ShortChannelID, error)
}

type (
Expand Down Expand Up @@ -261,6 +265,7 @@ func (m *Manager) startSubsystems(ctx context.Context) error {
HtlcInterceptor: m.cfg.HtlcInterceptor,
HtlcSubscriber: m.cfg.HtlcSubscriber,
AcceptHtlcEvents: m.acceptHtlcEvents,
AliasManager: m.cfg.AliasManager,
SpecifierChecker: m.AssetMatchesSpecifier,
NoOpHTLCs: m.cfg.NoOpHTLCs,
AuxChanNegotiator: m.cfg.AuxChanNegotiator,
Expand Down
54 changes: 48 additions & 6 deletions rfq/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Comment on lines +941 to +944
Copy link
Contributor

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.Goroutine here (and above if you like)

Copy link
Member

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.


h.mainEventLoop()
}()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down
Loading