mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 21:08:10 -05:00
* Implement static analysis to prevent panics * Add nopanic to nogo * Fix violations and add exclusions Fix violations and add exclusions for all * Changelog fragment * Use pass.Report instead of pass.Reportf * Remove strings.ToLower for checking init method name * Add exclusion for herumi init * Move api/client/beacon template function to init and its own file * Fix nopanic testcase
40 lines
1001 B
Go
40 lines
1001 B
Go
//go:build develop
|
|
|
|
package params
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/mohae/deepcopy"
|
|
)
|
|
|
|
var cfgrw sync.RWMutex
|
|
|
|
// BeaconConfig retrieves beacon chain config.
|
|
func BeaconConfig() *BeaconChainConfig {
|
|
cfgrw.RLock()
|
|
defer cfgrw.RUnlock()
|
|
return configs.getActive()
|
|
}
|
|
|
|
// OverrideBeaconConfig by replacing the config. The preferred pattern is to
|
|
// call BeaconConfig(), change the specific parameters, and then call
|
|
// OverrideBeaconConfig(c). Any subsequent calls to params.BeaconConfig() will
|
|
// return this new configuration.
|
|
func OverrideBeaconConfig(c *BeaconChainConfig) {
|
|
cfgrw.Lock()
|
|
defer cfgrw.Unlock()
|
|
configs.active = c
|
|
}
|
|
|
|
// Copy returns a copy of the config object.
|
|
func (b *BeaconChainConfig) Copy() *BeaconChainConfig {
|
|
cfgrw.RLock()
|
|
defer cfgrw.RUnlock()
|
|
config, ok := deepcopy.Copy(*b).(BeaconChainConfig)
|
|
if !ok {
|
|
panic("somehow deepcopy produced a BeaconChainConfig that is not of the same type as the original") // lint:nopanic -- Impossible scenario.
|
|
}
|
|
return &config
|
|
}
|