erigon-pulse/cmd/devnet/scenarios/context.go
Mark Holt 529d359ca6
Bor span testing (#7897)
An update to the devnet to introduce a local heimdall to facilitate
multiple validators without the need for an external process, and hence
validator registration/staking etc.

In this initial release only span generation is supported.  

It has the following changes:

* Introduction of a local grpc heimdall interface
* Allocation of accounts via a devnet account generator ()
* Introduction on 'Services' for the network config

"--chain bor-devnet --bor.localheimdall" will run a 2 validator network
with a local service
"--chain bor-devnet --bor.withoutheimdall" will sun a single validator
with no heimdall service as before

---------

Co-authored-by: Alex Sharp <alexsharp@Alexs-MacBook-Pro-2.local>
2023-07-18 09:47:04 +01:00

106 lines
2.2 KiB
Go

package scenarios
import (
"context"
"sync"
)
func stepRunners(ctx context.Context) []*stepRunner {
return nil
}
func ContextValues(ctx context.Context) []context.Context {
if ctx == nil {
return nil
}
if compound, ok := ctx.(*CompoundContext); ok {
var contexts []context.Context
for context := range compound.contexts {
contexts = append(contexts, context)
}
return contexts
}
return []context.Context{ctx}
}
var empty struct{}
type CompoundContext struct {
context.Context
contexts map[context.Context]struct{}
mutex sync.RWMutex
}
func (join *CompoundContext) Err() error {
if join.Context.Err() != nil {
return join.Context.Err()
}
join.mutex.RLock()
defer join.mutex.RUnlock()
for context := range join.contexts {
if context.Err() != nil {
return context.Err()
}
}
return nil
}
func (join *CompoundContext) Value(key interface{}) interface{} {
join.mutex.RLock()
defer join.mutex.RUnlock()
for context := range join.contexts {
if value := context.Value(key); value != nil {
return value
}
}
return join.Context.Value(key)
}
var background = context.Background()
func JoinContexts(ctx context.Context, others ...context.Context) context.Context {
var join *CompoundContext
if ctx != nil {
if compound, ok := ctx.(*CompoundContext); ok {
join = &CompoundContext{compound.Context, map[context.Context]struct{}{}, sync.RWMutex{}}
compound.mutex.RLock()
for context := range compound.contexts {
join.contexts[context] = empty
}
compound.mutex.RUnlock()
} else {
join = &CompoundContext{background, map[context.Context]struct{}{ctx: empty}, sync.RWMutex{}}
}
} else {
join = &CompoundContext{background, map[context.Context]struct{}{}, sync.RWMutex{}}
}
for _, context := range others {
if compound, ok := context.(*CompoundContext); ok {
if compound.Context != background {
join.contexts[compound.Context] = empty
}
compound.mutex.RLock()
for context := range compound.contexts {
if context != background {
join.contexts[context] = empty
}
}
compound.mutex.RUnlock()
} else if context != nil && context != background {
join.contexts[context] = empty
}
}
return join
}