mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-01 18:27:43 +02:00
aliasmgr: avoid collision when requesting alias
With the new RPC calls that we are going to add in the next commits, it will be possible for users to add (local only, non-gossipped) SCID aliases for channels. Since those will be in the same range as the ones given out by RequestAlias, we need to make sure that when we generate a new one that it doesn't collide with an already existing one.
This commit is contained in:
@@ -168,6 +168,24 @@ func TestAliasLifecycle(t *testing.T) {
|
||||
// Query the aliases and verify that none exists.
|
||||
aliasList = aliasStore.GetAliases(baseScid)
|
||||
require.Len(t, aliasList, 0)
|
||||
|
||||
// We now request an alias generated by the aliasStore. This should give
|
||||
// the first from the pre-defined list of allocated aliases.
|
||||
firstRequested, err := aliasStore.RequestAlias()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, StartingAlias, firstRequested)
|
||||
|
||||
// We now manually add the next alias from the range as a custom alias.
|
||||
secondAlias := getNextScid(firstRequested)
|
||||
err = aliasStore.AddLocalAlias(secondAlias, baseScid, false, true)
|
||||
require.NoError(t, err)
|
||||
|
||||
// When we now request another alias from the allocation list, we expect
|
||||
// the third one (tx position 2) to be returned.
|
||||
thirdRequested, err := aliasStore.RequestAlias()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, getNextScid(secondAlias), thirdRequested)
|
||||
require.EqualValues(t, 2, thirdRequested.TxPosition)
|
||||
}
|
||||
|
||||
// TestGetNextScid tests that given a current lnwire.ShortChannelID,
|
||||
@@ -182,7 +200,7 @@ func TestGetNextScid(t *testing.T) {
|
||||
name: "starting alias",
|
||||
current: StartingAlias,
|
||||
expected: lnwire.ShortChannelID{
|
||||
BlockHeight: uint32(startingBlockHeight),
|
||||
BlockHeight: startingBlockHeight,
|
||||
TxIndex: 0,
|
||||
TxPosition: 1,
|
||||
},
|
||||
|
Reference in New Issue
Block a user