Skip to content

Commit

Permalink
Merge pull request #9036 from Roasbeef/0-18-3-branch
Browse files Browse the repository at this point in the history
release: bump version to v0.18.3 rc2
  • Loading branch information
Roasbeef authored Aug 28, 2024
2 parents 8f25de0 + d111d8d commit 3bb4d6d
Show file tree
Hide file tree
Showing 25 changed files with 1,279 additions and 197 deletions.
2 changes: 1 addition & 1 deletion build/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (

// AppPreRelease MUST only contain characters from semanticAlphabet per
// the semantic versioning spec.
AppPreRelease = "beta.rc1"
AppPreRelease = "beta.rc2"
)

func init() {
Expand Down
4 changes: 4 additions & 0 deletions channeldb/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ var (
// created.
ErrMetaNotFound = fmt.Errorf("unable to locate meta information")

// ErrClosedScidsNotFound is returned when the closed scid bucket
// hasn't been created.
ErrClosedScidsNotFound = fmt.Errorf("closed scid bucket doesn't exist")

// ErrGraphNotFound is returned when at least one of the components of
// graph doesn't exist.
ErrGraphNotFound = fmt.Errorf("graph bucket not initialized")
Expand Down
100 changes: 97 additions & 3 deletions channeldb/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ var (
// case we'll remove all entries from the prune log with a block height
// that no longer exists.
pruneLogBucket = []byte("prune-log")

// closedScidBucket is a top-level bucket that stores scids for
// channels that we know to be closed. This is used so that we don't
// need to perform expensive validation checks if we receive a channel
// announcement for the channel again.
//
// maps: scid -> []byte{}
closedScidBucket = []byte("closed-scid")
)

const (
Expand Down Expand Up @@ -318,6 +326,7 @@ var graphTopLevelBuckets = [][]byte{
nodeBucket,
edgeBucket,
graphMetaBucket,
closedScidBucket,
}

// Wipe completely deletes all saved state within all used buckets within the
Expand Down Expand Up @@ -2143,6 +2152,21 @@ func (c *ChannelGraph) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo,
zombieIndex, scid,
)

// TODO(ziggie): Make sure that for the strict
// pruning case we compare the pubkeys and
// whether the right timestamp is not older than
// the `ChannelPruneExpiry`.
//
// NOTE: The timestamp data has no verification
// attached to it in the `ReplyChannelRange` msg
// so we are trusting this data at this point.
// However it is not critical because we are
// just removing the channel from the db when
// the timestamps are more recent. During the
// querying of the gossip msg verification
// happens as usual.
// However we should start punishing peers when
// they don't provide us honest data ?
isStillZombie := isZombieChan(
info.Node1UpdateTimestamp,
info.Node2UpdateTimestamp,
Expand Down Expand Up @@ -2211,6 +2235,29 @@ type ChannelUpdateInfo struct {
Node2UpdateTimestamp time.Time
}

// NewChannelUpdateInfo is a constructor which makes sure we initialize the
// timestamps with zero seconds unix timestamp which equals
// `January 1, 1970, 00:00:00 UTC` in case the value is `time.Time{}`.
func NewChannelUpdateInfo(scid lnwire.ShortChannelID, node1Timestamp,
node2Timestamp time.Time) ChannelUpdateInfo {

chanInfo := ChannelUpdateInfo{
ShortChannelID: scid,
Node1UpdateTimestamp: node1Timestamp,
Node2UpdateTimestamp: node2Timestamp,
}

if node1Timestamp.IsZero() {
chanInfo.Node1UpdateTimestamp = time.Unix(0, 0)
}

if node2Timestamp.IsZero() {
chanInfo.Node2UpdateTimestamp = time.Unix(0, 0)
}

return chanInfo
}

// BlockChannelRange represents a range of channels for a given block height.
type BlockChannelRange struct {
// Height is the height of the block all of the channels below were
Expand Down Expand Up @@ -2284,9 +2331,9 @@ func (c *ChannelGraph) FilterChannelRange(startHeight,
rawCid := byteOrder.Uint64(k)
cid := lnwire.NewShortChanIDFromInt(rawCid)

chanInfo := ChannelUpdateInfo{
ShortChannelID: cid,
}
chanInfo := NewChannelUpdateInfo(
cid, time.Time{}, time.Time{},
)

if !withTimestamps {
channelsPerBlock[cid.BlockHeight] = append(
Expand Down Expand Up @@ -3846,6 +3893,53 @@ func (c *ChannelGraph) NumZombies() (uint64, error) {
return numZombies, nil
}

// PutClosedScid stores a SCID for a closed channel in the database. This is so
// that we can ignore channel announcements that we know to be closed without
// having to validate them and fetch a block.
func (c *ChannelGraph) PutClosedScid(scid lnwire.ShortChannelID) error {
return kvdb.Update(c.db, func(tx kvdb.RwTx) error {
closedScids, err := tx.CreateTopLevelBucket(closedScidBucket)
if err != nil {
return err
}

var k [8]byte
byteOrder.PutUint64(k[:], scid.ToUint64())

return closedScids.Put(k[:], []byte{})
}, func() {})
}

// IsClosedScid checks whether a channel identified by the passed in scid is
// closed. This helps avoid having to perform expensive validation checks.
// TODO: Add an LRU cache to cut down on disc reads.
func (c *ChannelGraph) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
var isClosed bool
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
closedScids := tx.ReadBucket(closedScidBucket)
if closedScids == nil {
return ErrClosedScidsNotFound
}

var k [8]byte
byteOrder.PutUint64(k[:], scid.ToUint64())

if closedScids.Get(k[:]) != nil {
isClosed = true
return nil
}

return nil
}, func() {
isClosed = false
})
if err != nil {
return false, err
}

return isClosed, nil
}

func putLightningNode(nodeBucket kvdb.RwBucket, aliasBucket kvdb.RwBucket, // nolint:dupl
updateIndex kvdb.RwBucket, node *LightningNode) error {

Expand Down
93 changes: 64 additions & 29 deletions channeldb/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1980,9 +1980,9 @@ func TestFilterKnownChanIDs(t *testing.T) {
t.Fatalf("unable to create channel edge: %v", err)
}

chanIDs = append(chanIDs, ChannelUpdateInfo{
ShortChannelID: chanID,
})
chanIDs = append(chanIDs, NewChannelUpdateInfo(
chanID, time.Time{}, time.Time{},
))
}

const numZombies = 5
Expand Down Expand Up @@ -2024,20 +2024,28 @@ func TestFilterKnownChanIDs(t *testing.T) {
// should get the same set back.
{
queryIDs: []ChannelUpdateInfo{
{ShortChannelID: lnwire.ShortChannelID{
BlockHeight: 99,
}},
{ShortChannelID: lnwire.ShortChannelID{
BlockHeight: 100,
}},
{
ShortChannelID: lnwire.ShortChannelID{
BlockHeight: 99,
},
},
{
ShortChannelID: lnwire.ShortChannelID{
BlockHeight: 100,
},
},
},
resp: []ChannelUpdateInfo{
{ShortChannelID: lnwire.ShortChannelID{
BlockHeight: 99,
}},
{ShortChannelID: lnwire.ShortChannelID{
BlockHeight: 100,
}},
{
ShortChannelID: lnwire.ShortChannelID{
BlockHeight: 99,
},
},
{
ShortChannelID: lnwire.ShortChannelID{
BlockHeight: 100,
},
},
},
},

Expand Down Expand Up @@ -2419,7 +2427,7 @@ func TestFilterChannelRange(t *testing.T) {
)
)

updateTimeSeed := int64(1)
updateTimeSeed := time.Now().Unix()
maybeAddPolicy := func(chanID uint64, node *LightningNode,
node2 bool) time.Time {

Expand All @@ -2428,7 +2436,7 @@ func TestFilterChannelRange(t *testing.T) {
chanFlags = lnwire.ChanUpdateDirection
}

var updateTime time.Time
var updateTime = time.Unix(0, 0)
if rand.Int31n(2) == 0 {
updateTime = time.Unix(updateTimeSeed, 0)
err = graph.UpdateEdgePolicy(&models.ChannelEdgePolicy{
Expand Down Expand Up @@ -2456,11 +2464,16 @@ func TestFilterChannelRange(t *testing.T) {
)
require.NoError(t, graph.AddChannelEdge(&channel2))

chanInfo1 := NewChannelUpdateInfo(
chanID1, time.Time{}, time.Time{},
)
chanInfo2 := NewChannelUpdateInfo(
chanID2, time.Time{}, time.Time{},
)
channelRanges = append(channelRanges, BlockChannelRange{
Height: chanHeight,
Channels: []ChannelUpdateInfo{
{ShortChannelID: chanID1},
{ShortChannelID: chanID2},
chanInfo1, chanInfo2,
},
})

Expand All @@ -2471,20 +2484,17 @@ func TestFilterChannelRange(t *testing.T) {
time4 = maybeAddPolicy(channel2.ChannelID, node2, true)
)

chanInfo1 = NewChannelUpdateInfo(
chanID1, time1, time2,
)
chanInfo2 = NewChannelUpdateInfo(
chanID2, time3, time4,
)
channelRangesWithTimestamps = append(
channelRangesWithTimestamps, BlockChannelRange{
Height: chanHeight,
Channels: []ChannelUpdateInfo{
{
ShortChannelID: chanID1,
Node1UpdateTimestamp: time1,
Node2UpdateTimestamp: time2,
},
{
ShortChannelID: chanID2,
Node1UpdateTimestamp: time3,
Node2UpdateTimestamp: time4,
},
chanInfo1, chanInfo2,
},
},
)
Expand Down Expand Up @@ -4027,3 +4037,28 @@ func TestGraphLoading(t *testing.T) {
graphReloaded.graphCache.nodeFeatures,
)
}

// TestClosedScid tests that we can correctly insert a SCID into the index of
// closed short channel ids.
func TestClosedScid(t *testing.T) {
t.Parallel()

graph, err := MakeTestGraph(t)
require.Nil(t, err)

scid := lnwire.ShortChannelID{}

// The scid should not exist in the closedScidBucket.
exists, err := graph.IsClosedScid(scid)
require.Nil(t, err)
require.False(t, exists)

// After we call PutClosedScid, the call to IsClosedScid should return
// true.
err = graph.PutClosedScid(scid)
require.Nil(t, err)

exists, err = graph.IsClosedScid(scid)
require.Nil(t, err)
require.True(t, exists)
}
Loading

0 comments on commit 3bb4d6d

Please sign in to comment.