enabling apis for merge if chainConfig has TTD (#3721)

This commit is contained in:
Enrique Jose Avila Asapche 2022-03-17 01:28:17 +00:00 committed by GitHub
parent 956a57f7c6
commit bb711676a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -287,26 +287,57 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger,
}
log.Info("if you run RPCDaemon on same machine with Erigon add --datadir option")
}
var cc *params.ChainConfig
if err := db.View(context.Background(), func(tx kv.Tx) error {
genesisBlock, err := rawdb.ReadBlockByNumber(tx, 0)
if err != nil {
return err
}
cc, err = rawdb.ReadChainConfig(tx, genesisBlock.Hash())
if err != nil {
return err
}
return nil
}); err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, ff, err
}
if cc == nil {
return nil, nil, nil, nil, nil, nil, nil, nil, ff, fmt.Errorf("chain config not found in db. Need start erigon at least once on this db")
}
// if chain config has terminal total difficulty then rpc has to have these API's to function
if cc.TerminalTotalDifficulty != nil {
hasEthApiEnabled := false
hasEngineApiEnabled := false
hasNetApiEnabled := false
for _, api := range cfg.API {
switch api {
case "eth":
hasEthApiEnabled = true
case "engine":
hasEngineApiEnabled = true
case "net":
hasNetApiEnabled = true
}
}
if !hasEthApiEnabled {
cfg.API = append(cfg.API, "eth")
}
if !hasEngineApiEnabled {
cfg.API = append(cfg.API, "engine")
}
if !hasNetApiEnabled {
cfg.API = append(cfg.API, "net")
}
}
if cfg.SingleNodeMode {
if cfg.Snapshot.Enabled {
var cc *params.ChainConfig
if err := db.View(context.Background(), func(tx kv.Tx) error {
genesisBlock, err := rawdb.ReadBlockByNumber(tx, 0)
if err != nil {
return err
}
cc, err = rawdb.ReadChainConfig(tx, genesisBlock.Hash())
if err != nil {
return err
}
return nil
}); err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, ff, err
}
if cc == nil {
return nil, nil, nil, nil, nil, nil, nil, nil, ff, fmt.Errorf("chain config not found in db. Need start erigon at least once on this db")
}
allSnapshots := snapshotsync.NewRoSnapshots(cfg.Snapshot, filepath.Join(cfg.DataDir, "snapshots"))
allSnapshots.AsyncOpenAll(ctx)