Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polygon/heimdall: tidy client naming #12686

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ devtools:

## mocks: generate test mocks
mocks:
@cd erigon-lib && $(MAKE) mocks
rm -f $(GOBIN)/mockgen
$(GOBUILD) -o "$(GOBIN)/mockgen" go.uber.org/mock/mockgen
grep -r -l --exclude-dir="erigon-lib" --exclude-dir="tests" --exclude-dir="*$(GOBINREL)*" "^// Code generated by MockGen. DO NOT EDIT.$$" . | xargs rm -r
Expand Down
25 changes: 13 additions & 12 deletions cl/beacon/synced_data/mock_services/synced_data_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/devnet/services/polygon/heimdall.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func (h *Heimdall) Start(ctx context.Context) error {
return startHTTPServer(ctx, server, "devnet Heimdall service", h.logger)
}

func makeHeimdallRouter(ctx context.Context, client heimdall.HeimdallClient) *chi.Mux {
func makeHeimdallRouter(ctx context.Context, client heimdall.Client) *chi.Mux {
router := chi.NewRouter()

writeResponse := func(w http.ResponseWriter, result any, err error) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/devnet/services/polygon/heimdall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestHeimdallServer(t *testing.T) {

ctx := context.Background()
ctrl := gomock.NewController(t)
client := heimdall.NewMockHeimdallClient(ctrl)
client := heimdall.NewMockClient(ctrl)

events := []*heimdall.EventRecordWithTime{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type HeimdallSimulator struct {
logger log.Logger
}

var _ heimdall.HeimdallClient = (*HeimdallSimulator)(nil)
var _ heimdall.Client = (*HeimdallSimulator)(nil)

type sprintLengthCalculator struct{}

Expand Down
4 changes: 2 additions & 2 deletions cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ func overrideStorageMode(db kv.RwDB, logger log.Logger) error {
})
}

func initConsensusEngine(ctx context.Context, cc *chain2.Config, dir string, db kv.RwDB, blockReader services.FullBlockReader, logger log.Logger) (engine consensus.Engine, heimdallClient heimdall.HeimdallClient) {
func initConsensusEngine(ctx context.Context, cc *chain2.Config, dir string, db kv.RwDB, blockReader services.FullBlockReader, logger log.Logger) (engine consensus.Engine, heimdallClient heimdall.Client) {
config := ethconfig.Defaults

var consensusConfig interface{}
Expand All @@ -1551,7 +1551,7 @@ func initConsensusEngine(ctx context.Context, cc *chain2.Config, dir string, db
consensusConfig = cc.Bor
config.HeimdallURL = HeimdallURL
if !config.WithoutHeimdall {
heimdallClient = heimdall.NewHeimdallClient(config.HeimdallURL, logger)
heimdallClient = heimdall.NewHttpClient(config.HeimdallURL, logger)
}
} else {
consensusConfig = &config.Ethash
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ grpc: protoc-all
mocks:
rm -f $(GOBIN)/mockgen
$(GOBUILD) -o "$(GOBIN)/mockgen" go.uber.org/mock/mockgen
# grep -r -l --exclude-dir="*$(GOBINREL)*" "^// Code generated by MockGen. DO NOT EDIT.$$" . | xargs rm -r
grep -r -l --exclude-dir="*$(GOBINREL)*" "^// Code generated by MockGen. DO NOT EDIT.$$" . | xargs rm -r
PATH="$(GOBIN):$(PATH)" go generate -run "mockgen" ./...

lintci-deps:
Expand Down
4 changes: 2 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,15 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
consensusConfig = &config.Ethash
}

var heimdallClient heimdall.HeimdallClient
var heimdallClient heimdall.Client
var polygonBridge *bridge.Service
var heimdallService *heimdall.Service
var bridgeRPC *bridge.BackendServer
var heimdallRPC *heimdall.BackendServer

if chainConfig.Bor != nil {
if !config.WithoutHeimdall {
heimdallClient = heimdall.NewHeimdallClient(config.HeimdallURL, logger)
heimdallClient = heimdall.NewHttpClient(config.HeimdallURL, logger)
}

if config.PolygonSync {
Expand Down
2 changes: 1 addition & 1 deletion eth/ethconsensusconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
)

func CreateConsensusEngine(ctx context.Context, nodeConfig *nodecfg.Config, chainConfig *chain.Config, config interface{}, notify []string, noVerify bool,
heimdallClient heimdall.HeimdallClient, withoutHeimdall bool, blockReader services.FullBlockReader, readonly bool,
heimdallClient heimdall.Client, withoutHeimdall bool, blockReader services.FullBlockReader, readonly bool,
logger log.Logger, polygonBridge *bridge.Service, heimdallService *heimdall.Service,
) consensus.Engine {
var eng consensus.Engine
Expand Down
12 changes: 6 additions & 6 deletions eth/stagedsync/bor_heimdall_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func FetchSpanZeroForMiningIfNeeded(
ctx context.Context,
db kv.RwDB,
blockReader services.FullBlockReader,
heimdallClient heimdall.HeimdallClient,
heimdallClient heimdall.Client,
heimdallStore heimdall.Store,
logger log.Logger,
) error {
Expand Down Expand Up @@ -106,7 +106,7 @@ func fetchAndWriteHeimdallSpan(
ctx context.Context,
spanID uint64,
tx kv.RwTx,
heimdallClient heimdall.HeimdallClient,
heimdallClient heimdall.Client,
heimdallStore heimdall.Store,
logPrefix string,
logger log.Logger,
Expand Down Expand Up @@ -201,7 +201,7 @@ func fetchAndWriteHeimdallCheckpoint(
ctx context.Context,
checkpointId uint64,
tx kv.RwTx,
heimdallClient heimdall.HeimdallClient,
heimdallClient heimdall.Client,
heimdallStore heimdall.Store,
logPrefix string,
logger log.Logger,
Expand Down Expand Up @@ -305,7 +305,7 @@ func fetchAndWriteHeimdallMilestone(
ctx context.Context,
milestoneId uint64,
tx kv.RwTx,
heimdallClient heimdall.HeimdallClient,
heimdallClient heimdall.Client,
heimdallStore heimdall.Store,
logPrefix string,
logger log.Logger,
Expand All @@ -332,7 +332,7 @@ func fetchRequiredHeimdallStateSyncEventsIfNeeded(
tx kv.RwTx,
borConfig *borcfg.BorConfig,
blockReader services.FullBlockReader,
heimdallClient heimdall.HeimdallClient,
heimdallClient heimdall.Client,
bridgeStore bridge.Store,
chainID string,
logPrefix string,
Expand Down Expand Up @@ -371,7 +371,7 @@ func fetchAndWriteHeimdallStateSyncEvents(
tx kv.RwTx,
config *borcfg.BorConfig,
blockReader services.FullBlockReader,
heimdallClient heimdall.HeimdallClient,
heimdallClient heimdall.Client,
bridgeStore bridge.Store,
chainID string,
logPrefix string,
Expand Down
6 changes: 3 additions & 3 deletions eth/stagedsync/stage_bor_heimdall.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type BorHeimdallCfg struct {
miningState *MiningState
chainConfig *chain.Config
borConfig *borcfg.BorConfig
heimdallClient heimdall.HeimdallClient
heimdallClient heimdall.Client
heimdallStore heimdall.Store
bridgeStore bridge.Store
blockReader services.FullBlockReader
Expand All @@ -79,7 +79,7 @@ func StageBorHeimdallCfg(
snapDb kv.RwDB,
miningState MiningState,
chainConfig chain.Config,
heimdallClient heimdall.HeimdallClient,
heimdallClient heimdall.Client,
heimdallStore heimdall.Store,
bridgeStore bridge.Store,
blockReader services.FullBlockReader,
Expand Down Expand Up @@ -651,7 +651,7 @@ func initValidatorSets(
tx kv.RwTx,
blockReader services.FullBlockReader,
config *borcfg.BorConfig,
heimdallClient heimdall.HeimdallClient,
heimdallClient heimdall.Client,
heimdallStore heimdall.Store,
chain consensus.ChainHeaderReader,
blockNum uint64,
Expand Down
2 changes: 1 addition & 1 deletion eth/stagedsync/stage_polygon_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func NewPolygonSyncStageCfg(
logger log.Logger,
chainConfig *chain.Config,
db kv.RwDB,
heimdallClient heimdall.HeimdallClient,
heimdallClient heimdall.Client,
heimdallStore heimdall.Store,
bridgeStore bridge.Store,
sentry sentryproto.SentryClient,
Expand Down
7 changes: 4 additions & 3 deletions eth/stagedsync/stagedsynctest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import (
"testing"
"time"

"github.com/erigontech/erigon-lib/kv/order"
"github.com/holiman/uint256"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

"github.com/erigontech/erigon-lib/kv/order"

"github.com/erigontech/erigon-lib/chain"
libcommon "github.com/erigontech/erigon-lib/common"
"github.com/erigontech/erigon-lib/crypto"
Expand Down Expand Up @@ -64,7 +65,7 @@ func InitHarness(ctx context.Context, t *testing.T, cfg HarnessCfg) Harness {
blockReader := m.BlockReader
borConsensusDB := memdb.NewTestDB(t)
ctrl := gomock.NewController(t)
heimdallClient := heimdall.NewMockHeimdallClient(ctrl)
heimdallClient := heimdall.NewMockClient(ctrl)
miningState := stagedsync.NewMiningState(&ethconfig.Defaults.Miner)
bridgeStore := bridge.NewDbStore(m.DB)
heimdallStore := heimdall.NewDbStore(m.DB)
Expand Down Expand Up @@ -180,7 +181,7 @@ type Harness struct {
miningSync *stagedsync.Sync
miningState stagedsync.MiningState
bhCfg stagedsync.BorHeimdallCfg
heimdallClient *heimdall.MockHeimdallClient
heimdallClient *heimdall.MockClient
heimdallNextMockSpan *heimdall.Span
heimdallLastEventID uint64
heimdallLastEventHeaderNum uint64
Expand Down
6 changes: 3 additions & 3 deletions polygon/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ type Bor struct {

spanner Spanner
stateReceiver StateReceiver
HeimdallClient heimdall.HeimdallClient
HeimdallClient heimdall.Client
useSpanReader bool
spanReader spanReader
useBridgeReader bool
Expand Down Expand Up @@ -354,7 +354,7 @@ func New(
db kv.RwDB,
blockReader services.FullBlockReader,
spanner Spanner,
heimdallClient heimdall.HeimdallClient,
heimdallClient heimdall.Client,
genesisContracts StateReceiver,
logger log.Logger,
bridgeReader bridgeReader,
Expand Down Expand Up @@ -1608,7 +1608,7 @@ func (c *Bor) CommitStates(
return nil
}

func (c *Bor) SetHeimdallClient(h heimdall.HeimdallClient) {
func (c *Bor) SetHeimdallClient(h heimdall.Client) {
c.HeimdallClient = h
}

Expand Down
16 changes: 16 additions & 0 deletions polygon/bor/bor_internal_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// Copyright 2024 The Erigon Authors
// This file is part of Erigon.
//
// Erigon is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Erigon is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Erigon. If not, see <http://www.gnu.org/licenses/>.

package bor

import (
Expand Down
14 changes: 7 additions & 7 deletions polygon/bor/finality/whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
)

type config struct {
heimdall heimdall.HeimdallClient
heimdall heimdall.Client
borDB kv.RwDB
chainDB kv.RwDB
blockReader services.BlockReader
Expand All @@ -45,7 +45,7 @@ type BorAPI interface {
GetRootHash(start uint64, end uint64) (string, error)
}

func Whitelist(heimdall heimdall.HeimdallClient, borDB kv.RwDB, chainDB kv.RwDB, blockReader services.BlockReader, logger log.Logger, borAPI BorAPI, closeCh chan struct{}) {
func Whitelist(heimdall heimdall.Client, borDB kv.RwDB, chainDB kv.RwDB, blockReader services.BlockReader, logger log.Logger, borAPI BorAPI, closeCh chan struct{}) {
if !flags.Milestone {
return
}
Expand Down Expand Up @@ -111,7 +111,7 @@ func startNoAckMilestoneByIDService(config *config) {
RetryHeimdallHandler(handleNoAckMilestoneByID, config, tickerDuration, noAckMilestoneTimeout, fnName)
}

type heimdallHandler func(ctx context.Context, heimdallClient heimdall.HeimdallClient, config *config) error
type heimdallHandler func(ctx context.Context, heimdallClient heimdall.Client, config *config) error

func RetryHeimdallHandler(fn heimdallHandler, config *config, tickerDuration time.Duration, timeout time.Duration, fnName string) {
retryHeimdallHandler(fn, config, tickerDuration, timeout, fnName)
Expand Down Expand Up @@ -174,7 +174,7 @@ func retryHeimdallHandler(fn heimdallHandler, config *config, tickerDuration tim
}

// handleWhitelistCheckpoint handles the checkpoint whitelist mechanism.
func handleWhitelistCheckpoint(ctx context.Context, heimdallClient heimdall.HeimdallClient, config *config) error {
func handleWhitelistCheckpoint(ctx context.Context, heimdallClient heimdall.Client, config *config) error {
service := whitelist.GetWhitelistingService()

// Create a new bor verifier, which will be used to verify checkpoints and milestones
Expand All @@ -194,7 +194,7 @@ func handleWhitelistCheckpoint(ctx context.Context, heimdallClient heimdall.Heim
}

// handleMilestone handles the milestone mechanism.
func handleMilestone(ctx context.Context, heimdallClient heimdall.HeimdallClient, config *config) error {
func handleMilestone(ctx context.Context, heimdallClient heimdall.Client, config *config) error {
service := whitelist.GetWhitelistingService()

// Create a new bor verifier, which will be used to verify checkpoints and milestones
Expand Down Expand Up @@ -222,7 +222,7 @@ func handleMilestone(ctx context.Context, heimdallClient heimdall.HeimdallClient
return nil
}

func handleNoAckMilestone(ctx context.Context, heimdallClient heimdall.HeimdallClient, config *config) error {
func handleNoAckMilestone(ctx context.Context, heimdallClient heimdall.Client, config *config) error {
service := whitelist.GetWhitelistingService()
milestoneID, err := fetchNoAckMilestone(ctx, heimdallClient, config.logger)

Expand All @@ -239,7 +239,7 @@ func handleNoAckMilestone(ctx context.Context, heimdallClient heimdall.HeimdallC
return nil
}

func handleNoAckMilestoneByID(ctx context.Context, heimdallClient heimdall.HeimdallClient, config *config) error {
func handleNoAckMilestoneByID(ctx context.Context, heimdallClient heimdall.Client, config *config) error {
service := whitelist.GetWhitelistingService()
milestoneIDs := service.GetMilestoneIDsList()

Expand Down
Loading
Loading