Skip to content

Commit 3985343

Browse files
authored
added --experimental.modular (erigontech#7925)
1 parent 9d3551f commit 3985343

File tree

6 files changed

+797
-30
lines changed

6 files changed

+797
-30
lines changed

eth/backend.go

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"github.com/ledgerwatch/erigon/turbo/engineapi"
4444
"github.com/ledgerwatch/erigon/turbo/engineapi/engine_helpers"
4545
"github.com/ledgerwatch/erigon/turbo/jsonrpc"
46+
"github.com/ledgerwatch/erigon/turbo/rpchelper"
4647
"github.com/ledgerwatch/erigon/turbo/snapshotsync/freezeblocks"
4748
"github.com/ledgerwatch/erigon/turbo/snapshotsync/snap"
4849

@@ -74,11 +75,13 @@ import (
7475
"github.com/ledgerwatch/erigon-lib/txpool/txpooluitl"
7576
types2 "github.com/ledgerwatch/erigon-lib/types"
7677

78+
txpool2 "github.com/ledgerwatch/erigon-lib/gointerfaces/txpool"
7779
"github.com/ledgerwatch/erigon/cl/clparams"
7880
"github.com/ledgerwatch/erigon/cl/cltypes"
7981
"github.com/ledgerwatch/erigon/cl/fork"
8082
"github.com/ledgerwatch/erigon/cmd/caplin-phase1/caplin1"
8183
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli"
84+
"github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli/httpcfg"
8285
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel"
8386
"github.com/ledgerwatch/erigon/cmd/sentinel/sentinel/service"
8487
"github.com/ledgerwatch/erigon/cmd/sentry/sentry"
@@ -114,6 +117,12 @@ import (
114117
"github.com/ledgerwatch/erigon/turbo/stages/headerdownload"
115118
)
116119

120+
type StartableEngineRPC interface {
121+
Start(httpConfig httpcfg.HttpCfg,
122+
filters *rpchelper.Filters, stateCache kvcache.Cache, agg *libstate.AggregatorV3, engineReader consensus.EngineReader,
123+
eth rpchelper.ApiBackend, txPool txpool2.TxpoolClient, mining txpool2.MiningClient)
124+
}
125+
117126
// Config contains the configuration options of the ETH protocol.
118127
// Deprecated: use ethconfig.Config instead.
119128
type Config = ethconfig.Config
@@ -139,7 +148,7 @@ type Ethereum struct {
139148
genesisHash libcommon.Hash
140149

141150
ethBackendRPC *privateapi.EthBackendServer
142-
engineBackendRPC *engineapi.EngineServer
151+
engineBackendRPC StartableEngineRPC
143152
miningRPC txpool_proto.MiningServer
144153
stateChangesClient txpool.StateChangesClient
145154

@@ -558,7 +567,22 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
558567
// Initialize ethbackend
559568
ethBackendRPC := privateapi.NewEthBackendServer(ctx, backend, backend.chainDB, backend.notifications.Events, blockReader, logger, latestBlockBuiltStore)
560569
// intiialize engine backend
561-
backend.engineBackendRPC = engineapi.NewEngineServer(ctx, logger, chainConfig, assembleBlockPOS, backend.chainDB, blockReader, backend.sentriesClient.Hd, config.Miner.EnabledPOS)
570+
var engine *execution_client.ExecutionClientDirect
571+
572+
if config.ExperimentalConsensusSeparation {
573+
log.Info("Using experimental Engine API")
574+
engineBackendRPC := engineapi.NewEngineServerExperimental(ctx, logger, chainConfig, assembleBlockPOS, backend.chainDB, blockReader, backend.sentriesClient.Hd, config.Miner.EnabledPOS)
575+
backend.engineBackendRPC = engineBackendRPC
576+
engine, err = execution_client.NewExecutionClientDirect(ctx,
577+
engineBackendRPC,
578+
)
579+
} else {
580+
engineBackendRPC := engineapi.NewEngineServer(ctx, logger, chainConfig, assembleBlockPOS, backend.chainDB, blockReader, backend.sentriesClient.Hd, config.Miner.EnabledPOS)
581+
backend.engineBackendRPC = engineBackendRPC
582+
engine, err = execution_client.NewExecutionClientDirect(ctx,
583+
engineBackendRPC,
584+
)
585+
}
562586

563587
miningRPC = privateapi.NewMiningServer(ctx, backend, ethashApi, logger)
564588

@@ -630,10 +654,6 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
630654
return nil, fmt.Errorf("could not load jwt for Caplin: %s", err)
631655
}
632656

633-
engine, err := execution_client.NewExecutionClientDirect(ctx,
634-
backend.engineBackendRPC,
635-
)
636-
637657
if err != nil {
638658
return nil, err
639659
}

eth/ethconfig/config.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,13 @@ type Config struct {
238238
// Ethstats service
239239
Ethstats string
240240
// Consensus layer
241-
InternalCL bool
242-
LightClientDiscoveryAddr string
243-
LightClientDiscoveryPort uint64
244-
LightClientDiscoveryTCPPort uint64
245-
SentinelAddr string
246-
SentinelPort uint64
241+
InternalCL bool
242+
LightClientDiscoveryAddr string
243+
LightClientDiscoveryPort uint64
244+
LightClientDiscoveryTCPPort uint64
245+
SentinelAddr string
246+
SentinelPort uint64
247+
ExperimentalConsensusSeparation bool
247248

248249
OverrideShanghaiTime *big.Int `toml:",omitempty"`
249250

turbo/cli/default_flags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var DefaultFlags = []cli.Flag{
4747
&StateStreamDisableFlag,
4848
&SyncLoopThrottleFlag,
4949
&BadBlockFlag,
50+
&ExperimentalConsensusSeparationFlag,
5051

5152
&utils.HTTPEnabledFlag,
5253
&utils.GraphQLEnabledFlag,

turbo/cli/flags.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ var (
201201
Usage: "How often transactions should be committed to the storage",
202202
Value: txpoolcfg.DefaultConfig.CommitEvery,
203203
}
204+
205+
ExperimentalConsensusSeparationFlag = cli.BoolFlag{
206+
Name: "experimental.modular",
207+
Usage: "Enable consensus separation (experimental feauture)",
208+
Value: false,
209+
}
204210
)
205211

206212
func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config, logger log.Logger) {
@@ -246,6 +252,8 @@ func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config, logger log.
246252
}
247253
}
248254

255+
cfg.ExperimentalConsensusSeparation = ctx.Bool(ExperimentalConsensusSeparationFlag.Name)
256+
249257
if ctx.String(SyncLoopThrottleFlag.Name) != "" {
250258
syncLoopThrottle, err := time.ParseDuration(ctx.String(SyncLoopThrottleFlag.Name))
251259
if err != nil {

turbo/engineapi/engine_helpers/fork_validator.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -297,24 +297,7 @@ func (fv *ForkValidator) validateAndStorePayload(tx kv.RwTx, header *types.Heade
297297
fv.validHashes.Add(header.Hash(), true)
298298

299299
// If we do not have the body we can recover it from the batch.
300-
if body == nil {
301-
var bodyFromDb *types.Body
302-
bodyFromDb, criticalError = fv.blockReader.BodyWithTransactions(context.Background(), tx, header.Hash(), header.Number.Uint64())
303-
if criticalError != nil {
304-
return
305-
}
306-
if bodyFromDb == nil {
307-
criticalError = fmt.Errorf("ForkValidator failed to recover block body: %d, %x", header.Number.Uint64(), header.Hash())
308-
return
309-
}
310-
if criticalError = rawdb.WriteHeader(tx, header); criticalError != nil {
311-
return
312-
}
313-
314-
} else {
315-
if criticalError = rawdb.WriteHeader(tx, header); criticalError != nil {
316-
return
317-
}
300+
if body != nil {
318301
if _, criticalError = rawdb.WriteRawBodyIfNotExists(tx, header.Hash(), header.Number.Uint64(), body); criticalError != nil {
319302
return
320303
}

0 commit comments

Comments
 (0)