diff options
author | Janoš Guljaš <janos@users.noreply.github.com> | 2018-11-26 19:39:38 +0800 |
---|---|---|
committer | Anton Evangelatov <anton.evangelatov@gmail.com> | 2018-11-26 19:39:38 +0800 |
commit | 93854bbad4fb819375463d04cf6b7e66b7f272f7 (patch) | |
tree | 83d2e79e1f542fcf26d5e8268477bbe515a52d8d /swarm/network/simulation/simulation.go | |
parent | f0515800e6e92044466b095bbb2374465c53b6f1 (diff) | |
download | dexon-93854bbad4fb819375463d04cf6b7e66b7f272f7.tar.gz dexon-93854bbad4fb819375463d04cf6b7e66b7f272f7.tar.zst dexon-93854bbad4fb819375463d04cf6b7e66b7f272f7.zip |
swarm/network/simulation: fix New function for-loop scope (#18161)
Diffstat (limited to 'swarm/network/simulation/simulation.go')
-rw-r--r-- | swarm/network/simulation/simulation.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/swarm/network/simulation/simulation.go b/swarm/network/simulation/simulation.go index f6d3ce229..e5435b9f0 100644 --- a/swarm/network/simulation/simulation.go +++ b/swarm/network/simulation/simulation.go @@ -68,6 +68,10 @@ type ServiceFunc func(ctx *adapters.ServiceContext, bucket *sync.Map) (s node.Se // New creates a new Simulation instance with new // simulations.Network initialized with provided services. +// Services map must have unique keys as service names and +// every ServiceFunc must return a node.Service of the unique type. +// This restriction is required by node.Node.Start() function +// which is used to start node.Service returned by ServiceFunc. func New(services map[string]ServiceFunc) (s *Simulation) { s = &Simulation{ buckets: make(map[enode.ID]*sync.Map), @@ -76,6 +80,9 @@ func New(services map[string]ServiceFunc) (s *Simulation) { adapterServices := make(map[string]adapters.ServiceFunc, len(services)) for name, serviceFunc := range services { + // Scope this variables correctly + // as they will be in the adapterServices[name] function accessed later. + name, serviceFunc := name, serviceFunc s.serviceNames = append(s.serviceNames, name) adapterServices[name] = func(ctx *adapters.ServiceContext) (node.Service, error) { b := new(sync.Map) |