Ensure nodeconfig.shardConfigs is initialized

Previously, only nodeconfig.GetShardConfig initialized this; calling
SetNetworkType before GetShardConfig resulted in GetShardConfig calls to
return empty network type.
pull/1939/head
Eugene Kim 5 years ago
parent d8650cbf1e
commit 22f0c4eac3
  1. 9
      internal/configs/node/config.go

@ -98,14 +98,18 @@ var shardConfigs []ConfigType
var defaultConfig ConfigType var defaultConfig ConfigType
var onceForConfigs sync.Once var onceForConfigs sync.Once
// GetShardConfig return the shard's ConfigType variable func ensureShardConfigs() {
func GetShardConfig(shardID uint32) *ConfigType {
onceForConfigs.Do(func() { onceForConfigs.Do(func() {
shardConfigs = make([]ConfigType, MaxShards) shardConfigs = make([]ConfigType, MaxShards)
for i := range shardConfigs { for i := range shardConfigs {
shardConfigs[i].ShardID = uint32(i) shardConfigs[i].ShardID = uint32(i)
} }
}) })
}
// GetShardConfig return the shard's ConfigType variable
func GetShardConfig(shardID uint32) *ConfigType {
ensureShardConfigs()
if int(shardID) >= cap(shardConfigs) { if int(shardID) >= cap(shardConfigs) {
return nil return nil
} }
@ -213,6 +217,7 @@ func (conf *ConfigType) Role() Role {
// SetNetworkType set the networkType // SetNetworkType set the networkType
func SetNetworkType(networkType NetworkType) { func SetNetworkType(networkType NetworkType) {
ensureShardConfigs()
defaultConfig.networkType = networkType defaultConfig.networkType = networkType
for i := range shardConfigs { for i := range shardConfigs {
shardConfigs[i].networkType = networkType shardConfigs[i].networkType = networkType

Loading…
Cancel
Save