Merge pull request #9621 from jjjike2021/exp/maps

multi: remove x/exp/maps dependency
This commit is contained in:
Oliver Gugger 2025-03-25 07:08:02 -06:00 committed by GitHub
commit 813f26cbc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 22 additions and 13 deletions

View File

@ -3,13 +3,14 @@ package aliasmgr
import (
"encoding/binary"
"fmt"
"maps"
"slices"
"sync"
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/lnwire"
"golang.org/x/exp/maps"
)
// UpdateLinkAliases is a function type for a function that locates the active
@ -515,7 +516,7 @@ func (m *Manager) RequestAlias() (lnwire.ShortChannelID, error) {
// channel in the baseToSet map.
haveAlias := func(maybeNextAlias lnwire.ShortChannelID) bool {
return fn.Any(
maps.Values(m.baseToSet),
slices.Collect(maps.Values(m.baseToSet)),
func(aliasList []lnwire.ShortChannelID) bool {
return fn.Any(
aliasList,

View File

@ -242,6 +242,8 @@ close transaction.
* [The bitcoin `testnet4` test network is now also
supported](https://github.com/lightningnetwork/lnd/pull/9620).
* [remove x/exp/maps dependency](https://github.com/lightningnetwork/lnd/pull/9621)
## RPC Updates
* Some RPCs that previously just returned an empty response message now at least

View File

@ -2,13 +2,13 @@ package fn
import (
"fmt"
"golang.org/x/exp/maps"
"maps"
"slices"
)
// KeySet converts a map into a Set containing the keys of the map.
func KeySet[K comparable, V any](m map[K]V) Set[K] {
return NewSet(maps.Keys(m)...)
return NewSet(slices.Collect(maps.Keys(m))...)
}
// NewSubMapIntersect returns a sub-map of `m` containing only the keys found in

View File

@ -1,6 +1,9 @@
package fn
import "golang.org/x/exp/maps"
import (
"maps"
"slices"
)
// Set is a generic set using type params that supports the following
// operations: diff, union, intersection, and subset.
@ -92,7 +95,7 @@ func (s Set[T]) Equal(other Set[T]) bool {
// ToSlice returns the set as a slice.
func (s Set[T]) ToSlice() []T {
return maps.Keys(s)
return slices.Collect(maps.Keys(s))
}
// Copy copies s and returns the result.

View File

@ -4,6 +4,8 @@ import (
"encoding/hex"
"errors"
"fmt"
"maps"
"slices"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg"
@ -14,7 +16,6 @@ import (
"github.com/lightningnetwork/lnd/fn/v2"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
"golang.org/x/exp/maps"
)
var (
@ -222,7 +223,7 @@ func UnmarshallCoinSelectionStrategy(strategy CoinSelectionStrategy,
// used in various RPCs that handle scid alias mappings.
func MarshalAliasMap(scidMap aliasmgr.ScidAliasMap) []*AliasMap {
return fn.Map(
maps.Keys(scidMap),
slices.Collect(maps.Keys(scidMap)),
func(base lnwire.ShortChannelID) *AliasMap {
return &AliasMap{
BaseScid: base.ToUint64(),

View File

@ -10,9 +10,11 @@ import (
"encoding/binary"
"errors"
"fmt"
"maps"
"math"
"os"
"path/filepath"
"slices"
"sort"
"time"
@ -43,7 +45,6 @@ import (
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/sweep"
"golang.org/x/exp/maps"
"google.golang.org/grpc"
"gopkg.in/macaroon-bakery.v2/bakery"
)
@ -1269,7 +1270,7 @@ func (w *WalletKit) BumpForceCloseFee(_ context.Context,
err)
}
pendingSweeps := maps.Values(inputsMap)
pendingSweeps := slices.Collect(maps.Values(inputsMap))
// Discard everything except for the anchor sweeps.
anchors := fn.Filter(

View File

@ -3,7 +3,9 @@ package sweep
import (
"errors"
"fmt"
"maps"
"math"
"slices"
"time"
"github.com/btcsuite/btcd/btcutil"
@ -15,7 +17,6 @@ import (
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
"golang.org/x/exp/maps"
)
var (
@ -425,7 +426,7 @@ func fetchUtxosFromOutpoints(utxos []*lnwallet.Utxo,
return nil, fmt.Errorf("%w: %v", ErrUnknownUTXO, err.Error())
}
fetchedUtxos := maps.Values(subMap)
fetchedUtxos := slices.Collect(maps.Values(subMap))
return fetchedUtxos, nil
}