Skip to content

Commit 852cc28

Browse files
authored
Merge pull request #4 from aftermath2/fix_age_calculation
Fix age calculation
2 parents 0ec3fa7 + d3b79ce commit 852cc28

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

policy/node.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func (n *Node) checkAge(bestBlockHeight uint32, channels []*lnrpc.ChannelEdge) b
5858
}
5959
}
6060

61-
difference := bestBlockHeight - oldestChannel
62-
return n.Age.Contains(difference)
61+
age := (bestBlockHeight - oldestChannel) + 1
62+
return n.Age.Contains(age)
6363
}
6464

6565
func (n *Node) checkHybrid(addresses []*lnrpc.NodeAddress) bool {

policy/node_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func TestEvaluateNode(t *testing.T) {
115115
func TestCheckAge(t *testing.T) {
116116
bestBlockHeight := uint32(820931)
117117
one := uint32(1)
118+
two := uint32(2)
118119

119120
cases := []struct {
120121
desc string
@@ -136,7 +137,7 @@ func TestCheckAge(t *testing.T) {
136137
{
137138
desc: "Min no match",
138139
age: &Range[uint32]{
139-
Min: &one,
140+
Min: &two,
140141
},
141142
channels: []*lnrpc.ChannelEdge{
142143
{ChannelId: 902623180101779456}, // 820931
@@ -149,7 +150,6 @@ func TestCheckAge(t *testing.T) {
149150
Max: &one,
150151
},
151152
channels: []*lnrpc.ChannelEdge{
152-
{ChannelId: 902622080590151680}, // 820930
153153
{ChannelId: 902623180101779456}, // 820931
154154
},
155155
expected: true,
@@ -165,6 +165,18 @@ func TestCheckAge(t *testing.T) {
165165
},
166166
expected: false,
167167
},
168+
{
169+
desc: "Range",
170+
age: &Range[uint32]{
171+
Min: &one,
172+
Max: &two,
173+
},
174+
channels: []*lnrpc.ChannelEdge{
175+
{ChannelId: 902622080590151680}, // 820930
176+
{ChannelId: 902623180101779456}, // 820931
177+
},
178+
expected: true,
179+
},
168180
{
169181
desc: "No channels min",
170182
age: &Range[uint32]{

0 commit comments

Comments
 (0)