Skip to content

Commit

Permalink
golangci: add import alias linter (#1696)
Browse files Browse the repository at this point in the history
Adds imports alias linters.

category: misc
ticket: #1684
  • Loading branch information
corverroos authored Jan 27, 2023
1 parent 5997187 commit 6f843df
Show file tree
Hide file tree
Showing 20 changed files with 290 additions and 266 deletions.
24 changes: 24 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ linters-settings:
disable:
- fieldalignment
- shadow
importas:
no-unaliased: true
alias:
- pkg: github.com/attestantio/go-eth2-client/spec/phase0
alias: eth2p0
- pkg: github.com/attestantio/go-eth2-client/api/v1
alias: eth2v1
- pkg: github.com/attestantio/go-eth2-client/api
alias: eth2api
- pkg: github.com/attestantio/go-eth2-client/spec
alias: eth2spec
- pkg: github.com/attestantio/go-eth2-client/http
alias: eth2http
- pkg: github.com/attestantio/go-eth2-client/mock
alias: eth2mock
- pkg: github.com/attestantio/go-eth2-client/api/v1/bellatrix
alias: eth2bellatrix
- pkg: github.com/attestantio/go-eth2-client/api/v1/capella
alias: eth2capella
- pkg: github.com/decred/dcrd/dcrec/secp256k1/v4
alias: k1
nlreturn:
block-size: 2
revive:
Expand Down Expand Up @@ -83,6 +104,9 @@ issues:
- gosec
- noctx
- revive
- path: 'eth2wrap'
linters:
- importas
exclude:
- "error returned from interface method should be wrapped" # Relax wrapcheck
- "defer: prefer not to defer chains of function calls" # Relax revive
Expand Down
4 changes: 2 additions & 2 deletions app/simnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

eth2api "github.com/attestantio/go-eth2-client/api"
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/attestantio/go-eth2-client/spec"
eth2spec "github.com/attestantio/go-eth2-client/spec"
"github.com/coinbase/kryptology/pkg/signatures/bls/bls_sig"
k1 "github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -391,7 +391,7 @@ func newRegistrationProvider(t *testing.T, args simnetArgs) func() <-chan *eth2a
pubkey, err := core.PubKey(args.Lock.Validators[0].PublicKeyHex()).ToETH2()
require.NoError(t, err)
reg := &eth2api.VersionedValidatorRegistration{
Version: spec.BuilderVersionV1,
Version: eth2spec.BuilderVersionV1,
V1: &eth2v1.ValidatorRegistration{
FeeRecipient: testutil.RandomExecutionAddress(),
GasLimit: 99,
Expand Down
10 changes: 5 additions & 5 deletions core/bcast/bcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

eth2api "github.com/attestantio/go-eth2-client/api"
eth2capella "github.com/attestantio/go-eth2-client/api/v1/capella"
"github.com/attestantio/go-eth2-client/spec"
eth2spec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/altair"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -120,8 +120,8 @@ func beaconBlockData(t *testing.T, mock *beaconmock.Mock) test {

asserted := make(chan struct{})

block1 := spec.VersionedSignedBeaconBlock{
Version: spec.DataVersionPhase0,
block1 := eth2spec.VersionedSignedBeaconBlock{
Version: eth2spec.DataVersionPhase0,
Phase0: &eth2p0.SignedBeaconBlock{
Message: testutil.RandomPhase0BeaconBlock(),
Signature: testutil.RandomEth2Signature(),
Expand All @@ -130,7 +130,7 @@ func beaconBlockData(t *testing.T, mock *beaconmock.Mock) test {

aggData := core.VersionedSignedBeaconBlock{VersionedSignedBeaconBlock: block1}

mock.SubmitBeaconBlockFunc = func(ctx context.Context, block2 *spec.VersionedSignedBeaconBlock) error {
mock.SubmitBeaconBlockFunc = func(ctx context.Context, block2 *eth2spec.VersionedSignedBeaconBlock) error {
require.Equal(t, block1, *block2)
close(asserted)

Expand All @@ -152,7 +152,7 @@ func blindedBeaconBlockData(t *testing.T, mock *beaconmock.Mock) test {
asserted := make(chan struct{})

block1 := eth2api.VersionedSignedBlindedBeaconBlock{
Version: spec.DataVersionBellatrix,
Version: eth2spec.DataVersionBellatrix,
Capella: &eth2capella.SignedBlindedBeaconBlock{
Message: testutil.RandomCapellaBlindedBeaconBlock(),
Signature: testutil.RandomEth2Signature(),
Expand Down
12 changes: 6 additions & 6 deletions core/dutydb/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"sync"

eth2api "github.com/attestantio/go-eth2-client/api"
"github.com/attestantio/go-eth2-client/spec"
eth2spec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/altair"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"

Expand All @@ -36,7 +36,7 @@ func NewMemDB(deadliner core.Deadliner) *MemDB {
attPubKeys: make(map[pkKey]core.PubKey),
attKeysBySlot: make(map[int64][]pkKey),
builderProDuties: make(map[int64]*eth2api.VersionedBlindedBeaconBlock),
proDuties: make(map[int64]*spec.VersionedBeaconBlock),
proDuties: make(map[int64]*eth2spec.VersionedBeaconBlock),
aggDuties: make(map[aggKey]core.AggregatedAttestation),
aggKeysBySlot: make(map[int64][]aggKey),
contribDuties: make(map[contribKey]*altair.SyncCommitteeContribution),
Expand All @@ -62,7 +62,7 @@ type MemDB struct {
builderProQueries []builderProQuery

// DutyProposer
proDuties map[int64]*spec.VersionedBeaconBlock
proDuties map[int64]*eth2spec.VersionedBeaconBlock
proQueries []proQuery

// DutyAggregator
Expand Down Expand Up @@ -171,10 +171,10 @@ func (db *MemDB) Store(_ context.Context, duty core.Duty, unsignedSet core.Unsig
}

// AwaitBeaconBlock implements core.DutyDB, see its godoc.
func (db *MemDB) AwaitBeaconBlock(ctx context.Context, slot int64) (*spec.VersionedBeaconBlock, error) {
func (db *MemDB) AwaitBeaconBlock(ctx context.Context, slot int64) (*eth2spec.VersionedBeaconBlock, error) {
cancel := make(chan struct{})
defer close(cancel)
response := make(chan *spec.VersionedBeaconBlock, 1)
response := make(chan *eth2spec.VersionedBeaconBlock, 1)

db.mu.Lock()
db.proQueries = append(db.proQueries, proQuery{
Expand Down Expand Up @@ -714,7 +714,7 @@ type attQuery struct {
// proQuery is a waiting proQuery with a response channel.
type proQuery struct {
Key int64
Response chan<- *spec.VersionedBeaconBlock
Response chan<- *eth2spec.VersionedBeaconBlock
Cancel <-chan struct{}
}

Expand Down
30 changes: 15 additions & 15 deletions core/dutydb/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

eth2api "github.com/attestantio/go-eth2-client/api"
eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/attestantio/go-eth2-client/spec"
eth2spec "github.com/attestantio/go-eth2-client/spec"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -146,7 +146,7 @@ func TestMemDBProposer(t *testing.T) {
slots := [queries]int64{123, 456, 789}

type response struct {
block *spec.VersionedBeaconBlock
block *eth2spec.VersionedBeaconBlock
}
var awaitResponse [queries]chan response
for i := 0; i < queries; i++ {
Expand All @@ -158,11 +158,11 @@ func TestMemDBProposer(t *testing.T) {
}(i)
}

blocks := make([]*spec.VersionedBeaconBlock, queries)
blocks := make([]*eth2spec.VersionedBeaconBlock, queries)
pubkeysByIdx := make(map[eth2p0.ValidatorIndex]core.PubKey)
for i := 0; i < queries; i++ {
blocks[i] = &spec.VersionedBeaconBlock{
Version: spec.DataVersionPhase0,
blocks[i] = &eth2spec.VersionedBeaconBlock{
Version: eth2spec.DataVersionPhase0,
Phase0: testutil.RandomPhase0BeaconBlock(),
}
blocks[i].Phase0.Slot = eth2p0.Slot(slots[i])
Expand Down Expand Up @@ -314,13 +314,13 @@ func TestMemDBClashingBlocks(t *testing.T) {
db := dutydb.NewMemDB(new(testDeadliner))

const slot = 123
block1 := &spec.VersionedBeaconBlock{
Version: spec.DataVersionPhase0,
block1 := &eth2spec.VersionedBeaconBlock{
Version: eth2spec.DataVersionPhase0,
Phase0: testutil.RandomPhase0BeaconBlock(),
}
block1.Phase0.Slot = eth2p0.Slot(slot)
block2 := &spec.VersionedBeaconBlock{
Version: spec.DataVersionPhase0,
block2 := &eth2spec.VersionedBeaconBlock{
Version: eth2spec.DataVersionPhase0,
Phase0: testutil.RandomPhase0BeaconBlock(),
}
block2.Phase0.Slot = eth2p0.Slot(slot)
Expand Down Expand Up @@ -352,8 +352,8 @@ func TestMemDBClashProposer(t *testing.T) {

const slot = 123

block := &spec.VersionedBeaconBlock{
Version: spec.DataVersionPhase0,
block := &eth2spec.VersionedBeaconBlock{
Version: eth2spec.DataVersionPhase0,
Phase0: testutil.RandomPhase0BeaconBlock(),
}
block.Phase0.Slot = eth2p0.Slot(slot)
Expand Down Expand Up @@ -410,7 +410,7 @@ func TestMemDBBuilderProposer(t *testing.T) {
pubkeysByIdx := make(map[eth2p0.ValidatorIndex]core.PubKey)
for i := 0; i < queries; i++ {
blocks[i] = &eth2api.VersionedBlindedBeaconBlock{
Version: spec.DataVersionBellatrix,
Version: eth2spec.DataVersionBellatrix,
Bellatrix: testutil.RandomBellatrixBlindedBeaconBlock(),
}
blocks[i].Bellatrix.Slot = eth2p0.Slot(slots[i])
Expand Down Expand Up @@ -443,12 +443,12 @@ func TestMemDBClashingBlindedBlocks(t *testing.T) {

const slot = 123
block1 := &eth2api.VersionedBlindedBeaconBlock{
Version: spec.DataVersionBellatrix,
Version: eth2spec.DataVersionBellatrix,
Bellatrix: testutil.RandomBellatrixBlindedBeaconBlock(),
}
block1.Bellatrix.Slot = eth2p0.Slot(slot)
block2 := &eth2api.VersionedBlindedBeaconBlock{
Version: spec.DataVersionBellatrix,
Version: eth2spec.DataVersionBellatrix,
Bellatrix: testutil.RandomBellatrixBlindedBeaconBlock(),
}
block2.Bellatrix.Slot = eth2p0.Slot(slot)
Expand Down Expand Up @@ -481,7 +481,7 @@ func TestMemDBClashBuilderProposer(t *testing.T) {
const slot = 123

block := &eth2api.VersionedBlindedBeaconBlock{
Version: spec.DataVersionBellatrix,
Version: eth2spec.DataVersionBellatrix,
Bellatrix: testutil.RandomBellatrixBlindedBeaconBlock(),
}
block.Bellatrix.Slot = eth2p0.Slot(slot)
Expand Down
16 changes: 8 additions & 8 deletions core/fetcher/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"fmt"
"strings"

"github.com/attestantio/go-eth2-client/api"
"github.com/attestantio/go-eth2-client/spec"
eth2api "github.com/attestantio/go-eth2-client/api"
eth2spec "github.com/attestantio/go-eth2-client/spec"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"

"github.com/obolnetwork/charon/app/errors"
Expand Down Expand Up @@ -369,14 +369,14 @@ func (f *Fetcher) fetchContributionData(ctx context.Context, slot int64, defSet
}

// verifyFeeRecipient logs a warning when fee recipient is not correctly populated in the block.
func verifyFeeRecipient(ctx context.Context, block *spec.VersionedBeaconBlock, feeRecipientAddress string) {
func verifyFeeRecipient(ctx context.Context, block *eth2spec.VersionedBeaconBlock, feeRecipientAddress string) {
// Note that fee-recipient is not available in forks earlier than bellatrix.
var actualAddr string

switch block.Version {
case spec.DataVersionBellatrix:
case eth2spec.DataVersionBellatrix:
actualAddr = fmt.Sprintf("%#x", block.Bellatrix.Body.ExecutionPayload.FeeRecipient)
case spec.DataVersionCapella:
case eth2spec.DataVersionCapella:
actualAddr = fmt.Sprintf("%#x", block.Capella.Body.ExecutionPayload.FeeRecipient)
default:
return
Expand All @@ -389,14 +389,14 @@ func verifyFeeRecipient(ctx context.Context, block *spec.VersionedBeaconBlock, f
}

// verifyFeeRecipientBlindedBlock logs a warning when fee recipient is not correctly populated in the provided blinded beacon block.
func verifyFeeRecipientBlindedBlock(ctx context.Context, block *api.VersionedBlindedBeaconBlock, feeRecipientAddress string) {
func verifyFeeRecipientBlindedBlock(ctx context.Context, block *eth2api.VersionedBlindedBeaconBlock, feeRecipientAddress string) {
// Note that fee-recipient is not available in forks earlier than bellatrix.
var actualAddr string

switch block.Version {
case spec.DataVersionBellatrix:
case eth2spec.DataVersionBellatrix:
actualAddr = fmt.Sprintf("%#x", block.Bellatrix.Body.ExecutionPayloadHeader.FeeRecipient)
case spec.DataVersionCapella:
case eth2spec.DataVersionCapella:
actualAddr = fmt.Sprintf("%#x", block.Capella.Body.ExecutionPayloadHeader.FeeRecipient)
default:
return
Expand Down
14 changes: 7 additions & 7 deletions core/fetcher/fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"testing"

eth2v1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/attestantio/go-eth2-client/spec"
eth2spec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/altair"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethereum/go-ethereum/common/math"
Expand Down Expand Up @@ -528,13 +528,13 @@ func assertRandao(t *testing.T, randao eth2p0.BLSSignature, block core.Versioned
t.Helper()

switch block.Version {
case spec.DataVersionPhase0:
case eth2spec.DataVersionPhase0:
require.EqualValues(t, randao, block.Phase0.Body.RANDAOReveal)
case spec.DataVersionAltair:
case eth2spec.DataVersionAltair:
require.EqualValues(t, randao, block.Altair.Body.RANDAOReveal)
case spec.DataVersionBellatrix:
case eth2spec.DataVersionBellatrix:
require.EqualValues(t, randao, block.Bellatrix.Body.RANDAOReveal)
case spec.DataVersionCapella:
case eth2spec.DataVersionCapella:
require.EqualValues(t, randao, block.Capella.Body.RANDAOReveal)
default:
require.Fail(t, "invalid block")
Expand All @@ -545,9 +545,9 @@ func assertRandaoBlindedBlock(t *testing.T, randao eth2p0.BLSSignature, block co
t.Helper()

switch block.Version {
case spec.DataVersionBellatrix:
case eth2spec.DataVersionBellatrix:
require.EqualValues(t, randao, block.Bellatrix.Body.RANDAOReveal)
case spec.DataVersionCapella:
case eth2spec.DataVersionCapella:
require.EqualValues(t, randao, block.Capella.Body.RANDAOReveal)
default:
require.Fail(t, "invalid block")
Expand Down
10 changes: 5 additions & 5 deletions core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"context"

eth2api "github.com/attestantio/go-eth2-client/api"
"github.com/attestantio/go-eth2-client/spec"
eth2spec "github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/altair"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
)
Expand Down Expand Up @@ -59,7 +59,7 @@ type DutyDB interface {

// AwaitBeaconBlock blocks and returns the proposed beacon block
// for the slot when available.
AwaitBeaconBlock(ctx context.Context, slot int64) (*spec.VersionedBeaconBlock, error)
AwaitBeaconBlock(ctx context.Context, slot int64) (*eth2spec.VersionedBeaconBlock, error)

// AwaitBlindedBeaconBlock blocks and returns the proposed blinded beacon block
// for the slot when available.
Expand Down Expand Up @@ -95,7 +95,7 @@ type Consensus interface {
// ValidatorAPI provides a beacon node API to validator clients. It serves duty data from the DutyDB and stores partial signed data in the ParSigDB.
type ValidatorAPI interface {
// RegisterAwaitBeaconBlock registers a function to query unsigned beacon block by slot.
RegisterAwaitBeaconBlock(func(ctx context.Context, slot int64) (*spec.VersionedBeaconBlock, error))
RegisterAwaitBeaconBlock(func(ctx context.Context, slot int64) (*eth2spec.VersionedBeaconBlock, error))

// RegisterAwaitBlindedBeaconBlock registers a function to query unsigned blinded beacon block by slot.
RegisterAwaitBlindedBeaconBlock(func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedBeaconBlock, error))
Expand Down Expand Up @@ -210,15 +210,15 @@ type wireFuncs struct {
ConsensusPropose func(context.Context, Duty, UnsignedDataSet) error
ConsensusSubscribe func(func(context.Context, Duty, UnsignedDataSet) error)
DutyDBStore func(context.Context, Duty, UnsignedDataSet) error
DutyDBAwaitBeaconBlock func(ctx context.Context, slot int64) (*spec.VersionedBeaconBlock, error)
DutyDBAwaitBeaconBlock func(ctx context.Context, slot int64) (*eth2spec.VersionedBeaconBlock, error)
DutyDBAwaitBlindedBeaconBlock func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedBeaconBlock, error)
DutyDBAwaitAttestation func(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error)
DutyDBPubKeyByAttestation func(ctx context.Context, slot, commIdx, valCommIdx int64) (PubKey, error)
DutyDBAwaitAggAttestation func(ctx context.Context, slot int64, attestationRoot eth2p0.Root) (*eth2p0.Attestation, error)
DutyDBAwaitSyncContribution func(ctx context.Context, slot, subcommIdx int64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error)
VAPIRegisterAwaitAttestation func(func(ctx context.Context, slot, commIdx int64) (*eth2p0.AttestationData, error))
VAPIRegisterAwaitSyncContribution func(func(ctx context.Context, slot, subcommIdx int64, beaconBlockRoot eth2p0.Root) (*altair.SyncCommitteeContribution, error))
VAPIRegisterAwaitBeaconBlock func(func(ctx context.Context, slot int64) (*spec.VersionedBeaconBlock, error))
VAPIRegisterAwaitBeaconBlock func(func(ctx context.Context, slot int64) (*eth2spec.VersionedBeaconBlock, error))
VAPIRegisterAwaitBlindedBeaconBlock func(func(ctx context.Context, slot int64) (*eth2api.VersionedBlindedBeaconBlock, error))
VAPIRegisterGetDutyDefinition func(func(context.Context, Duty) (DutyDefinitionSet, error))
VAPIRegisterPubKeyByAttestation func(func(ctx context.Context, slot, commIdx, valCommIdx int64) (PubKey, error))
Expand Down
Loading

0 comments on commit 6f843df

Please sign in to comment.