Merge pull request #3889 from carlaKC/chanfitness-startonlineevent
chanfitness: Bugfix save initial peer online event
This commit is contained in:
commit
4a0ccc927a
@ -210,6 +210,12 @@ func (c *ChannelEventStore) addChannel(channelPoint wire.OutPoint,
|
|||||||
// Create an event log for the channel.
|
// Create an event log for the channel.
|
||||||
eventLog := newEventLog(channelPoint, peer, time.Now)
|
eventLog := newEventLog(channelPoint, peer, time.Now)
|
||||||
|
|
||||||
|
// If the peer is already online, add a peer online event to record
|
||||||
|
// the starting state of the peer.
|
||||||
|
if c.peers[peer] {
|
||||||
|
eventLog.add(peerOnlineEvent)
|
||||||
|
}
|
||||||
|
|
||||||
c.channels[channelPoint] = eventLog
|
c.channels[channelPoint] = eventLog
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,23 +469,61 @@ func TestGetUptime(t *testing.T) {
|
|||||||
|
|
||||||
// TestAddChannel tests that channels are added to the event store with
|
// TestAddChannel tests that channels are added to the event store with
|
||||||
// appropriate timestamps. This test addresses a bug where offline channels
|
// appropriate timestamps. This test addresses a bug where offline channels
|
||||||
// did not have an opened time set.
|
// did not have an opened time set, and checks that an online event is set for
|
||||||
|
// peers that are online at the time that a channel is opened.
|
||||||
func TestAddChannel(t *testing.T) {
|
func TestAddChannel(t *testing.T) {
|
||||||
_, vertex, chanPoint := getTestChannel(t)
|
_, vertex, chanPoint := getTestChannel(t)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
|
||||||
|
// peers maps peers to an online state.
|
||||||
|
peers map[route.Vertex]bool
|
||||||
|
|
||||||
|
expectedEvents []eventType
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "peer offline",
|
||||||
|
peers: make(map[route.Vertex]bool),
|
||||||
|
expectedEvents: []eventType{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "peer online",
|
||||||
|
peers: map[route.Vertex]bool{
|
||||||
|
vertex: true,
|
||||||
|
},
|
||||||
|
expectedEvents: []eventType{peerOnlineEvent},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
test := test
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
store := NewChannelEventStore(&Config{})
|
store := NewChannelEventStore(&Config{})
|
||||||
|
store.peers = test.peers
|
||||||
|
|
||||||
// Add channel to the store.
|
// Add channel to the store.
|
||||||
store.addChannel(chanPoint, vertex)
|
store.addChannel(chanPoint, vertex)
|
||||||
|
|
||||||
// Check that the eventlog is successfully added.
|
// Check that the eventLog is successfully added.
|
||||||
eventlog, ok := store.channels[chanPoint]
|
eventLog, ok := store.channels[chanPoint]
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("channel should be in store")
|
t.Fatalf("channel should be in store")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the eventLog contains the events we
|
||||||
|
// expect.
|
||||||
|
for i, e := range test.expectedEvents {
|
||||||
|
if e != eventLog.events[i].eventType {
|
||||||
|
t.Fatalf("expected: %v, got: %v",
|
||||||
|
e, eventLog.events[i].eventType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure that open time is always set.
|
// Ensure that open time is always set.
|
||||||
if eventlog.openedAt.IsZero() {
|
if eventLog.openedAt.IsZero() {
|
||||||
t.Fatalf("channel should have opened at set")
|
t.Fatalf("channel should have opened at set")
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user