Skip to content

Commit

Permalink
golangci: add import duplication flag (cosmos#1093)
Browse files Browse the repository at this point in the history
<!--
Please read and fill out this form before submitting your PR.

Please make sure you have reviewed our contributors guide before
submitting your
first PR.
-->

## Overview
Duplicate imports when given custom names were not being caught by the
linter. This PR adds the needed flag and fixes some errors.

<!-- 
Please provide an explanation of the PR, including the appropriate
context,
background, goal, and rationale. If there is an issue with this
information,
please provide a tl;dr and link the issue. 
-->

## Checklist

<!-- 
Please complete the checklist to ensure that the PR is ready to be
reviewed.

IMPORTANT:
PRs should be left in Draft until the below checklist is completed.
-->

- [ ] New and updated code has appropriate documentation
- [ ] New and updated code has new and/or updated testing
- [ ] Required CI checks are passing
- [ ] Visual proof for any user facing features like CLI or
documentation updates
- [ ] Linked issues closed with keywords
  • Loading branch information
MSevey authored Jul 24, 2023
1 parent dc0516d commit c9a21e5
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ linters-settings:
rules:
- name: package-comments
disabled: true
- name: duplicated-imports
severity: warning

goimports:
local-prefixes: github.com/rollkit
6 changes: 3 additions & 3 deletions node/block_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
goheaderstore "github.com/celestiaorg/go-header/store"
goheadersync "github.com/celestiaorg/go-header/sync"
"github.com/cometbft/cometbft/libs/log"
tmtypes "github.com/cometbft/cometbft/types"
cmtypes "github.com/cometbft/cometbft/types"
ds "github.com/ipfs/go-datastore"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/host"
Expand All @@ -29,7 +29,7 @@ import (
// Uses the go-header library for handling all P2P logic.
type BlockExchangeService struct {
conf config.NodeConfig
genesis *tmtypes.GenesisDoc
genesis *cmtypes.GenesisDoc
p2p *p2p.Client
ex *goheaderp2p.Exchange[*types.Block]
sub *goheaderp2p.Subscriber[*types.Block]
Expand All @@ -43,7 +43,7 @@ type BlockExchangeService struct {
ctx context.Context
}

func NewBlockExchangeService(ctx context.Context, store ds.TxnDatastore, conf config.NodeConfig, genesis *tmtypes.GenesisDoc, p2p *p2p.Client, logger log.Logger) (*BlockExchangeService, error) {
func NewBlockExchangeService(ctx context.Context, store ds.TxnDatastore, conf config.NodeConfig, genesis *cmtypes.GenesisDoc, p2p *p2p.Client, logger log.Logger) (*BlockExchangeService, error) {
if genesis == nil {
return nil, errors.New("genesis doc cannot be nil")
}
Expand Down
3 changes: 1 addition & 2 deletions node/full_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/config"
bytes "github.com/cometbft/cometbft/libs/bytes"
cmbytes "github.com/cometbft/cometbft/libs/bytes"
cmmath "github.com/cometbft/cometbft/libs/math"
cmpubsub "github.com/cometbft/cometbft/libs/pubsub"
Expand Down Expand Up @@ -802,7 +801,7 @@ func (c *FullClient) Header(ctx context.Context, height *int64) (*ctypes.ResultH
return &ctypes.ResultHeader{Header: &blockMeta.Header}, nil
}

func (c *FullClient) HeaderByHash(ctx context.Context, hash bytes.HexBytes) (*ctypes.ResultHeader, error) {
func (c *FullClient) HeaderByHash(ctx context.Context, hash cmbytes.HexBytes) (*ctypes.ResultHeader, error) {
// N.B. The hash parameter is HexBytes so that the reflective parameter
// decoding logic in the HTTP service will correctly translate from JSON.
// See https://github.com/cometbft/cometbft/issues/6802 for context.
Expand Down
3 changes: 1 addition & 2 deletions node/header_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
goheadersync "github.com/celestiaorg/go-header/sync"
"github.com/cometbft/cometbft/libs/log"
cmtypes "github.com/cometbft/cometbft/types"
tmtypes "github.com/cometbft/cometbft/types"
ds "github.com/ipfs/go-datastore"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/host"
Expand Down Expand Up @@ -44,7 +43,7 @@ type HeaderExchangeService struct {
ctx context.Context
}

func NewHeaderExchangeService(ctx context.Context, store ds.TxnDatastore, conf config.NodeConfig, genesis *tmtypes.GenesisDoc, p2p *p2p.Client, logger log.Logger) (*HeaderExchangeService, error) {
func NewHeaderExchangeService(ctx context.Context, store ds.TxnDatastore, conf config.NodeConfig, genesis *cmtypes.GenesisDoc, p2p *p2p.Client, logger log.Logger) (*HeaderExchangeService, error) {
if genesis == nil {
return nil, errors.New("genesis doc cannot be nil")
}
Expand Down
9 changes: 4 additions & 5 deletions node/light_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package node
import (
"context"

bytes "github.com/cometbft/cometbft/libs/bytes"
cmtypes "github.com/cometbft/cometbft/libs/bytes"
cmbytes "github.com/cometbft/cometbft/libs/bytes"
rpcclient "github.com/cometbft/cometbft/rpc/client"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cometbft/cometbft/types"
Expand All @@ -29,12 +28,12 @@ func (c *LightClient) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, err
}

// ABCIQuery queries for data from application.
func (c *LightClient) ABCIQuery(ctx context.Context, path string, data cmtypes.HexBytes) (*ctypes.ResultABCIQuery, error) {
func (c *LightClient) ABCIQuery(ctx context.Context, path string, data cmbytes.HexBytes) (*ctypes.ResultABCIQuery, error) {
panic("Not implemented")
}

// ABCIQueryWithOptions queries for data from application.
func (c *LightClient) ABCIQueryWithOptions(ctx context.Context, path string, data cmtypes.HexBytes, opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
func (c *LightClient) ABCIQueryWithOptions(ctx context.Context, path string, data cmbytes.HexBytes, opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
panic("Not implemented")
}

Expand Down Expand Up @@ -184,6 +183,6 @@ func (c *LightClient) Header(ctx context.Context, height *int64) (*ctypes.Result
panic("Not implemented")
}

func (c *LightClient) HeaderByHash(ctx context.Context, hash bytes.HexBytes) (*ctypes.ResultHeader, error) {
func (c *LightClient) HeaderByHash(ctx context.Context, hash cmbytes.HexBytes) (*ctypes.ResultHeader, error) {
panic("Not implemented")
}
6 changes: 3 additions & 3 deletions node/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
testutils "github.com/celestiaorg/utils/test"
"github.com/cometbft/cometbft/crypto/ed25519"
"github.com/cometbft/cometbft/p2p"
tmtypes "github.com/cometbft/cometbft/types"
cmtypes "github.com/cometbft/cometbft/types"
"github.com/libp2p/go-libp2p/core/crypto"

"github.com/rollkit/rollkit/conv"
Expand Down Expand Up @@ -93,14 +93,14 @@ func waitForAtLeastNBlocks(node Node, n int, useBlockExchange bool) error {
}

// TODO: use n and return n validators
func getGenesisValidatorSetWithSigner(n int) ([]tmtypes.GenesisValidator, crypto.PrivKey) {
func getGenesisValidatorSetWithSigner(n int) ([]cmtypes.GenesisValidator, crypto.PrivKey) {
nodeKey := &p2p.NodeKey{
PrivKey: genesisValidatorKey,
}
signingKey, _ := conv.GetNodeKey(nodeKey)
pubKey := genesisValidatorKey.PubKey()

genesisValidators := []tmtypes.GenesisValidator{
genesisValidators := []cmtypes.GenesisValidator{
{Address: pubKey.Address(), PubKey: pubKey, Power: int64(100), Name: "gen #1"},
}
return genesisValidators, signingKey
Expand Down
6 changes: 3 additions & 3 deletions rpc/json/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/cometbft/cometbft/p2p"
"github.com/cometbft/cometbft/proxy"
rpcclient "github.com/cometbft/cometbft/rpc/client"
tmtypes "github.com/cometbft/cometbft/types"
cmtypes "github.com/cometbft/cometbft/types"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -53,10 +53,10 @@ func getRPC(t *testing.T) (*mocks.Application, rpcclient.Client) {
signingKey, _ := conv.GetNodeKey(nodeKey)
pubKey := validatorKey.PubKey()

genesisValidators := []tmtypes.GenesisValidator{
genesisValidators := []cmtypes.GenesisValidator{
{Address: pubKey.Address(), PubKey: pubKey, Power: int64(100), Name: "gen #1"},
}
n, err := node.NewNode(context.Background(), config.NodeConfig{Aggregator: true, DALayer: "mock", BlockManagerConfig: config.BlockManagerConfig{BlockTime: 1 * time.Second}, Light: false}, key, signingKey, proxy.NewLocalClientCreator(app), &tmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
n, err := node.NewNode(context.Background(), config.NodeConfig{Aggregator: true, DALayer: "mock", BlockManagerConfig: config.BlockManagerConfig{BlockTime: 1 * time.Second}, Light: false}, key, signingKey, proxy.NewLocalClientCreator(app), &cmtypes.GenesisDoc{ChainID: "test", Validators: genesisValidators}, log.TestingLogger())
require.NoError(err)
require.NotNil(n)

Expand Down
12 changes: 6 additions & 6 deletions types/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import (
"time"

"github.com/cometbft/cometbft/crypto/ed25519"
tmtypes "github.com/cometbft/cometbft/types"
cmtypes "github.com/cometbft/cometbft/types"
)

// TODO: accept argument for number of validators / proposer index
func GetRandomValidatorSet() *tmtypes.ValidatorSet {
func GetRandomValidatorSet() *cmtypes.ValidatorSet {
valSet, _ := GetRandomValidatorSetWithPrivKey()
return valSet
}

func GetRandomValidatorSetWithPrivKey() (*tmtypes.ValidatorSet, ed25519.PrivKey) {
func GetRandomValidatorSetWithPrivKey() (*cmtypes.ValidatorSet, ed25519.PrivKey) {
privKey := ed25519.GenPrivKey()
pubKey := privKey.PubKey()
return &tmtypes.ValidatorSet{
Proposer: &tmtypes.Validator{PubKey: pubKey, Address: pubKey.Address()},
Validators: []*tmtypes.Validator{
return &cmtypes.ValidatorSet{
Proposer: &cmtypes.Validator{PubKey: pubKey, Address: pubKey.Address()},
Validators: []*cmtypes.Validator{
{PubKey: pubKey, Address: pubKey.Address()},
},
}, privKey
Expand Down

0 comments on commit c9a21e5

Please sign in to comment.