2022-03-14 20:58:13 +00:00
|
|
|
//go:build develop
|
2021-01-04 20:48:39 +00:00
|
|
|
|
|
|
|
package params
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/mohae/deepcopy"
|
|
|
|
)
|
|
|
|
|
2022-05-20 07:16:53 +00:00
|
|
|
var cfgrw sync.RWMutex
|
2021-01-04 20:48:39 +00:00
|
|
|
|
|
|
|
// BeaconConfig retrieves beacon chain config.
|
|
|
|
func BeaconConfig() *BeaconChainConfig {
|
2022-05-20 07:16:53 +00:00
|
|
|
cfgrw.RLock()
|
|
|
|
defer cfgrw.RUnlock()
|
|
|
|
return configs.getActive()
|
2021-01-04 20:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2022-05-20 07:16:53 +00:00
|
|
|
cfgrw.Lock()
|
|
|
|
defer cfgrw.Unlock()
|
|
|
|
configs.active = c
|
2021-01-04 20:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy returns a copy of the config object.
|
2021-09-24 17:42:16 +00:00
|
|
|
func (b *BeaconChainConfig) Copy() *BeaconChainConfig {
|
2022-05-20 07:16:53 +00:00
|
|
|
cfgrw.RLock()
|
|
|
|
defer cfgrw.RUnlock()
|
2021-09-24 17:42:16 +00:00
|
|
|
config, ok := deepcopy.Copy(*b).(BeaconChainConfig)
|
2021-01-04 20:48:39 +00:00
|
|
|
if !ok {
|
2022-05-20 07:16:53 +00:00
|
|
|
panic("somehow deepcopy produced a BeaconChainConfig that is not of the same type as the original")
|
2021-01-04 20:48:39 +00:00
|
|
|
}
|
|
|
|
return &config
|
|
|
|
}
|