Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sei-tendermint/internal/statesync/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ func (l *PeerList) Remove(peer types.NodeID) {
func (l *PeerList) All() []types.NodeID {
l.mtx.Lock()
defer l.mtx.Unlock()
return l.peers
peers := make([]types.NodeID, len(l.peers))
copy(peers, l.peers)
return peers
}

func (l *PeerList) Contains(id types.NodeID) bool {
Expand Down
17 changes: 17 additions & 0 deletions sei-tendermint/internal/statesync/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,23 @@ func TestPeerListBasic(t *testing.T) {
assert.Equal(t, half, peerList.Len())
}

func TestPeerListAllReturnsSnapshot(t *testing.T) {
peerList := NewPeerList()
peerSet := createPeerSet(2)
for _, peer := range peerSet {
peerList.Append(peer)
}

peers := peerList.All()
require.Len(t, peers, 2)

// Mutating the returned list must not mutate the internal peer list.
peers[0] = peerSet[1]
peers = peerList.All()
require.Equal(t, peerSet[0], peers[0])
require.Equal(t, peerSet[1], peers[1])
}

func TestPeerListBlocksWhenEmpty(t *testing.T) {
t.Cleanup(leaktest.Check(t))
peerList := NewPeerList()
Expand Down
5 changes: 5 additions & 0 deletions sei-tendermint/internal/statesync/reactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ func (rts *reactorTestSuite) AddPeer(t *testing.T) *Node {
paramsCh: orPanic(p2p.OpenChannel(testNode.Router, GetParamsChannelDescriptor())),
}
rts.node.Connect(t.Context(), testNode)
// Peer registration in the reactor is asynchronous, so block until this peer
// is visible before returning to callers that may assert on peer counts.
require.Eventually(t, func() bool {
return rts.reactor.peers.Contains(testNode.NodeID)
}, 5*time.Second, 50*time.Millisecond)
return n
}

Expand Down
Loading