-
Notifications
You must be signed in to change notification settings - Fork 1.4k
integration: use polygon services in initConsensusEngine (#16946) #16951
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,7 @@ import ( | |
| "github.com/erigontech/erigon/db/state/statecfg" | ||
| "github.com/erigontech/erigon/db/state/stats" | ||
| "github.com/erigontech/erigon/db/wrap" | ||
| "github.com/erigontech/erigon/eth" | ||
| "github.com/erigontech/erigon/eth/ethconfig" | ||
| "github.com/erigontech/erigon/eth/ethconfig/features" | ||
| "github.com/erigontech/erigon/eth/ethconsensusconfig" | ||
|
|
@@ -79,8 +80,10 @@ import ( | |
| "github.com/erigontech/erigon/p2p/sentry" | ||
| "github.com/erigontech/erigon/p2p/sentry/sentry_multi_client" | ||
| "github.com/erigontech/erigon/polygon/bor" | ||
| "github.com/erigontech/erigon/polygon/bor/borcfg" | ||
| "github.com/erigontech/erigon/polygon/bridge" | ||
| "github.com/erigontech/erigon/polygon/heimdall" | ||
| "github.com/erigontech/erigon/polygon/heimdall/poshttp" | ||
| "github.com/erigontech/erigon/turbo/app" | ||
| "github.com/erigontech/erigon/turbo/debug" | ||
| "github.com/erigontech/erigon/turbo/logging" | ||
|
|
@@ -1355,14 +1358,15 @@ func newSync(ctx context.Context, db kv.TemporalRwDB, miningConfig *buildercfg.M | |
| cfg.Miner = *miningConfig | ||
| } | ||
| cfg.Dirs = dirs | ||
| allSn, borSn, agg, _, _, _, err := allSnapshots(ctx, db, logger) | ||
| dbReadConcurrency := runtime.GOMAXPROCS(-1) * 16 | ||
| blockSnapBuildSema := semaphore.NewWeighted(int64(dbg.BuildSnapshotAllowance)) | ||
| blockReader, blockWriter, allSn, borSn, bridgeStore, heimdallStore, _, err := eth.SetUpBlockReader(ctx, db, dirs, &cfg, chainConfig, dbReadConcurrency, logger, blockSnapBuildSema) | ||
| if err != nil { | ||
| panic(err) // we do already panic above on genesis error | ||
| panic(err) | ||
| } | ||
| cfg.Snapshot = allSn.Cfg() | ||
|
|
||
| blockReader, blockWriter := blocksIO(db, logger) | ||
| engine := initConsensusEngine(ctx, chainConfig, cfg.Dirs.DataDir, db, blockReader, logger) | ||
| borSn.DownloadComplete() // mark as ready | ||
| engine := initConsensusEngine(ctx, chainConfig, cfg.Dirs.DataDir, db, blockReader, bridgeStore, heimdallStore, logger) | ||
|
|
||
| statusDataProvider := sentry.NewStatusDataProvider( | ||
| db, | ||
|
|
@@ -1393,22 +1397,13 @@ func newSync(ctx context.Context, db kv.TemporalRwDB, miningConfig *buildercfg.M | |
| panic(err) | ||
| } | ||
|
|
||
| blockSnapBuildSema := semaphore.NewWeighted(int64(dbg.BuildSnapshotAllowance)) | ||
| agg.SetSnapshotBuildSema(blockSnapBuildSema) | ||
antonis19 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| notifications := shards.NewNotifications(nil) | ||
|
|
||
| var ( | ||
| signatures *lru.ARCCache[common.Hash, common.Address] | ||
| bridgeStore bridge.Store | ||
| heimdallStore heimdall.Store | ||
| ) | ||
| var signatures *lru.ARCCache[common.Hash, common.Address] | ||
|
|
||
| if bor, ok := engine.(*bor.Bor); ok { | ||
| signatures = bor.Signatures | ||
| bridgeStore = bridge.NewSnapshotStore(bridge.NewDbStore(db), borSn, chainConfig.Bor) | ||
| heimdallStore = heimdall.NewSnapshotStore(heimdall.NewDbStore(db), borSn) | ||
| } | ||
| borSn.DownloadComplete() // mark as ready | ||
| blockRetire := freezeblocks.NewBlockRetire(estimate.CompressSnapshot.Workers(), dirs, blockReader, blockWriter, db, heimdallStore, bridgeStore, chainConfig, &cfg, notifications.Events, blockSnapBuildSema, logger) | ||
|
|
||
| stageList := stages2.NewDefaultStages(context.Background(), db, p2p.Config{}, &cfg, sentryControlServer, notifications, nil, blockReader, blockRetire, nil, nil, | ||
|
|
@@ -1473,9 +1468,12 @@ func stage(st *stagedsync.Sync, tx kv.Tx, db kv.RoDB, stage stages.SyncStage) *s | |
| return res | ||
| } | ||
|
|
||
| func initConsensusEngine(ctx context.Context, cc *chain2.Config, dir string, db kv.RwDB, blockReader services.FullBlockReader, logger log.Logger) (engine consensus.Engine) { | ||
| func initConsensusEngine(ctx context.Context, cc *chain2.Config, dir string, db kv.RwDB, blockReader services.FullBlockReader, bridgeStore bridge.Store, heimdallStore heimdall.Store, logger log.Logger) consensus.Engine { | ||
| config := ethconfig.Defaults | ||
|
|
||
| var polygonBridge *bridge.Service | ||
| var heimdallService *heimdall.Service | ||
| var heimdallClient heimdall.Client | ||
| var bridgeClient bridge.Client | ||
| var consensusConfig interface{} | ||
| if cc.Clique != nil { | ||
| consensusConfig = chainspec.CliqueSnapshot | ||
|
|
@@ -1484,11 +1482,42 @@ func initConsensusEngine(ctx context.Context, cc *chain2.Config, dir string, db | |
| } else if cc.Bor != nil { | ||
| consensusConfig = cc.Bor | ||
| config.HeimdallURL = HeimdallURL | ||
| if !config.WithoutHeimdall { | ||
| heimdallClient = heimdall.NewHttpClient(config.HeimdallURL, logger, poshttp.WithApiVersioner(ctx)) | ||
| bridgeClient = bridge.NewHttpClient(config.HeimdallURL, logger, poshttp.WithApiVersioner(ctx)) | ||
| } else { | ||
| heimdallClient = heimdall.NewIdleClient(config.Miner) | ||
| bridgeClient = bridge.NewIdleClient() | ||
| } | ||
|
Comment on lines
+1485
to
+1491
|
||
| borConfig := consensusConfig.(*borcfg.BorConfig) | ||
|
|
||
| polygonBridge = bridge.NewService(bridge.ServiceConfig{ | ||
| Store: bridgeStore, | ||
| Logger: logger, | ||
| BorConfig: borConfig, | ||
| EventFetcher: bridgeClient, | ||
| }) | ||
|
|
||
| if err := heimdallStore.Prepare(ctx); err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| if err := bridgeStore.Prepare(ctx); err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| heimdallService = heimdall.NewService(heimdall.ServiceConfig{ | ||
| Store: heimdallStore, | ||
| BorConfig: borConfig, | ||
| Client: heimdallClient, | ||
| Logger: logger, | ||
| }) | ||
|
|
||
| } else { | ||
| consensusConfig = &config.Ethash | ||
| } | ||
| return ethconsensusconfig.CreateConsensusEngine(ctx, &nodecfg.Config{Dirs: datadir.New(dir)}, cc, consensusConfig, config.Miner.Notify, config.Miner.Noverify, | ||
| config.WithoutHeimdall, blockReader, db.ReadOnly(), logger, nil, nil) | ||
| config.WithoutHeimdall, blockReader, db.ReadOnly(), logger, polygonBridge, heimdallService) | ||
| } | ||
|
|
||
| func readGenesis(chain string) *types.Genesis { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 16 should be defined as a named constant to explain its purpose and make it easier to maintain.