Skip to content

Commit 8c3fc56

Browse files
authored
p2p/simulations/adapters: use maps.Clone (#29626)
1 parent 4bdbaab commit 8c3fc56

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

p2p/simulations/adapters/inproc.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"maps"
2324
"math"
2425
"net"
2526
"sync"
@@ -215,10 +216,7 @@ func (sn *SimNode) ServeRPC(conn *websocket.Conn) error {
215216
// simulation_snapshot RPC method
216217
func (sn *SimNode) Snapshots() (map[string][]byte, error) {
217218
sn.lock.RLock()
218-
services := make(map[string]node.Lifecycle, len(sn.running))
219-
for name, service := range sn.running {
220-
services[name] = service
221-
}
219+
services := maps.Clone(sn.running)
222220
sn.lock.RUnlock()
223221
if len(services) == 0 {
224222
return nil, errors.New("no running services")
@@ -315,11 +313,7 @@ func (sn *SimNode) Services() []node.Lifecycle {
315313
func (sn *SimNode) ServiceMap() map[string]node.Lifecycle {
316314
sn.lock.RLock()
317315
defer sn.lock.RUnlock()
318-
services := make(map[string]node.Lifecycle, len(sn.running))
319-
for name, service := range sn.running {
320-
services[name] = service
321-
}
322-
return services
316+
return maps.Clone(sn.running)
323317
}
324318

325319
// Server returns the underlying p2p.Server

0 commit comments

Comments
 (0)