Skip to content

Commit

Permalink
stub: add closed channels 10% of the time
Browse files Browse the repository at this point in the history
  • Loading branch information
carlaKC committed Oct 11, 2023
1 parent 3095a6f commit 5bbbcd5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var stubNodes = []string{

type stubChannel struct {
initiator bool
closed bool
}

type stubInFlight struct {
Expand Down Expand Up @@ -101,8 +102,13 @@ func newStubClient(ctx context.Context) *stubLndClient {
channelCount := int(key[5]%5) + 1
for i := 0; i < channelCount; i++ {
initiator := key[6+i]%2 == 0

// Make this a closed channel 10% of the time.
closed := rand.Intn(10) == 0 //nolint: gosec

channels[chanId] = &stubChannel{
initiator: initiator,
closed: closed,
}

chanMap[chanId] = key
Expand Down Expand Up @@ -322,21 +328,29 @@ func (s *stubLndClient) getInfo() (*info, error) {
}

func (s *stubLndClient) listChannels() (map[uint64]*channel, error) {
return s.getChannels(false), nil
}

func (s *stubLndClient) getChannels(closed bool) map[uint64]*channel {
allChannels := make(map[uint64]*channel)
for key, peer := range s.peers {
for chanId, ch := range peer.channels {
if (ch.closed || closed) && !(ch.closed && closed) {
continue
}

allChannels[chanId] = &channel{
peer: key,
initiator: ch.initiator,
}
}
}

return allChannels, nil
return allChannels
}

func (s *stubLndClient) listClosedChannels() (map[uint64]*channel, error) {
return make(map[uint64]*channel), nil
return s.getChannels(true), nil
}

func (s *stubLndClient) getNodeAlias(key route.Vertex) (string, error) {
Expand Down

0 comments on commit 5bbbcd5

Please sign in to comment.