@@ -659,6 +659,10 @@ type OrderHandlerCfg struct {
659
659
// intercept and accept/reject HTLCs.
660
660
HtlcInterceptor HtlcInterceptor
661
661
662
+ // AliasManager is the SCID alias manager. This component is used to add
663
+ // and remove SCID aliases.
664
+ AliasManager ScidAliasManager
665
+
662
666
// AcceptHtlcEvents is a channel that receives accepted HTLCs.
663
667
AcceptHtlcEvents chan <- * AcceptHtlcEvent
664
668
@@ -866,7 +870,7 @@ func (h *OrderHandler) subscribeHtlcs(ctx context.Context) error {
866
870
func (h * OrderHandler ) Start () error {
867
871
var startErr error
868
872
h .startOnce .Do (func () {
869
- // Start the main event loop in a separate goroutine .
873
+ // Start the HTLC interceptor in a separate go routine .
870
874
h .Wg .Add (1 )
871
875
go func () {
872
876
defer h .Wg .Done ()
@@ -880,6 +884,12 @@ func (h *OrderHandler) Start() error {
880
884
"interception: %v" , startErr )
881
885
return
882
886
}
887
+ }()
888
+
889
+ // Start the main event loop in a separate go routine.
890
+ h .Wg .Add (1 )
891
+ go func () {
892
+ defer h .Wg .Done ()
883
893
884
894
h .mainEventLoop ()
885
895
}()
@@ -913,8 +923,8 @@ func (h *OrderHandler) RegisterAssetSalePolicy(buyAccept rfqmsg.BuyAccept) {
913
923
h .policies .Store (policy .AcceptedQuoteId .Scid (), policy )
914
924
}
915
925
916
- // RegisterAssetPurchasePolicy generates and registers an asset buy policy with the
917
- // order handler. This function takes an incoming sell accept message as an
926
+ // RegisterAssetPurchasePolicy generates and registers an asset buy policy with
927
+ // the order handler. This function takes an incoming sell accept message as an
918
928
// argument.
919
929
func (h * OrderHandler ) RegisterAssetPurchasePolicy (
920
930
sellAccept rfqmsg.SellAccept ) {
@@ -1057,9 +1067,41 @@ func (h *OrderHandler) cleanupStalePolicies() {
1057
1067
1058
1068
h .policies .ForEach (
1059
1069
func (scid SerialisedScid , policy Policy ) error {
1060
- if policy .HasExpired () {
1061
- staleCounter ++
1062
- h .policies .Delete (scid )
1070
+ if ! policy .HasExpired () {
1071
+ return nil
1072
+ }
1073
+
1074
+ staleCounter ++
1075
+
1076
+ // Delete the local entry of this policy.
1077
+ h .policies .Delete (scid )
1078
+
1079
+ ctx , cancel := h .WithCtxQuitCustomTimeout (
1080
+ h .DefaultTimeout ,
1081
+ )
1082
+ defer cancel ()
1083
+
1084
+ aliasScid := lnwire .NewShortChanIDFromInt (
1085
+ uint64 (scid ),
1086
+ )
1087
+
1088
+ // Find the base SCID for the alias.
1089
+ baseScid , err := h .cfg .AliasManager .FindBaseAlias (
1090
+ ctx , aliasScid ,
1091
+ )
1092
+ if err != nil {
1093
+ log .Warnf ("Error finding base SCID for alias " +
1094
+ "%d: %v" , scid , err )
1095
+ return nil
1096
+ }
1097
+
1098
+ // Delete the alias scid mapping on LND.
1099
+ err = h .cfg .AliasManager .DeleteLocalAlias (
1100
+ ctx , aliasScid , baseScid ,
1101
+ )
1102
+ if err != nil {
1103
+ log .Warnf ("Error deleting SCID alias %d: %v" ,
1104
+ scid , err )
1063
1105
}
1064
1106
1065
1107
return nil
0 commit comments