From f54e688a6f9345061a1fb1c32cb4ee4f3d9a8097 Mon Sep 17 00:00:00 2001 From: aBear Date: Sat, 28 Sep 2024 19:05:38 +0200 Subject: [PATCH] nit --- mod/consensus/pkg/cometbft/service/abci.go | 48 +++++++++++----------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/mod/consensus/pkg/cometbft/service/abci.go b/mod/consensus/pkg/cometbft/service/abci.go index dee19f5779..c08e329382 100644 --- a/mod/consensus/pkg/cometbft/service/abci.go +++ b/mod/consensus/pkg/cometbft/service/abci.go @@ -44,7 +44,6 @@ import ( var errInvalidHeight = errors.New("invalid height") -//nolint:gocognit // todo fix. func (s *Service[LoggerT]) InitChain( _ context.Context, req *cmtabci.InitChainRequest, @@ -111,35 +110,34 @@ func (s *Service[LoggerT]) InitChain( if len(resValidators) == 0 { return nil, errors.New( - "application init chain handler returned a no validators", + "application init chain handler returned no validators", ) } - if len(req.Validators) > 0 { - if len(req.Validators) != len(resValidators) { - return nil, fmt.Errorf( - "len(RequestInitChain.Validators) != len(GenesisValidators) (%d != %d)", - len(req.Validators), - len(resValidators), - ) + // check validators + if len(req.Validators) != len(resValidators) { + return nil, fmt.Errorf( + "len(RequestInitChain.Validators) != len(GenesisValidators) (%d != %d)", + len(req.Validators), + len(resValidators), + ) + } + + sort.Sort(cmtabci.ValidatorUpdates(req.Validators)) + + for i := range resValidators { + if req.Validators[i].Power != resValidators[i].Power { + return nil, errors.New("mismatched power") + } + if !bytes.Equal( + req.Validators[i].PubKeyBytes, resValidators[i]. + PubKeyBytes) { + return nil, errors.New("mismatched pubkey bytes") } - sort.Sort(cmtabci.ValidatorUpdates(req.Validators)) - - for i := range resValidators { - if req.Validators[i].Power != resValidators[i].Power { - return nil, errors.New("mismatched power") - } - if !bytes.Equal( - req.Validators[i].PubKeyBytes, resValidators[i]. - PubKeyBytes) { - return nil, errors.New("mismatched pubkey bytes") - } - - if req.Validators[i].PubKeyType != - resValidators[i].PubKeyType { - return nil, errors.New("mismatched pubkey types") - } + if req.Validators[i].PubKeyType != + resValidators[i].PubKeyType { + return nil, errors.New("mismatched pubkey types") } }