From 22f0c4eac32f5a2c8fd0165239310c2568f61dcb Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Mon, 2 Dec 2019 15:39:27 -0800 Subject: [PATCH] Ensure nodeconfig.shardConfigs is initialized Previously, only nodeconfig.GetShardConfig initialized this; calling SetNetworkType before GetShardConfig resulted in GetShardConfig calls to return empty network type. --- internal/configs/node/config.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/configs/node/config.go b/internal/configs/node/config.go index db38b505d..695e592c9 100644 --- a/internal/configs/node/config.go +++ b/internal/configs/node/config.go @@ -98,14 +98,18 @@ var shardConfigs []ConfigType var defaultConfig ConfigType var onceForConfigs sync.Once -// GetShardConfig return the shard's ConfigType variable -func GetShardConfig(shardID uint32) *ConfigType { +func ensureShardConfigs() { onceForConfigs.Do(func() { shardConfigs = make([]ConfigType, MaxShards) for i := range shardConfigs { shardConfigs[i].ShardID = uint32(i) } }) +} + +// GetShardConfig return the shard's ConfigType variable +func GetShardConfig(shardID uint32) *ConfigType { + ensureShardConfigs() if int(shardID) >= cap(shardConfigs) { return nil } @@ -213,6 +217,7 @@ func (conf *ConfigType) Role() Role { // SetNetworkType set the networkType func SetNetworkType(networkType NetworkType) { + ensureShardConfigs() defaultConfig.networkType = networkType for i := range shardConfigs { shardConfigs[i].networkType = networkType