Skip to content

Commit 54287fc

Browse files
committed
rfq: addScidAlias accepts group key specifier
When trying to add a local scid alias we would look up all channels and filter them based on whether the asset ID matches the one of the specifier. We now call the previously introduced helper method to easily check the asset against the specifier.
1 parent f66ec78 commit 54287fc

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

rfq/manager.go

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -558,18 +558,7 @@ func (m *Manager) addScidAlias(scidAlias uint64, assetSpecifier asset.Specifier,
558558
return c.PubKeyBytes == peer
559559
}, localChans)
560560

561-
// Identify the correct channel to use as the base SCID for the alias
562-
// by inspecting the asset data in the custom channel data.
563-
assetID, err := assetSpecifier.UnwrapIdOrErr()
564-
if err != nil {
565-
return fmt.Errorf("asset ID must be specified when adding "+
566-
"alias: %w", err)
567-
}
568-
569-
var (
570-
assetIDStr = assetID.String()
571-
baseSCID uint64
572-
)
561+
var baseSCID uint64
573562
for _, localChan := range peerChannels {
574563
if len(localChan.CustomChannelData) == 0 {
575564
continue
@@ -583,12 +572,20 @@ func (m *Manager) addScidAlias(scidAlias uint64, assetSpecifier asset.Specifier,
583572
continue
584573
}
585574

586-
for _, channelAsset := range assetData.Assets {
587-
gen := channelAsset.AssetInfo.AssetGenesis
588-
if gen.AssetID == assetIDStr {
589-
baseSCID = localChan.ChannelID
590-
break
591-
}
575+
match, err := m.ChannelCompatible(
576+
ctxb, assetData.Assets, assetSpecifier,
577+
)
578+
if err != nil {
579+
return err
580+
}
581+
582+
// TODO(george): Instead of returning the first result,
583+
// try to pick the best channel for what we're trying to
584+
// do (receive/send). Binding a baseSCID means we're
585+
// also binding the asset liquidity on that channel.
586+
if match {
587+
baseSCID = localChan.ChannelID
588+
break
592589
}
593590
}
594591

@@ -602,8 +599,8 @@ func (m *Manager) addScidAlias(scidAlias uint64, assetSpecifier asset.Specifier,
602599
// At this point, if the base SCID is still not found, we return an
603600
// error. We can't map the SCID alias to a base SCID.
604601
if baseSCID == 0 {
605-
return fmt.Errorf("add alias: base SCID not found for asset: "+
606-
"%v", assetID)
602+
return fmt.Errorf("add alias: base SCID not found for %s",
603+
&assetSpecifier)
607604
}
608605

609606
log.Debugf("Adding SCID alias %d for base SCID %d", scidAlias, baseSCID)

0 commit comments

Comments
 (0)