From e0412ae06a2fb995935898f0f7c72488224966c5 Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Thu, 29 Feb 2024 11:24:00 -0400 Subject: [PATCH] refactored. --- cmd/harmony/main.go | 10 +--------- consensus/consensus.go | 5 +++++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/cmd/harmony/main.go b/cmd/harmony/main.go index 31332b2e6..7b17e7a4b 100644 --- a/cmd/harmony/main.go +++ b/cmd/harmony/main.go @@ -812,7 +812,7 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi registry = setupChain(hc, nodeConfig, registry) if registry.GetShardChainCollection() == nil { - panic("shard chain collection is nil1111111") + panic("shard chain collection is nil") } registry.SetWebHooks(nodeConfig.WebHooks.Hooks) cxPool := core.NewCxPool(core.CxPoolSize) @@ -862,14 +862,6 @@ func setupConsensusAndNode(hc harmonyconfig.HarmonyConfig, nodeConfig *nodeconfi currentNode.NodeConfig.SetClientGroupID(nodeconfig.NewClientGroupIDByShardID(shard.BeaconChainShardID)) currentNode.NodeConfig.ConsensusPriKey = nodeConfig.ConsensusPriKey - // This needs to be executed after consensus setup - if err := currentConsensus.InitConsensusWithValidators(); err != nil { - utils.Logger().Warn(). - Int("shardID", hc.General.ShardID). - Err(err). - Msg("InitConsensusWithMembers failed") - } - // Set the consensus ID to be the current block number viewID := currentNode.Blockchain().CurrentBlock().Header().ViewID().Uint64() currentConsensus.SetViewIDs(viewID + 1) diff --git a/consensus/consensus.go b/consensus/consensus.go index 20fe3f542..2bb669e3a 100644 --- a/consensus/consensus.go +++ b/consensus/consensus.go @@ -313,6 +313,11 @@ func New( initMetrics() consensus.AddPubkeyMetrics() + err := consensus.InitConsensusWithValidators() + if err != nil { + return nil, errors.WithMessage(err, "failed to init consensus with validators") + } + return &consensus, nil }