multi: fix time.Time initialization.
ChanUpdate timestamps are now restircted so that they cannot be more than two weeks into the future. Moreover channels with both timestamps in the ReplyChannelRange msg either too far in the past or too far in the future are not queried. Moreover fix unitests.
This commit is contained in:
5 files changed
+208
-38
No files matched your search
+26
-3
@@ -2211,6 +2211,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
|
||||
@@ -2284,9 +2307,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(
|
||||
|
||||
+39
-29
@@ -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
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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{
|
||||
@@ -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,
|
||||
},
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user