From 604bd81100b04ea6730e651ad5e14b199b70ccd9 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 9 Aug 2024 16:05:04 +0200 Subject: [PATCH] aliasmgr: export alias start and end ranges Because we restrict custom SCID aliases to be in a specific range, we export the range start and end values so a user of the RPCs we're going to add in the next commits can adjust their values to fit within the range. --- aliasmgr/aliasmgr.go | 23 +++++++++++++---------- aliasmgr/aliasmgr_test.go | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/aliasmgr/aliasmgr.go b/aliasmgr/aliasmgr.go index 689af1366..f06cb53d7 100644 --- a/aliasmgr/aliasmgr.go +++ b/aliasmgr/aliasmgr.go @@ -58,17 +58,18 @@ var ( // operations. byteOrder = binary.BigEndian - // startBlockHeight is the starting block height of the alias range. - startingBlockHeight uint32 = 16_000_000 + // AliasStartBlockHeight is the starting block height of the alias + // range. + AliasStartBlockHeight uint32 = 16_000_000 - // endBlockHeight is the ending block height of the alias range. - endBlockHeight uint32 = 16_250_000 + // AliasEndBlockHeight is the ending block height of the alias range. + AliasEndBlockHeight uint32 = 16_250_000 // StartingAlias is the first alias ShortChannelID that will get // assigned by RequestAlias. The starting BlockHeight is chosen so that // legitimate SCIDs in integration tests aren't mistaken for an alias. StartingAlias = lnwire.ShortChannelID{ - BlockHeight: startingBlockHeight, + BlockHeight: AliasStartBlockHeight, TxIndex: 0, TxPosition: 0, } @@ -547,7 +548,9 @@ func (m *Manager) RequestAlias() (lnwire.ShortChannelID, error) { nextAlias = getNextScid(nextAlias) // Abort if we've reached the end of the range. - if nextAlias.BlockHeight >= endBlockHeight { + if nextAlias.BlockHeight >= + AliasEndBlockHeight { + return fmt.Errorf("range for custom " + "aliases exhausted") } @@ -581,7 +584,7 @@ func (m *Manager) RequestAlias() (lnwire.ShortChannelID, error) { nextAlias = getNextScid(nextAlias) // Abort if we've reached the end of the range. - if nextAlias.BlockHeight >= endBlockHeight { + if nextAlias.BlockHeight >= AliasEndBlockHeight { return fmt.Errorf("range for custom " + "aliases exhausted") } @@ -665,10 +668,10 @@ func getNextScid(last lnwire.ShortChannelID) lnwire.ShortChannelID { // IsAlias returns true if the passed SCID is an alias. The function determines // this by looking at the BlockHeight. If the BlockHeight is greater than -// startingBlockHeight and less than endBlockHeight, then it is an alias +// AliasStartBlockHeight and less than AliasEndBlockHeight, then it is an alias // assigned by RequestAlias. These bounds only apply to aliases we generate. // Our peers are free to use any range they choose. func IsAlias(scid lnwire.ShortChannelID) bool { - return scid.BlockHeight >= startingBlockHeight && - scid.BlockHeight < endBlockHeight + return scid.BlockHeight >= AliasStartBlockHeight && + scid.BlockHeight < AliasEndBlockHeight } diff --git a/aliasmgr/aliasmgr_test.go b/aliasmgr/aliasmgr_test.go index 2d9a54e23..1844a82ef 100644 --- a/aliasmgr/aliasmgr_test.go +++ b/aliasmgr/aliasmgr_test.go @@ -200,7 +200,7 @@ func TestGetNextScid(t *testing.T) { name: "starting alias", current: StartingAlias, expected: lnwire.ShortChannelID{ - BlockHeight: startingBlockHeight, + BlockHeight: AliasStartBlockHeight, TxIndex: 0, TxPosition: 1, },