Made Lightclient default (#5813)

lightclient cl is default, for external cl, run `--externalcl`
This commit is contained in:
Giulio rebuffo 2022-11-10 18:06:04 +01:00 committed by GitHub
parent ea1edf4a11
commit f8916e9226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 79 additions and 49 deletions

View File

@ -142,6 +142,10 @@ Don't start services as separated processes unless you have clear reason for it:
your own implementation, security.
How to start Erigon's services as separated processes, see in [docker-compose.yml](./docker-compose.yml).
### Embedded Consensus Layer
By default the Engine API is disabled in favour of Erigon native Embedded Consensus Layer, if you want to either stake or sync an external Consensus Layer, run Erigon with flag `--externalcl`.
### Optional stages
There is an optional stage that can be enabled through flags:

View File

@ -708,3 +708,11 @@ func GetCheckpointSyncEndpoint(net NetworkType) string {
}
return checkpoints[n.Int64()]
}
// Check if chain with a specific ID is supported or not
// 1 is Ethereum Mainnet
// 5 is Goerli Testnet
// 11155111 is Sepolia Testnet
func Supported(id uint64) bool {
return id == 1 || id == 5 || id == 11155111
}

View File

@ -50,6 +50,7 @@ type HttpCfg struct {
HTTPTimeouts rpccfg.HTTPTimeouts
AuthRpcTimeouts rpccfg.HTTPTimeouts
EvmCallTimeout time.Duration
InternalCL bool
LogDirVerbosity string
LogDirPath string
}

View File

@ -129,7 +129,7 @@ func AuthAPIList(db kv.RoDB, eth rpchelper.ApiBackend, txPool txpool.TxpoolClien
base := NewBaseApi(filters, stateCache, blockReader, agg, cfg.WithDatadir, cfg.EvmCallTimeout)
ethImpl := NewEthAPI(base, db, eth, txPool, mining, cfg.Gascap)
engineImpl := NewEngineAPI(base, db, eth)
engineImpl := NewEngineAPI(base, db, eth, cfg.InternalCL)
list = append(list, rpc.API{
Namespace: "eth",

View File

@ -69,8 +69,9 @@ type EngineAPI interface {
// EngineImpl is implementation of the EngineAPI interface
type EngineImpl struct {
*BaseAPI
db kv.RoDB
api rpchelper.ApiBackend
db kv.RoDB
api rpchelper.ApiBackend
internalCL bool
}
func convertPayloadStatus(x *remote.EnginePayloadStatus) map[string]interface{} {
@ -88,6 +89,10 @@ func convertPayloadStatus(x *remote.EnginePayloadStatus) map[string]interface{}
}
func (e *EngineImpl) ForkchoiceUpdatedV1(ctx context.Context, forkChoiceState *ForkChoiceState, payloadAttributes *PayloadAttributes) (map[string]interface{}, error) {
if e.internalCL {
log.Error("EXTERNAL CONSENSUS LAYER IS NOT ENABLED, PLEASE RESTART WITH FLAG --externalcl")
return nil, fmt.Errorf("engine api should not be used, restart with --externalcl")
}
log.Debug("Received ForkchoiceUpdated", "head", forkChoiceState.HeadHash, "safe", forkChoiceState.HeadHash, "finalized", forkChoiceState.FinalizedBlockHash,
"build", payloadAttributes != nil)
@ -143,6 +148,10 @@ func (e *EngineImpl) ForkchoiceUpdatedV1(ctx context.Context, forkChoiceState *F
// NewPayloadV1 processes new payloads (blocks) from the beacon chain.
// See https://github.com/ethereum/execution-apis/blob/main/src/engine/specification.md#engine_newpayloadv1
func (e *EngineImpl) NewPayloadV1(ctx context.Context, payload *ExecutionPayload) (map[string]interface{}, error) {
if e.internalCL {
log.Error("EXTERNAL CONSENSUS LAYER IS NOT ENABLED, PLEASE RESTART WITH FLAG --externalcl")
return nil, fmt.Errorf("engine api should not be used, restart with --externalcl")
}
log.Debug("Received NewPayload", "height", uint64(payload.BlockNumber), "hash", payload.BlockHash)
var baseFee *uint256.Int
@ -201,6 +210,11 @@ func (e *EngineImpl) NewPayloadV1(ctx context.Context, payload *ExecutionPayload
}
func (e *EngineImpl) GetPayloadV1(ctx context.Context, payloadID hexutil.Bytes) (*ExecutionPayload, error) {
if e.internalCL {
log.Error("EXTERNAL CONSENSUS LAYER IS NOT ENABLED, PLEASE RESTART WITH FLAG --externalcl")
return nil, fmt.Errorf("engine api should not be used, restart with --externalcl")
}
decodedPayloadId := binary.BigEndian.Uint64(payloadID)
log.Info("Received GetPayload", "payloadId", decodedPayloadId)
@ -242,6 +256,11 @@ func (e *EngineImpl) GetPayloadV1(ctx context.Context, payloadID hexutil.Bytes)
// Can also be used to ping the execution layer (heartbeats).
// See https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.7/src/engine/specification.md#engine_exchangetransitionconfigurationv1
func (e *EngineImpl) ExchangeTransitionConfigurationV1(ctx context.Context, beaconConfig TransitionConfiguration) (TransitionConfiguration, error) {
if e.internalCL {
log.Error("EXTERNAL CONSENSUS LAYER IS NOT ENABLED, PLEASE RESTART WITH FLAG --externalcl")
return TransitionConfiguration{}, fmt.Errorf("engine api should not be used, restart with --externalcl")
}
tx, err := e.db.BeginRo(ctx)
if err != nil {
@ -274,10 +293,11 @@ func (e *EngineImpl) ExchangeTransitionConfigurationV1(ctx context.Context, beac
}
// NewEngineAPI returns EngineImpl instance
func NewEngineAPI(base *BaseAPI, db kv.RoDB, api rpchelper.ApiBackend) *EngineImpl {
func NewEngineAPI(base *BaseAPI, db kv.RoDB, api rpchelper.ApiBackend, internalCL bool) *EngineImpl {
return &EngineImpl{
BaseAPI: base,
db: db,
api: api,
BaseAPI: base,
db: db,
api: api,
internalCL: internalCL,
}
}

View File

@ -163,9 +163,9 @@ var (
Name: "snapshots",
Usage: `Default: use snapshots "true" for BSC, Mainnet and Goerli. use snapshots "false" in all other cases`,
}
LightClientFlag = cli.BoolFlag{
Name: "experimental.lightclient",
Usage: "enables experimental CL lightclient.",
ExternalConsensusFlag = cli.BoolFlag{
Name: "externalcl",
Usage: "enables external consensus",
}
// Transaction pool settings
TxPoolDisableFlag = cli.BoolFlag{
@ -1427,7 +1427,7 @@ func CheckExclusive(ctx *cli.Context, args ...interface{}) {
// SetEthConfig applies eth-related command line flags to the config.
func SetEthConfig(ctx *cli.Context, nodeConfig *nodecfg.Config, cfg *ethconfig.Config) {
cfg.CL = ctx.GlobalBool(LightClientFlag.Name)
cfg.CL = ctx.GlobalBool(ExternalConsensusFlag.Name)
cfg.Sync.UseSnapshots = ctx.GlobalBoolT(SnapshotFlag.Name)
cfg.Dirs = nodeConfig.Dirs
cfg.Snapshot.KeepBlocks = ctx.GlobalBool(SnapKeepBlocksFlag.Name)

View File

@ -453,44 +453,40 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
blockReader, chainConfig, assembleBlockPOS, backend.sentriesClient.Hd, config.Miner.EnabledPOS)
miningRPC = privateapi.NewMiningServer(ctx, backend, ethashApi)
if config.CL {
// Chains supported are Sepolia, Mainnet and Goerli
if config.NetworkID == 1 || config.NetworkID == 5 || config.NetworkID == 11155111 {
genesisCfg, networkCfg, beaconCfg := clparams.GetConfigsByNetwork(clparams.NetworkType(config.NetworkID))
if err != nil {
return nil, err
}
client, err := service.StartSentinelService(&sentinel.SentinelConfig{
IpAddr: "127.0.0.1",
Port: 4000,
TCPPort: 4001,
GenesisConfig: genesisCfg,
NetworkConfig: networkCfg,
BeaconConfig: beaconCfg,
}, &service.ServerConfig{Network: "tcp", Addr: "localhost:7777"})
if err != nil {
return nil, err
}
lc, err := lightclient.NewLightClient(ctx, genesisCfg, beaconCfg, ethBackendRPC, client, currentBlockNumber, false)
if err != nil {
return nil, err
}
bs, err := clcore.RetrieveBeaconState(ctx,
clparams.GetCheckpointSyncEndpoint(clparams.NetworkType(config.NetworkID)))
if err != nil {
return nil, err
}
if err := lc.BootstrapCheckpoint(ctx, bs.FinalizedCheckpoint.Root); err != nil {
return nil, err
}
go lc.Start()
} else {
log.Warn("Cannot run lightclient on a non-supported chain. only goerli, sepolia and mainnet are allowed")
// If we choose not to run a consensus layer, run our embedded.
if !config.CL && clparams.Supported(config.NetworkID) {
genesisCfg, networkCfg, beaconCfg := clparams.GetConfigsByNetwork(clparams.NetworkType(config.NetworkID))
if err != nil {
return nil, err
}
client, err := service.StartSentinelService(&sentinel.SentinelConfig{
IpAddr: "127.0.0.1",
Port: 4000,
TCPPort: 4001,
GenesisConfig: genesisCfg,
NetworkConfig: networkCfg,
BeaconConfig: beaconCfg,
}, &service.ServerConfig{Network: "tcp", Addr: "localhost:7777"})
if err != nil {
return nil, err
}
lc, err := lightclient.NewLightClient(ctx, genesisCfg, beaconCfg, ethBackendRPC, client, currentBlockNumber, false)
if err != nil {
return nil, err
}
bs, err := clcore.RetrieveBeaconState(ctx,
clparams.GetCheckpointSyncEndpoint(clparams.NetworkType(config.NetworkID)))
if err != nil {
return nil, err
}
if err := lc.BootstrapCheckpoint(ctx, bs.FinalizedCheckpoint.Root); err != nil {
return nil, err
}
go lc.Start()
}
if stack.Config().PrivateApiAddr != "" {

View File

@ -12,7 +12,7 @@ var DefaultFlags = []cli.Flag{
utils.DataDirFlag,
utils.EthashDatasetDirFlag,
utils.SnapshotFlag,
utils.LightClientFlag,
utils.ExternalConsensusFlag,
utils.TxPoolDisableFlag,
utils.TxPoolLocalsFlag,
utils.TxPoolNoLocalsFlag,

View File

@ -371,6 +371,7 @@ func setEmbeddedRpcDaemon(ctx *cli.Context, cfg *nodecfg.Config) {
TxPoolApiAddr: ctx.GlobalString(utils.TxpoolApiAddrFlag.Name),
StateCache: kvcache.DefaultCoherentConfig,
InternalCL: !ctx.GlobalBool(utils.ExternalConsensusFlag.Name),
}
if ctx.GlobalIsSet(utils.HttpCompressionFlag.Name) {
c.HttpCompression = ctx.GlobalBool(utils.HttpCompressionFlag.Name)