swarm/network/simulation: fix New function for-loop scope (#18161)
This commit is contained in:
committed by
Anton Evangelatov
parent
f0515800e6
commit
93854bbad4
@ -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)
|
||||
|
Reference in New Issue
Block a user