Skip to content
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

Support group keys for RFQ negotiation flows #1382

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
42 changes: 27 additions & 15 deletions rfq/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rfq
import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
"fmt"
"sync"
Expand Down Expand Up @@ -558,18 +559,7 @@ func (m *Manager) addScidAlias(scidAlias uint64, assetSpecifier asset.Specifier,
return c.PubKeyBytes == peer
}, localChans)

// Identify the correct channel to use as the base SCID for the alias
// by inspecting the asset data in the custom channel data.
assetID, err := assetSpecifier.UnwrapIdOrErr()
if err != nil {
return fmt.Errorf("asset ID must be specified when adding "+
"alias: %w", err)
}

var (
assetIDStr = assetID.String()
baseSCID uint64
)
var baseSCID uint64
for _, localChan := range peerChannels {
if len(localChan.CustomChannelData) == 0 {
continue
Expand All @@ -585,7 +575,29 @@ func (m *Manager) addScidAlias(scidAlias uint64, assetSpecifier asset.Specifier,

for _, channelAsset := range assetData.Assets {
gen := channelAsset.AssetInfo.AssetGenesis
if gen.AssetID == assetIDStr {
assetIDBytes, err := hex.DecodeString(
gen.AssetID,
)
if err != nil {
return fmt.Errorf("error "+
"decoding asset ID: %w", err)
}

var assetID asset.ID
copy(assetID[:], assetIDBytes)

match, err := m.AssetMatchesSpecifier(
ctxb, assetSpecifier, assetID,
)
if err != nil {
return err
}

// TODO(george): Instead of returning the first result,
// try to pick the best channel for what we're trying to
// do (receive/send). Binding a baseSCID means we're
// also binding the asset liquidity on that channel.
if match {
baseSCID = localChan.ChannelID
break
}
Expand All @@ -602,8 +614,8 @@ func (m *Manager) addScidAlias(scidAlias uint64, assetSpecifier asset.Specifier,
// At this point, if the base SCID is still not found, we return an
// error. We can't map the SCID alias to a base SCID.
if baseSCID == 0 {
return fmt.Errorf("add alias: base SCID not found for asset: "+
"%v", assetID)
return fmt.Errorf("add alias: base SCID not found for %v",
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to use %s and &assetSpecifier to invoke the .String() method here.

assetSpecifier)
}

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